MCPcopy Create free account
hub / github.com/gogs/gogs / getDiscordIssuesPayload

Function getDiscordIssuesPayload

internal/database/webhook_discord.go:170–240  ·  view source on GitHub ↗
(p *api.IssuesPayload, slack *SlackMeta)

Source from the content-addressed store, hash-verified

168}
169
170func getDiscordIssuesPayload(p *api.IssuesPayload, slack *SlackMeta) *DiscordPayload {
171 title := fmt.Sprintf("#%d %s", p.Index, p.Issue.Title)
172 url := fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Index)
173 content := ""
174 fields := make([]*DiscordEmbedFieldObject, 0, 1)
175 switch p.Action {
176 case api.HOOK_ISSUE_OPENED:
177 title = "New issue: " + title
178 content = p.Issue.Body
179 case api.HOOK_ISSUE_CLOSED:
180 title = "Issue closed: " + title
181 case api.HOOK_ISSUE_REOPENED:
182 title = "Issue re-opened: " + title
183 case api.HOOK_ISSUE_EDITED:
184 title = "Issue edited: " + title
185 content = p.Issue.Body
186 case api.HOOK_ISSUE_ASSIGNED:
187 title = "Issue assigned: " + title
188 fields = []*DiscordEmbedFieldObject{{
189 Name: "New Assignee",
190 Value: p.Issue.Assignee.UserName,
191 }}
192 case api.HOOK_ISSUE_UNASSIGNED:
193 title = "Issue unassigned: " + title
194 case api.HOOK_ISSUE_LABEL_UPDATED:
195 title = "Issue labels updated: " + title
196 labels := make([]string, len(p.Issue.Labels))
197 for i := range p.Issue.Labels {
198 labels[i] = p.Issue.Labels[i].Name
199 }
200 if len(labels) == 0 {
201 labels = []string{"<empty>"}
202 }
203 fields = []*DiscordEmbedFieldObject{{
204 Name: "Labels",
205 Value: strings.Join(labels, ", "),
206 }}
207 case api.HOOK_ISSUE_LABEL_CLEARED:
208 title = "Issue labels cleared: " + title
209 case api.HOOK_ISSUE_SYNCHRONIZED:
210 title = "Issue synchronized: " + title
211 case api.HOOK_ISSUE_MILESTONED:
212 title = "Issue milestoned: " + title
213 fields = []*DiscordEmbedFieldObject{{
214 Name: "New Milestone",
215 Value: p.Issue.Milestone.Title,
216 }}
217 case api.HOOK_ISSUE_DEMILESTONED:
218 title = "Issue demilestoned: " + title
219 }
220
221 color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32)
222 return &DiscordPayload{
223 Username: slack.Username,
224 AvatarURL: slack.IconURL,
225 Embeds: []*DiscordEmbedObject{{
226 Title: title,
227 Description: content,

Callers 1

GetDiscordPayloadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected