summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-10-18 17:42:04 -0500
committerzeripath <art27@cantab.net>2019-10-18 23:42:04 +0100
commit0a004a69cdcad2fa13d3d314cb984718c88a2940 (patch)
tree018ee4d70bba1b9b1f5de965cb35908380614687
parent05e437f8fd29d078af4148f3b2debcb789d8bfac (diff)
downloadgitea-0a004a69cdcad2fa13d3d314cb984718c88a2940.tar.gz
gitea-0a004a69cdcad2fa13d3d314cb984718c88a2940.zip
Improve webhooks (#8583)
* 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>
-rw-r--r--models/webhook_dingtalk.go24
-rw-r--r--models/webhook_discord.go114
-rw-r--r--models/webhook_msteams.go107
-rw-r--r--modules/structs/hook.go8
-rw-r--r--services/comments/comments.go3
-rw-r--r--services/pull/review.go5
6 files changed, 167 insertions, 94 deletions
diff --git a/models/webhook_dingtalk.go b/models/webhook_dingtalk.go
index 6a4bdaf06e..1c6c0a83b8 100644
--- a/models/webhook_dingtalk.go
+++ b/models/webhook_dingtalk.go
@@ -183,22 +183,36 @@ func getDingtalkIssuesPayload(p *api.IssuePayload) (*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))
var content string
switch p.Action {
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
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
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)
content = p.Comment.Body
}
+ title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title)
+
return &DingtalkPayload{
MsgType: "actionCard",
ActionCard: dingtalk.ActionCard{
@@ -282,7 +296,7 @@ func getDingtalkPullRequestApprovalPayload(p *api.PullRequestPayload, event Hook
}
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
}
diff --git a/models/webhook_discord.go b/models/webhook_discord.go
index 0b190495f2..32039edc9d 100644
--- a/models/webhook_discord.go
+++ b/models/webhook_discord.go
@@ -75,9 +75,14 @@ func color(clr string) int {
}
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
@@ -104,7 +109,7 @@ func getDiscordCreatePayload(p *api.CreatePayload, meta *DiscordMeta) (*DiscordP
{
Title: title,
URL: p.Repo.HTMLURL + "/src/" + refName,
- Color: successColor,
+ Color: greenColor,
Author: DiscordEmbedAuthor{
Name: p.Sender.UserName,
URL: setting.AppURL + p.Sender.UserName,
@@ -127,7 +132,7 @@ func getDiscordDeletePayload(p *api.DeletePayload, meta *DiscordMeta) (*DiscordP
{
Title: title,
URL: p.Repo.HTMLURL + "/src/" + refName,
- Color: warnColor,
+ Color: redColor,
Author: DiscordEmbedAuthor{
Name: p.Sender.UserName,
URL: setting.AppURL + p.Sender.UserName,
@@ -149,7 +154,7 @@ func getDiscordForkPayload(p *api.ForkPayload, meta *DiscordMeta) (*DiscordPaylo
{
Title: title,
URL: p.Repo.HTMLURL,
- Color: successColor,
+ Color: greenColor,
Author: DiscordEmbedAuthor{
Name: p.Sender.UserName,
URL: setting.AppURL + p.Sender.UserName,
@@ -199,7 +204,7 @@ func getDiscordPushPayload(p *api.PushPayload, meta *DiscordMeta) (*DiscordPaylo
Title: title,
Description: text,
URL: titleLink,
- Color: successColor,
+ Color: greenColor,
Author: DiscordEmbedAuthor{
Name: p.Sender.UserName,
URL: setting.AppURL + p.Sender.UserName,
@@ -218,48 +223,48 @@ func getDiscordIssuesPayload(p *api.IssuePayload, meta *DiscordMeta) (*DiscordPa
case api.HookIssueOpened:
title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = orangeColor
case api.HookIssueClosed:
title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
- color = failedColor
+ color = redColor
text = p.Issue.Body
case api.HookIssueReOpened:
title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueEdited:
title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueAssigned:
title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName,
p.Issue.Assignee.UserName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = successColor
+ color = greenColor
case api.HookIssueUnassigned:
title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelUpdated:
title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelCleared:
title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueSynchronized:
title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueMilestoned:
title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueDemilestoned:
title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
}
return &DiscordPayload{
@@ -282,26 +287,41 @@ func getDiscordIssuesPayload(p *api.IssuePayload, meta *DiscordMeta) (*DiscordPa
}
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))
content := ""
var color int
switch p.Action {
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
- color = successColor
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
- color = warnColor
+ color = yellowColor
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)
content = p.Comment.Body
- color = warnColor
+ color = redColor
}
+ title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title)
+
return &DiscordPayload{
Username: discord.Username,
AvatarURL: discord.IconURL,
@@ -328,24 +348,24 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, meta *DiscordMeta)
case api.HookIssueOpened:
title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = greenColor
case api.HookIssueClosed:
if p.PullRequest.HasMerged {
title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
- color = successColor
+ color = purpleColor
} else {
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
case api.HookIssueReOpened:
title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueEdited:
title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueAssigned:
list := make([]string, len(p.PullRequest.Assignees))
for i, user := range p.PullRequest.Assignees {
@@ -355,31 +375,31 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, meta *DiscordMeta)
strings.Join(list, ", "),
p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = successColor
+ color = greenColor
case api.HookIssueUnassigned:
title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelUpdated:
title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelCleared:
title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueSynchronized:
title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueMilestoned:
title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueDemilestoned:
title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
}
return &DiscordPayload{
@@ -412,17 +432,17 @@ func getDiscordPullRequestApprovalPayload(p *api.PullRequestPayload, meta *Disco
}
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 {
case HookEventPullRequestApproved:
- color = successColor
+ color = greenColor
case HookEventPullRequestRejected:
- color = failedColor
+ color = redColor
case HookEventPullRequestComment:
- fallthrough
+ color = greyColor
default:
- color = warnColor
+ color = yellowColor
}
}
@@ -452,10 +472,10 @@ func getDiscordRepositoryPayload(p *api.RepositoryPayload, meta *DiscordMeta) (*
case api.HookRepoCreated:
title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName)
url = p.Repository.HTMLURL
- color = successColor
+ color = greenColor
case api.HookRepoDeleted:
title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName)
- color = warnColor
+ color = redColor
}
return &DiscordPayload{
@@ -483,15 +503,15 @@ func getDiscordReleasePayload(p *api.ReleasePayload, meta *DiscordMeta) (*Discor
case api.HookReleasePublished:
title = fmt.Sprintf("[%s] Release created", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = greenColor
case api.HookReleaseUpdated:
title = fmt.Sprintf("[%s] Release updated", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = yellowColor
case api.HookReleaseDeleted:
title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = redColor
}
return &DiscordPayload{
diff --git a/models/webhook_msteams.go b/models/webhook_msteams.go
index bdbcdbc9d3..e8cdcca3ca 100644
--- a/models/webhook_msteams.go
+++ b/models/webhook_msteams.go
@@ -74,7 +74,7 @@ func getMSTeamsCreatePayload(p *api.CreatePayload) (*MSTeamsPayload, error) {
return &MSTeamsPayload{
Type: "MessageCard",
Context: "https://schema.org/extensions",
- ThemeColor: fmt.Sprintf("%x", successColor),
+ ThemeColor: fmt.Sprintf("%x", greenColor),
Title: title,
Summary: title,
Sections: []MSTeamsSection{
@@ -117,7 +117,7 @@ func getMSTeamsDeletePayload(p *api.DeletePayload) (*MSTeamsPayload, error) {
return &MSTeamsPayload{
Type: "MessageCard",
Context: "https://schema.org/extensions",
- ThemeColor: fmt.Sprintf("%x", warnColor),
+ ThemeColor: fmt.Sprintf("%x", yellowColor),
Title: title,
Summary: title,
Sections: []MSTeamsSection{
@@ -159,7 +159,7 @@ func getMSTeamsForkPayload(p *api.ForkPayload) (*MSTeamsPayload, error) {
return &MSTeamsPayload{
Type: "MessageCard",
Context: "https://schema.org/extensions",
- ThemeColor: fmt.Sprintf("%x", successColor),
+ ThemeColor: fmt.Sprintf("%x", greenColor),
Title: title,
Summary: title,
Sections: []MSTeamsSection{
@@ -228,7 +228,7 @@ func getMSTeamsPushPayload(p *api.PushPayload) (*MSTeamsPayload, error) {
return &MSTeamsPayload{
Type: "MessageCard",
Context: "https://schema.org/extensions",
- ThemeColor: fmt.Sprintf("%x", successColor),
+ ThemeColor: fmt.Sprintf("%x", greenColor),
Title: title,
Summary: title,
Sections: []MSTeamsSection{
@@ -272,48 +272,48 @@ func getMSTeamsIssuesPayload(p *api.IssuePayload) (*MSTeamsPayload, error) {
case api.HookIssueOpened:
title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = orangeColor
case api.HookIssueClosed:
title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
- color = failedColor
+ color = redColor
text = p.Issue.Body
case api.HookIssueReOpened:
title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueEdited:
title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueAssigned:
title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName,
p.Issue.Assignee.UserName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = successColor
+ color = greenColor
case api.HookIssueUnassigned:
title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelUpdated:
title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelCleared:
title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueSynchronized:
title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueMilestoned:
title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueDemilestoned:
title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
text = p.Issue.Body
- color = warnColor
+ color = yellowColor
}
return &MSTeamsPayload{
@@ -356,26 +356,41 @@ func getMSTeamsIssuesPayload(p *api.IssuePayload) (*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))
content := ""
var color int
switch p.Action {
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
- color = successColor
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
- color = warnColor
+ color = yellowColor
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)
content = p.Comment.Body
- color = warnColor
+ color = redColor
}
+ title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title)
+
return &MSTeamsPayload{
Type: "MessageCard",
Context: "https://schema.org/extensions",
@@ -422,24 +437,24 @@ func getMSTeamsPullRequestPayload(p *api.PullRequestPayload) (*MSTeamsPayload, e
case api.HookIssueOpened:
title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = greenColor
case api.HookIssueClosed:
if p.PullRequest.HasMerged {
title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
- color = successColor
+ color = purpleColor
} else {
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
case api.HookIssueReOpened:
title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueEdited:
title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueAssigned:
list := make([]string, len(p.PullRequest.Assignees))
for i, user := range p.PullRequest.Assignees {
@@ -449,31 +464,31 @@ func getMSTeamsPullRequestPayload(p *api.PullRequestPayload) (*MSTeamsPayload, e
strings.Join(list, ", "),
p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = successColor
+ color = greenColor
case api.HookIssueUnassigned:
title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelUpdated:
title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueLabelCleared:
title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueSynchronized:
title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueMilestoned:
title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
case api.HookIssueDemilestoned:
title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
- color = warnColor
+ color = yellowColor
}
return &MSTeamsPayload{
@@ -526,8 +541,18 @@ func getMSTeamsPullRequestApprovalPayload(p *api.PullRequestPayload, event HookE
}
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{
@@ -576,10 +601,10 @@ func getMSTeamsRepositoryPayload(p *api.RepositoryPayload) (*MSTeamsPayload, err
case api.HookRepoCreated:
title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName)
url = p.Repository.HTMLURL
- color = successColor
+ color = greenColor
case api.HookRepoDeleted:
title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName)
- color = warnColor
+ color = yellowColor
}
return &MSTeamsPayload{
@@ -623,15 +648,15 @@ func getMSTeamsReleasePayload(p *api.ReleasePayload) (*MSTeamsPayload, error) {
case api.HookReleasePublished:
title = fmt.Sprintf("[%s] Release created", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = greenColor
case api.HookReleaseUpdated:
title = fmt.Sprintf("[%s] Release updated", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = greenColor
case api.HookReleaseDeleted:
title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName)
url = p.Release.URL
- color = successColor
+ color = greenColor
}
return &MSTeamsPayload{
diff --git a/modules/structs/hook.go b/modules/structs/hook.go
index 2c923d36c5..e036442904 100644
--- a/modules/structs/hook.go
+++ b/modules/structs/hook.go
@@ -236,6 +236,7 @@ type IssueCommentPayload struct {
Changes *ChangesPayload `json:"changes,omitempty"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
+ IsPull bool `json:"is_pull"`
}
// SetSecret modifies the secret of the IssueCommentPayload
@@ -419,6 +420,7 @@ type PullRequestPayload struct {
PullRequest *PullRequest `json:"pull_request"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
+ Review *ReviewPayload `json:"review"`
}
// SetSecret modifies the secret of the PullRequestPayload.
@@ -431,6 +433,12 @@ func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
+// ReviewPayload FIXME
+type ReviewPayload struct {
+ Type string `json:"type"`
+ Content string `json:"content"`
+}
+
//__________ .__ __
//\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
diff --git a/services/comments/comments.go b/services/comments/comments.go
index e8448e9065..010c0aaac7 100644
--- a/services/comments/comments.go
+++ b/services/comments/comments.go
@@ -38,6 +38,7 @@ func CreateIssueComment(doer *models.User, repo *models.Repository, issue *model
Comment: comment.APIFormat(),
Repository: repo.APIFormat(mode),
Sender: doer.APIFormat(),
+ IsPull: issue.IsPull,
}); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
@@ -128,6 +129,7 @@ func UpdateComment(c *models.Comment, doer *models.User, oldContent string) erro
},
Repository: c.Issue.Repo.APIFormat(mode),
Sender: doer.APIFormat(),
+ IsPull: c.Issue.IsPull,
}); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
} else {
@@ -162,6 +164,7 @@ func DeleteComment(comment *models.Comment, doer *models.User) error {
Comment: comment.APIFormat(),
Repository: comment.Issue.Repo.APIFormat(mode),
Sender: doer.APIFormat(),
+ IsPull: comment.Issue.IsPull,
}); err != nil {
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
diff --git a/services/pull/review.go b/services/pull/review.go
index 261c2d32d2..3388e4bb56 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -55,13 +55,16 @@ func reviewHook(review *models.Review) error {
if err != nil {
return err
}
-
if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
Action: api.HookIssueSynchronized,
Index: review.Issue.Index,
PullRequest: pr.APIFormat(),
Repository: review.Issue.Repo.APIFormat(mode),
Sender: review.Reviewer.APIFormat(),
+ Review: &api.ReviewPayload{
+ Type: string(reviewHookType),
+ Content: review.Content,
+ },
}); err != nil {
return err
}