* Improve webhooks Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update MSTeams and ReviewPayload comment Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add repo.FullName to comments Signed-off-by: jolheiser <john.olheiser@gmail.com>tags/v1.11.0-rc1
} | } | ||||
func getDingtalkIssueCommentPayload(p *api.IssueCommentPayload) (*DingtalkPayload, error) { | func getDingtalkIssueCommentPayload(p *api.IssueCommentPayload) (*DingtalkPayload, error) { | ||||
title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title) | |||||
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)) | url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) | ||||
var content string | var content string | ||||
switch p.Action { | switch p.Action { | ||||
case api.HookIssueCommentCreated: | case api.HookIssueCommentCreated: | ||||
title = "New comment: " + title | |||||
if p.IsPull { | |||||
title = "New comment on pull request " + title | |||||
} else { | |||||
title = "New comment on issue " + title | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
case api.HookIssueCommentEdited: | case api.HookIssueCommentEdited: | ||||
title = "Comment edited: " + title | |||||
if p.IsPull { | |||||
title = "Comment edited on pull request " + title | |||||
} else { | |||||
title = "Comment edited on issue " + title | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
case api.HookIssueCommentDeleted: | case api.HookIssueCommentDeleted: | ||||
title = "Comment deleted: " + title | |||||
if p.IsPull { | |||||
title = "Comment deleted on pull request " + title | |||||
} else { | |||||
title = "Comment deleted on issue " + title | |||||
} | |||||
url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | ||||
content = p.Comment.Body | content = p.Comment.Body | ||||
} | } | ||||
title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title) | |||||
return &DingtalkPayload{ | return &DingtalkPayload{ | ||||
MsgType: "actionCard", | MsgType: "actionCard", | ||||
ActionCard: dingtalk.ActionCard{ | ActionCard: dingtalk.ActionCard{ | ||||
} | } | ||||
title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | |||||
text = p.Review.Content | |||||
} | } | ||||
} | } | ||||
var ( | var ( | ||||
successColor = color("1ac600") | |||||
warnColor = color("ffd930") | |||||
failedColor = color("ff3232") | |||||
greenColor = color("1ac600") | |||||
greenColorLight = color("bfe5bf") | |||||
yellowColor = color("ffd930") | |||||
greyColor = color("4f545c") | |||||
purpleColor = color("7289da") | |||||
orangeColor = color("eb6420") | |||||
orangeColorLight = color("e68d60") | |||||
redColor = color("ff3232") | |||||
) | ) | ||||
// SetSecret sets the discord secret | // SetSecret sets the discord secret | ||||
{ | { | ||||
Title: title, | Title: title, | ||||
URL: p.Repo.HTMLURL + "/src/" + refName, | URL: p.Repo.HTMLURL + "/src/" + refName, | ||||
Color: successColor, | |||||
Color: greenColor, | |||||
Author: DiscordEmbedAuthor{ | Author: DiscordEmbedAuthor{ | ||||
Name: p.Sender.UserName, | Name: p.Sender.UserName, | ||||
URL: setting.AppURL + p.Sender.UserName, | URL: setting.AppURL + p.Sender.UserName, | ||||
{ | { | ||||
Title: title, | Title: title, | ||||
URL: p.Repo.HTMLURL + "/src/" + refName, | URL: p.Repo.HTMLURL + "/src/" + refName, | ||||
Color: warnColor, | |||||
Color: redColor, | |||||
Author: DiscordEmbedAuthor{ | Author: DiscordEmbedAuthor{ | ||||
Name: p.Sender.UserName, | Name: p.Sender.UserName, | ||||
URL: setting.AppURL + p.Sender.UserName, | URL: setting.AppURL + p.Sender.UserName, | ||||
{ | { | ||||
Title: title, | Title: title, | ||||
URL: p.Repo.HTMLURL, | URL: p.Repo.HTMLURL, | ||||
Color: successColor, | |||||
Color: greenColor, | |||||
Author: DiscordEmbedAuthor{ | Author: DiscordEmbedAuthor{ | ||||
Name: p.Sender.UserName, | Name: p.Sender.UserName, | ||||
URL: setting.AppURL + p.Sender.UserName, | URL: setting.AppURL + p.Sender.UserName, | ||||
Title: title, | Title: title, | ||||
Description: text, | Description: text, | ||||
URL: titleLink, | URL: titleLink, | ||||
Color: successColor, | |||||
Color: greenColor, | |||||
Author: DiscordEmbedAuthor{ | Author: DiscordEmbedAuthor{ | ||||
Name: p.Sender.UserName, | Name: p.Sender.UserName, | ||||
URL: setting.AppURL + p.Sender.UserName, | URL: setting.AppURL + p.Sender.UserName, | ||||
case api.HookIssueOpened: | case api.HookIssueOpened: | ||||
title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = orangeColor | |||||
case api.HookIssueClosed: | case api.HookIssueClosed: | ||||
title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
color = failedColor | |||||
color = redColor | |||||
text = p.Issue.Body | text = p.Issue.Body | ||||
case api.HookIssueReOpened: | case api.HookIssueReOpened: | ||||
title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueEdited: | case api.HookIssueEdited: | ||||
title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueAssigned: | case api.HookIssueAssigned: | ||||
title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName, | title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName, | ||||
p.Issue.Assignee.UserName, p.Index, p.Issue.Title) | p.Issue.Assignee.UserName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookIssueUnassigned: | case api.HookIssueUnassigned: | ||||
title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelUpdated: | case api.HookIssueLabelUpdated: | ||||
title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelCleared: | case api.HookIssueLabelCleared: | ||||
title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueSynchronized: | case api.HookIssueSynchronized: | ||||
title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueMilestoned: | case api.HookIssueMilestoned: | ||||
title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueDemilestoned: | case api.HookIssueDemilestoned: | ||||
title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
return &DiscordPayload{ | return &DiscordPayload{ | ||||
} | } | ||||
func getDiscordIssueCommentPayload(p *api.IssueCommentPayload, discord *DiscordMeta) (*DiscordPayload, error) { | func getDiscordIssueCommentPayload(p *api.IssueCommentPayload, discord *DiscordMeta) (*DiscordPayload, error) { | ||||
title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title) | |||||
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)) | url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) | ||||
content := "" | content := "" | ||||
var color int | var color int | ||||
switch p.Action { | switch p.Action { | ||||
case api.HookIssueCommentCreated: | case api.HookIssueCommentCreated: | ||||
title = "New comment: " + title | |||||
if p.IsPull { | |||||
title = "New comment on pull request " + title | |||||
color = greenColorLight | |||||
} else { | |||||
title = "New comment on issue " + title | |||||
color = orangeColorLight | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = successColor | |||||
case api.HookIssueCommentEdited: | case api.HookIssueCommentEdited: | ||||
title = "Comment edited: " + title | |||||
if p.IsPull { | |||||
title = "Comment edited on pull request " + title | |||||
} else { | |||||
title = "Comment edited on issue " + title | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueCommentDeleted: | case api.HookIssueCommentDeleted: | ||||
title = "Comment deleted: " + title | |||||
if p.IsPull { | |||||
title = "Comment deleted on pull request " + title | |||||
} else { | |||||
title = "Comment deleted on issue " + title | |||||
} | |||||
url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | ||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = warnColor | |||||
color = redColor | |||||
} | } | ||||
title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title) | |||||
return &DiscordPayload{ | return &DiscordPayload{ | ||||
Username: discord.Username, | Username: discord.Username, | ||||
AvatarURL: discord.IconURL, | AvatarURL: discord.IconURL, | ||||
case api.HookIssueOpened: | case api.HookIssueOpened: | ||||
title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = greenColor | |||||
case api.HookIssueClosed: | case api.HookIssueClosed: | ||||
if p.PullRequest.HasMerged { | if p.PullRequest.HasMerged { | ||||
title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
color = successColor | |||||
color = purpleColor | |||||
} else { | } else { | ||||
title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
color = failedColor | |||||
color = redColor | |||||
} | } | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
case api.HookIssueReOpened: | case api.HookIssueReOpened: | ||||
title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueEdited: | case api.HookIssueEdited: | ||||
title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueAssigned: | case api.HookIssueAssigned: | ||||
list := make([]string, len(p.PullRequest.Assignees)) | list := make([]string, len(p.PullRequest.Assignees)) | ||||
for i, user := range p.PullRequest.Assignees { | for i, user := range p.PullRequest.Assignees { | ||||
strings.Join(list, ", "), | strings.Join(list, ", "), | ||||
p.Index, p.PullRequest.Title) | p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookIssueUnassigned: | case api.HookIssueUnassigned: | ||||
title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelUpdated: | case api.HookIssueLabelUpdated: | ||||
title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelCleared: | case api.HookIssueLabelCleared: | ||||
title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueSynchronized: | case api.HookIssueSynchronized: | ||||
title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueMilestoned: | case api.HookIssueMilestoned: | ||||
title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueDemilestoned: | case api.HookIssueDemilestoned: | ||||
title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
return &DiscordPayload{ | return &DiscordPayload{ | ||||
} | } | ||||
title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | |||||
text = p.Review.Content | |||||
switch event { | switch event { | ||||
case HookEventPullRequestApproved: | case HookEventPullRequestApproved: | ||||
color = successColor | |||||
color = greenColor | |||||
case HookEventPullRequestRejected: | case HookEventPullRequestRejected: | ||||
color = failedColor | |||||
color = redColor | |||||
case HookEventPullRequestComment: | case HookEventPullRequestComment: | ||||
fallthrough | |||||
color = greyColor | |||||
default: | default: | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
} | } | ||||
case api.HookRepoCreated: | case api.HookRepoCreated: | ||||
title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) | title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) | ||||
url = p.Repository.HTMLURL | url = p.Repository.HTMLURL | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookRepoDeleted: | case api.HookRepoDeleted: | ||||
title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) | title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) | ||||
color = warnColor | |||||
color = redColor | |||||
} | } | ||||
return &DiscordPayload{ | return &DiscordPayload{ | ||||
case api.HookReleasePublished: | case api.HookReleasePublished: | ||||
title = fmt.Sprintf("[%s] Release created", p.Release.TagName) | title = fmt.Sprintf("[%s] Release created", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookReleaseUpdated: | case api.HookReleaseUpdated: | ||||
title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) | title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = yellowColor | |||||
case api.HookReleaseDeleted: | case api.HookReleaseDeleted: | ||||
title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) | title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = redColor | |||||
} | } | ||||
return &DiscordPayload{ | return &DiscordPayload{ |
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
Type: "MessageCard", | Type: "MessageCard", | ||||
Context: "https://schema.org/extensions", | Context: "https://schema.org/extensions", | ||||
ThemeColor: fmt.Sprintf("%x", successColor), | |||||
ThemeColor: fmt.Sprintf("%x", greenColor), | |||||
Title: title, | Title: title, | ||||
Summary: title, | Summary: title, | ||||
Sections: []MSTeamsSection{ | Sections: []MSTeamsSection{ | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
Type: "MessageCard", | Type: "MessageCard", | ||||
Context: "https://schema.org/extensions", | Context: "https://schema.org/extensions", | ||||
ThemeColor: fmt.Sprintf("%x", warnColor), | |||||
ThemeColor: fmt.Sprintf("%x", yellowColor), | |||||
Title: title, | Title: title, | ||||
Summary: title, | Summary: title, | ||||
Sections: []MSTeamsSection{ | Sections: []MSTeamsSection{ | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
Type: "MessageCard", | Type: "MessageCard", | ||||
Context: "https://schema.org/extensions", | Context: "https://schema.org/extensions", | ||||
ThemeColor: fmt.Sprintf("%x", successColor), | |||||
ThemeColor: fmt.Sprintf("%x", greenColor), | |||||
Title: title, | Title: title, | ||||
Summary: title, | Summary: title, | ||||
Sections: []MSTeamsSection{ | Sections: []MSTeamsSection{ | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
Type: "MessageCard", | Type: "MessageCard", | ||||
Context: "https://schema.org/extensions", | Context: "https://schema.org/extensions", | ||||
ThemeColor: fmt.Sprintf("%x", successColor), | |||||
ThemeColor: fmt.Sprintf("%x", greenColor), | |||||
Title: title, | Title: title, | ||||
Summary: title, | Summary: title, | ||||
Sections: []MSTeamsSection{ | Sections: []MSTeamsSection{ | ||||
case api.HookIssueOpened: | case api.HookIssueOpened: | ||||
title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = orangeColor | |||||
case api.HookIssueClosed: | case api.HookIssueClosed: | ||||
title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
color = failedColor | |||||
color = redColor | |||||
text = p.Issue.Body | text = p.Issue.Body | ||||
case api.HookIssueReOpened: | case api.HookIssueReOpened: | ||||
title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueEdited: | case api.HookIssueEdited: | ||||
title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueAssigned: | case api.HookIssueAssigned: | ||||
title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName, | title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName, | ||||
p.Issue.Assignee.UserName, p.Index, p.Issue.Title) | p.Issue.Assignee.UserName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookIssueUnassigned: | case api.HookIssueUnassigned: | ||||
title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelUpdated: | case api.HookIssueLabelUpdated: | ||||
title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelCleared: | case api.HookIssueLabelCleared: | ||||
title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueSynchronized: | case api.HookIssueSynchronized: | ||||
title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueMilestoned: | case api.HookIssueMilestoned: | ||||
title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueDemilestoned: | case api.HookIssueDemilestoned: | ||||
title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
text = p.Issue.Body | text = p.Issue.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
} | } | ||||
func getMSTeamsIssueCommentPayload(p *api.IssueCommentPayload) (*MSTeamsPayload, error) { | func getMSTeamsIssueCommentPayload(p *api.IssueCommentPayload) (*MSTeamsPayload, error) { | ||||
title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title) | |||||
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)) | url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID)) | ||||
content := "" | content := "" | ||||
var color int | var color int | ||||
switch p.Action { | switch p.Action { | ||||
case api.HookIssueCommentCreated: | case api.HookIssueCommentCreated: | ||||
title = "New comment: " + title | |||||
if p.IsPull { | |||||
title = "New comment on pull request " + title | |||||
color = greenColorLight | |||||
} else { | |||||
title = "New comment on issue " + title | |||||
color = orangeColorLight | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = successColor | |||||
case api.HookIssueCommentEdited: | case api.HookIssueCommentEdited: | ||||
title = "Comment edited: " + title | |||||
if p.IsPull { | |||||
title = "Comment edited on pull request " + title | |||||
} else { | |||||
title = "Comment edited on issue " + title | |||||
} | |||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueCommentDeleted: | case api.HookIssueCommentDeleted: | ||||
title = "Comment deleted: " + title | |||||
if p.IsPull { | |||||
title = "Comment deleted on pull request " + title | |||||
} else { | |||||
title = "Comment deleted on issue " + title | |||||
} | |||||
url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | ||||
content = p.Comment.Body | content = p.Comment.Body | ||||
color = warnColor | |||||
color = redColor | |||||
} | } | ||||
title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title) | |||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
Type: "MessageCard", | Type: "MessageCard", | ||||
Context: "https://schema.org/extensions", | Context: "https://schema.org/extensions", | ||||
case api.HookIssueOpened: | case api.HookIssueOpened: | ||||
title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = greenColor | |||||
case api.HookIssueClosed: | case api.HookIssueClosed: | ||||
if p.PullRequest.HasMerged { | if p.PullRequest.HasMerged { | ||||
title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
color = successColor | |||||
color = purpleColor | |||||
} else { | } else { | ||||
title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
color = failedColor | |||||
color = redColor | |||||
} | } | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
case api.HookIssueReOpened: | case api.HookIssueReOpened: | ||||
title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueEdited: | case api.HookIssueEdited: | ||||
title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueAssigned: | case api.HookIssueAssigned: | ||||
list := make([]string, len(p.PullRequest.Assignees)) | list := make([]string, len(p.PullRequest.Assignees)) | ||||
for i, user := range p.PullRequest.Assignees { | for i, user := range p.PullRequest.Assignees { | ||||
strings.Join(list, ", "), | strings.Join(list, ", "), | ||||
p.Index, p.PullRequest.Title) | p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookIssueUnassigned: | case api.HookIssueUnassigned: | ||||
title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelUpdated: | case api.HookIssueLabelUpdated: | ||||
title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueLabelCleared: | case api.HookIssueLabelCleared: | ||||
title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueSynchronized: | case api.HookIssueSynchronized: | ||||
title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueMilestoned: | case api.HookIssueMilestoned: | ||||
title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
case api.HookIssueDemilestoned: | case api.HookIssueDemilestoned: | ||||
title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | text = p.PullRequest.Body | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
} | } | ||||
title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | ||||
text = p.PullRequest.Body | |||||
color = warnColor | |||||
text = p.Review.Content | |||||
switch event { | |||||
case HookEventPullRequestApproved: | |||||
color = greenColor | |||||
case HookEventPullRequestRejected: | |||||
color = redColor | |||||
case HookEventPullRequestComment: | |||||
color = greyColor | |||||
default: | |||||
color = yellowColor | |||||
} | |||||
} | } | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
case api.HookRepoCreated: | case api.HookRepoCreated: | ||||
title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) | title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) | ||||
url = p.Repository.HTMLURL | url = p.Repository.HTMLURL | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookRepoDeleted: | case api.HookRepoDeleted: | ||||
title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) | title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) | ||||
color = warnColor | |||||
color = yellowColor | |||||
} | } | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ | ||||
case api.HookReleasePublished: | case api.HookReleasePublished: | ||||
title = fmt.Sprintf("[%s] Release created", p.Release.TagName) | title = fmt.Sprintf("[%s] Release created", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookReleaseUpdated: | case api.HookReleaseUpdated: | ||||
title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) | title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = greenColor | |||||
case api.HookReleaseDeleted: | case api.HookReleaseDeleted: | ||||
title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) | title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) | ||||
url = p.Release.URL | url = p.Release.URL | ||||
color = successColor | |||||
color = greenColor | |||||
} | } | ||||
return &MSTeamsPayload{ | return &MSTeamsPayload{ |
Changes *ChangesPayload `json:"changes,omitempty"` | Changes *ChangesPayload `json:"changes,omitempty"` | ||||
Repository *Repository `json:"repository"` | Repository *Repository `json:"repository"` | ||||
Sender *User `json:"sender"` | Sender *User `json:"sender"` | ||||
IsPull bool `json:"is_pull"` | |||||
} | } | ||||
// SetSecret modifies the secret of the IssueCommentPayload | // SetSecret modifies the secret of the IssueCommentPayload | ||||
PullRequest *PullRequest `json:"pull_request"` | PullRequest *PullRequest `json:"pull_request"` | ||||
Repository *Repository `json:"repository"` | Repository *Repository `json:"repository"` | ||||
Sender *User `json:"sender"` | Sender *User `json:"sender"` | ||||
Review *ReviewPayload `json:"review"` | |||||
} | } | ||||
// SetSecret modifies the secret of the PullRequestPayload. | // SetSecret modifies the secret of the PullRequestPayload. | ||||
return json.MarshalIndent(p, "", " ") | return json.MarshalIndent(p, "", " ") | ||||
} | } | ||||
// ReviewPayload FIXME | |||||
type ReviewPayload struct { | |||||
Type string `json:"type"` | |||||
Content string `json:"content"` | |||||
} | |||||
//__________ .__ __ | //__________ .__ __ | ||||
//\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. | //\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. | ||||
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | | // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | |
Comment: comment.APIFormat(), | Comment: comment.APIFormat(), | ||||
Repository: repo.APIFormat(mode), | Repository: repo.APIFormat(mode), | ||||
Sender: doer.APIFormat(), | Sender: doer.APIFormat(), | ||||
IsPull: issue.IsPull, | |||||
}); err != nil { | }); err != nil { | ||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) | log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) | ||||
} else { | } else { | ||||
}, | }, | ||||
Repository: c.Issue.Repo.APIFormat(mode), | Repository: c.Issue.Repo.APIFormat(mode), | ||||
Sender: doer.APIFormat(), | Sender: doer.APIFormat(), | ||||
IsPull: c.Issue.IsPull, | |||||
}); err != nil { | }); err != nil { | ||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err) | log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err) | ||||
} else { | } else { | ||||
Comment: comment.APIFormat(), | Comment: comment.APIFormat(), | ||||
Repository: comment.Issue.Repo.APIFormat(mode), | Repository: comment.Issue.Repo.APIFormat(mode), | ||||
Sender: doer.APIFormat(), | Sender: doer.APIFormat(), | ||||
IsPull: comment.Issue.IsPull, | |||||
}); err != nil { | }); err != nil { | ||||
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) | log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) | ||||
} else { | } else { |
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ | if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{ | ||||
Action: api.HookIssueSynchronized, | Action: api.HookIssueSynchronized, | ||||
Index: review.Issue.Index, | Index: review.Issue.Index, | ||||
PullRequest: pr.APIFormat(), | PullRequest: pr.APIFormat(), | ||||
Repository: review.Issue.Repo.APIFormat(mode), | Repository: review.Issue.Repo.APIFormat(mode), | ||||
Sender: review.Reviewer.APIFormat(), | Sender: review.Reviewer.APIFormat(), | ||||
Review: &api.ReviewPayload{ | |||||
Type: string(reviewHookType), | |||||
Content: review.Content, | |||||
}, | |||||
}); err != nil { | }); err != nil { | ||||
return err | return err | ||||
} | } |