作为一名直接进入 Go 的 JS 开发者,如果长度超过commits
不止一个。我没有太多时间来完成这件事,而且我搜索的时间比我希望的要长。关于如何重组它或让它发挥作用有什么想法吗?
case github.PushPayload:
push := payload.(github.PushPayload)
repo := push.Repository.Name
owner := push.Repository.Owner.Login
ownerUrl := push.Repository.Owner.HTMLURL
ownerAvatar := push.Repository.Owner.AvatarURL
ref := push.Ref
refTrim := strings.Replace(ref, "/.*/", "", -1)
commits := push.Commits
for _, commit := range commits {
message := commit.Message
url := commit.URL
id := commit.ID
idShort := id[0:6]
committer := commit.Committer.Username
description := "[`" + idShort + "`](" + url + ") " + message + " - " + committer
}
if len(commits) == 1 {
discord.ChannelMessageSendEmbed(channelID, &discordgo.MessageEmbed{
Color: 0x00B1FF,
Description: description,
Title: "[" + repo + ":" + refTrim + "] 1 new commit! ????",
Author: &discordgo.MessageEmbedAuthor{
Name: owner,
URL: ownerUrl,
IconURL: ownerAvatar,
},
})
} else {
discord.ChannelMessageSendEmbed(channelID, &discordgo.MessageEmbed{
Color: 0x00B1FF,
Description: description,
Title: "[" + repo + ":" + refTrim + "] " + string(len(commits)) + " new commits! ⚒️",
Author: &discordgo.MessageEmbedAuthor{
Name: owner,
URL: ownerUrl,
IconURL: ownerAvatar,
},
})
}
PS:忽略string(len(commits))
我知道这是不正确的,我首先要解决这个问题。也忽略:refTrim := strings.Replace(ref, "/.*/", "", -1)
,这也不正确。