(p *api.PushPayload, slack *SlackMeta)
| 119 | } |
| 120 | |
| 121 | func getDiscordPushPayload(p *api.PushPayload, slack *SlackMeta) *DiscordPayload { |
| 122 | // n new commits |
| 123 | var ( |
| 124 | branchName = git.RefShortName(p.Ref) |
| 125 | commitDesc string |
| 126 | commitString string |
| 127 | ) |
| 128 | |
| 129 | if len(p.Commits) == 1 { |
| 130 | commitDesc = "1 new commit" |
| 131 | } else { |
| 132 | commitDesc = fmt.Sprintf("%d new commits", len(p.Commits)) |
| 133 | } |
| 134 | |
| 135 | if len(p.CompareURL) > 0 { |
| 136 | commitString = DiscordLinkFormatter(p.CompareURL, commitDesc) |
| 137 | } else { |
| 138 | commitString = commitDesc |
| 139 | } |
| 140 | |
| 141 | repoLink := DiscordLinkFormatter(p.Repo.HTMLURL, p.Repo.Name) |
| 142 | branchLink := DiscordLinkFormatter(p.Repo.HTMLURL+"/src/"+branchName, branchName) |
| 143 | content := fmt.Sprintf("Pushed %s to %s/%s\n", commitString, repoLink, branchLink) |
| 144 | |
| 145 | // for each commit, generate attachment text |
| 146 | for i, commit := range p.Commits { |
| 147 | content += fmt.Sprintf("%s %s - %s", DiscordSHALinkFormatter(commit.URL, commit.ID[:7]), DiscordTextFormatter(commit.Message), commit.Author.Name) |
| 148 | // add linebreak to each commit but the last |
| 149 | if i < len(p.Commits)-1 { |
| 150 | content += "\n" |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32) |
| 155 | return &DiscordPayload{ |
| 156 | Username: slack.Username, |
| 157 | AvatarURL: slack.IconURL, |
| 158 | Embeds: []*DiscordEmbedObject{{ |
| 159 | Description: content, |
| 160 | URL: conf.Server.ExternalURL + p.Sender.UserName, |
| 161 | Color: int(color), |
| 162 | Author: &DiscordEmbedAuthorObject{ |
| 163 | Name: p.Sender.UserName, |
| 164 | IconURL: p.Sender.AvatarUrl, |
| 165 | }, |
| 166 | }}, |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func getDiscordIssuesPayload(p *api.IssuesPayload, slack *SlackMeta) *DiscordPayload { |
| 171 | title := fmt.Sprintf("#%d %s", p.Index, p.Issue.Title) |
no test coverage detected