diff options
author | Unknwon <u@gogs.io> | 2017-03-09 04:11:23 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-03-09 04:11:23 -0500 |
commit | 89cc6aa430c65b87808ee4a159e0a80785b51935 (patch) | |
tree | 20ac897b69822337a02796ec7a8d9951bd0c285d /models/webhook_discord.go | |
parent | c93731339f3da01bb1158acc7acf781f0dfe2468 (diff) |
webhook: add issue comment event
Diffstat (limited to 'models/webhook_discord.go')
-rw-r--r-- | models/webhook_discord.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/models/webhook_discord.go b/models/webhook_discord.go index 48016c13..0e9a36f2 100644 --- a/models/webhook_discord.go +++ b/models/webhook_discord.go @@ -241,6 +241,45 @@ func getDiscordIssuesPayload(p *api.IssuesPayload, slack *SlackMeta) (*DiscordPa }, nil } +func getDiscordIssueCommentPayload(p *api.IssueCommentPayload, slack *SlackMeta) (*DiscordPayload, error) { + title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title) + url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) + content := "" + fields := make([]*DiscordEmbedFieldObject, 0, 1) + switch p.Action { + case api.HOOK_ISSUE_COMMENT_CREATED: + title = "New comment: " + title + content = p.Comment.Body + case api.HOOK_ISSUE_COMMENT_EDITED: + title = "Comment edited: " + title + content = p.Comment.Body + case api.HOOK_ISSUE_COMMENT_DELETED: + title = "Comment deleted: " + title + url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) + content = p.Comment.Body + } + + color, _ := strconv.ParseInt(strings.TrimLeft(slack.Color, "#"), 16, 32) + return &DiscordPayload{ + Username: slack.Username, + AvatarURL: slack.IconURL, + Embeds: []*DiscordEmbedObject{{ + Title: title, + Description: content, + URL: url, + Color: int(color), + Footer: &DiscordEmbedFooterObject{ + Text: p.Repository.FullName, + }, + Author: &DiscordEmbedAuthorObject{ + Name: p.Sender.UserName, + IconURL: p.Sender.AvatarUrl, + }, + Fields: fields, + }}, + }, nil +} + func getDiscordPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*DiscordPayload, error) { title := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title) url := fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index) @@ -331,6 +370,8 @@ func GetDiscordPayload(p api.Payloader, event HookEventType, meta string) (paylo payload, err = getDiscordPushPayload(p.(*api.PushPayload), slack) case HOOK_EVENT_ISSUES: payload, err = getDiscordIssuesPayload(p.(*api.IssuesPayload), slack) + case HOOK_EVENT_ISSUE_COMMENT: + payload, err = getDiscordIssueCommentPayload(p.(*api.IssueCommentPayload), slack) case HOOK_EVENT_PULL_REQUEST: payload, err = getDiscordPullRequestPayload(p.(*api.PullRequestPayload), slack) } |