From 5cca840bb8aefc937c0cc9071c2467995d6168c6 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 18 Feb 2019 03:38:26 +0000 Subject: [PATCH] Fix deadlock in webhook PullRequest (#6102) (#6104) Signed-off-by: Andrew Thornton --- models/webhook_dingtalk.go | 9 +++++---- models/webhook_discord.go | 11 ++++++----- models/webhook_slack.go | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/models/webhook_dingtalk.go b/models/webhook_dingtalk.go index dbbbebcd9..1021ab35f 100644 --- a/models/webhook_dingtalk.go +++ b/models/webhook_dingtalk.go @@ -230,12 +230,13 @@ func getDingtalkPullRequestPayload(p *api.PullRequestPayload) (*DingtalkPayload, title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) text = p.PullRequest.Body case api.HookIssueAssigned: - list, err := MakeAssigneeList(&Issue{ID: p.PullRequest.ID}) - if err != nil { - return &DingtalkPayload{}, err + list := make([]string, len(p.PullRequest.Assignees)) + for i, user := range p.PullRequest.Assignees { + list[i] = user.UserName } title = fmt.Sprintf("[%s] Pull request assigned to %s: #%d %s", p.Repository.FullName, - list, p.Index, p.PullRequest.Title) + strings.Join(list, ", "), + p.Index, p.PullRequest.Title) text = p.PullRequest.Body case api.HookIssueUnassigned: title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) diff --git a/models/webhook_discord.go b/models/webhook_discord.go index 4011880ea..893e78096 100644 --- a/models/webhook_discord.go +++ b/models/webhook_discord.go @@ -347,12 +347,13 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, meta *DiscordMeta) text = p.PullRequest.Body color = warnColor case api.HookIssueAssigned: - list, err := MakeAssigneeList(&Issue{ID: p.PullRequest.ID}) - if err != nil { - return &DiscordPayload{}, err + list := make([]string, len(p.PullRequest.Assignees)) + for i, user := range p.PullRequest.Assignees { + list[i] = user.UserName } - title = fmt.Sprintf("[%s] Pull request assigned to %s: #%d %s", p.Repository.FullName, - list, p.Index, p.PullRequest.Title) + title = fmt.Sprintf("[%s] Pull request assigned to %s: #%d by %s", p.Repository.FullName, + strings.Join(list, ", "), + p.Index, p.PullRequest.Title) text = p.PullRequest.Body color = successColor case api.HookIssueUnassigned: diff --git a/models/webhook_slack.go b/models/webhook_slack.go index 5c67951fb..90d5ccce0 100644 --- a/models/webhook_slack.go +++ b/models/webhook_slack.go @@ -301,12 +301,12 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S text = fmt.Sprintf("[%s] Pull request edited: %s by %s", p.Repository.FullName, titleLink, senderLink) attachmentText = SlackTextFormatter(p.PullRequest.Body) case api.HookIssueAssigned: - list, err := MakeAssigneeList(&Issue{ID: p.PullRequest.ID}) - if err != nil { - return &SlackPayload{}, err + list := make([]string, len(p.PullRequest.Assignees)) + for i, user := range p.PullRequest.Assignees { + list[i] = SlackLinkFormatter(setting.AppURL+user.UserName, user.UserName) } text = fmt.Sprintf("[%s] Pull request assigned to %s: %s by %s", p.Repository.FullName, - SlackLinkFormatter(setting.AppURL+list, list), + strings.Join(list, ", "), titleLink, senderLink) case api.HookIssueUnassigned: text = fmt.Sprintf("[%s] Pull request unassigned: %s by %s", p.Repository.FullName, titleLink, senderLink)