diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-05-21 10:28:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-21 10:28:29 +0800 |
commit | 6bdc556b7f490be7360104b731ce817050cc1d80 (patch) | |
tree | 63887addb45b5b2be1e672580c984497fa9f4112 /models | |
parent | dc0ef38950ec8aca78f6e870fb83d1ca68074682 (diff) | |
download | gitea-6bdc556b7f490be7360104b731ce817050cc1d80.tar.gz gitea-6bdc556b7f490be7360104b731ce817050cc1d80.zip |
Fix some webhooks bugs (#3981)
* fix some webhooks bugs
* update vendor
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* fix test
* fix clearlabels
* fix pullrequest webhook bug fix #3492
* update release webhook description
* remove unused code
* fix push webhook in pull request
* small changes
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 101 | ||||
-rw-r--r-- | models/issue_assignees.go | 26 | ||||
-rw-r--r-- | models/issue_comment.go | 6 | ||||
-rw-r--r-- | models/issue_milestone.go | 2 | ||||
-rw-r--r-- | models/issue_user.go | 12 | ||||
-rw-r--r-- | models/pull.go | 19 | ||||
-rw-r--r-- | models/release.go | 33 | ||||
-rw-r--r-- | models/repo.go | 6 | ||||
-rw-r--r-- | models/webhook_dingtalk.go | 63 | ||||
-rw-r--r-- | models/webhook_discord.go | 24 | ||||
-rw-r--r-- | models/webhook_slack.go | 12 |
11 files changed, 267 insertions, 37 deletions
diff --git a/models/issue.go b/models/issue.go index ad354cc34e..d97266b4ed 100644 --- a/models/issue.go +++ b/models/issue.go @@ -370,11 +370,19 @@ func (issue *Issue) HasLabel(labelID int64) bool { func (issue *Issue) sendLabelUpdatedWebhook(doer *User) { var err error + + if err = issue.loadRepo(x); err != nil { + log.Error(4, "loadRepo: %v", err) + return + } + + if err = issue.loadPoster(x); err != nil { + log.Error(4, "loadPoster: %v", err) + return + } + + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) if issue.IsPull { - if err = issue.loadRepo(x); err != nil { - log.Error(4, "loadRepo: %v", err) - return - } if err = issue.loadPullRequest(x); err != nil { log.Error(4, "loadPullRequest: %v", err) return @@ -390,6 +398,14 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) { Repository: issue.Repo.APIFormat(AccessModeNone), Sender: doer.APIFormat(), }) + } else { + err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueLabelUpdated, + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) } if err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) @@ -505,6 +521,11 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { return fmt.Errorf("Commit: %v", err) } + if err = issue.loadPoster(x); err != nil { + return fmt.Errorf("loadPoster: %v", err) + } + + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) if issue.IsPull { err = issue.PullRequest.LoadIssue() if err != nil { @@ -515,9 +536,17 @@ func (issue *Issue) ClearLabels(doer *User) (err error) { Action: api.HookIssueLabelCleared, Index: issue.Index, PullRequest: issue.PullRequest.APIFormat(), - Repository: issue.Repo.APIFormat(AccessModeNone), + Repository: issue.Repo.APIFormat(mode), Sender: doer.APIFormat(), }) + } else { + err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueLabelCleared, + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) } if err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) @@ -675,13 +704,14 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e return fmt.Errorf("Commit: %v", err) } + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) if issue.IsPull { // Merge pull request calls issue.changeStatus so we need to handle separately. issue.PullRequest.Issue = issue apiPullRequest := &api.PullRequestPayload{ Index: issue.Index, PullRequest: issue.PullRequest.APIFormat(), - Repository: repo.APIFormat(AccessModeNone), + Repository: repo.APIFormat(mode), Sender: doer.APIFormat(), } if isClosed { @@ -690,6 +720,19 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e apiPullRequest.Action = api.HookIssueReOpened } err = PrepareWebhooks(repo, HookEventPullRequest, apiPullRequest) + } else { + apiIssue := &api.IssuePayload{ + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: repo.APIFormat(mode), + Sender: doer.APIFormat(), + } + if isClosed { + apiIssue.Action = api.HookIssueClosed + } else { + apiIssue.Action = api.HookIssueReOpened + } + err = PrepareWebhooks(repo, HookEventIssues, apiIssue) } if err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err) @@ -723,6 +766,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) { return err } + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) if issue.IsPull { issue.PullRequest.Issue = issue err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{ @@ -734,10 +778,24 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) { }, }, PullRequest: issue.PullRequest.APIFormat(), - Repository: issue.Repo.APIFormat(AccessModeNone), + Repository: issue.Repo.APIFormat(mode), Sender: doer.APIFormat(), }) + } else { + err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueEdited, + Index: issue.Index, + Changes: &api.ChangesPayload{ + Title: &api.ChangesFromPayload{ + From: oldTitle, + }, + }, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: issue.Poster.APIFormat(), + }) } + if err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) } else { @@ -774,6 +832,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { return fmt.Errorf("UpdateIssueCols: %v", err) } + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) if issue.IsPull { issue.PullRequest.Issue = issue err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{ @@ -785,9 +844,22 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { }, }, PullRequest: issue.PullRequest.APIFormat(), - Repository: issue.Repo.APIFormat(AccessModeNone), + Repository: issue.Repo.APIFormat(mode), Sender: doer.APIFormat(), }) + } else { + err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueEdited, + Index: issue.Index, + Changes: &api.ChangesPayload{ + Body: &api.ChangesFromPayload{ + From: oldContent, + }, + }, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) } if err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) @@ -980,6 +1052,19 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in log.Error(4, "MailParticipants: %v", err) } + mode, _ := AccessLevel(issue.Poster.ID, issue.Repo) + if err = PrepareWebhooks(repo, HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueOpened, + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: repo.APIFormat(mode), + Sender: issue.Poster.APIFormat(), + }); err != nil { + log.Error(4, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(issue.RepoID) + } + return nil } diff --git a/models/issue_assignees.go b/models/issue_assignees.go index 3e68126a6c..24773cc576 100644 --- a/models/issue_assignees.go +++ b/models/issue_assignees.go @@ -159,12 +159,16 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in return fmt.Errorf("createAssigneeComment: %v", err) } + mode, _ := accessLevel(sess, doer.ID, issue.Repo) if issue.IsPull { - issue.PullRequest = &PullRequest{Issue: issue} + if err = issue.loadPullRequest(sess); err != nil { + return fmt.Errorf("loadPullRequest: %v", err) + } + issue.PullRequest.Issue = issue apiPullRequest := &api.PullRequestPayload{ Index: issue.Index, PullRequest: issue.PullRequest.APIFormat(), - Repository: issue.Repo.APIFormat(AccessModeNone), + Repository: issue.Repo.APIFormat(mode), Sender: doer.APIFormat(), } if removed { @@ -172,7 +176,23 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in } else { apiPullRequest.Action = api.HookIssueAssigned } - if err := PrepareWebhooks(issue.Repo, HookEventPullRequest, apiPullRequest); err != nil { + if err := prepareWebhooks(sess, issue.Repo, HookEventPullRequest, apiPullRequest); err != nil { + log.Error(4, "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err) + return nil + } + } else { + apiIssue := &api.IssuePayload{ + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + } + if removed { + apiIssue.Action = api.HookIssueUnassigned + } else { + apiIssue.Action = api.HookIssueAssigned + } + if err := prepareWebhooks(sess, issue.Repo, HookEventIssues, apiIssue); err != nil { log.Error(4, "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, removed, err) return nil } diff --git a/models/issue_comment.go b/models/issue_comment.go index ad200934bc..a829c80663 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -612,6 +612,8 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri Sender: doer.APIFormat(), }); err != nil { log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) + } else { + go HookQueue.Add(repo.ID) } return comment, nil } @@ -754,6 +756,8 @@ func UpdateComment(doer *User, c *Comment, oldContent string) error { Sender: doer.APIFormat(), }); err != nil { log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err) + } else { + go HookQueue.Add(c.Issue.Repo.ID) } return nil @@ -805,6 +809,8 @@ func DeleteComment(doer *User, comment *Comment) error { Sender: doer.APIFormat(), }); err != nil { log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err) + } else { + go HookQueue.Add(comment.Issue.Repo.ID) } return nil diff --git a/models/issue_milestone.go b/models/issue_milestone.go index be55dc4f5b..177984a1f1 100644 --- a/models/issue_milestone.go +++ b/models/issue_milestone.go @@ -402,6 +402,8 @@ func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err } if err != nil { log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + } else { + go HookQueue.Add(issue.RepoID) } return nil } diff --git a/models/issue_user.go b/models/issue_user.go index de5a185aec..733c35df1f 100644 --- a/models/issue_user.go +++ b/models/issue_user.go @@ -54,28 +54,30 @@ func newIssueUsers(e Engine, repo *Repository, issue *Issue) error { func updateIssueAssignee(e *xorm.Session, issue *Issue, assigneeID int64) (removed bool, err error) { // Check if the user exists - _, err = GetUserByID(assigneeID) + assignee, err := GetUserByID(assigneeID) if err != nil { return false, err } // Check if the submitted user is already assigne, if yes delete him otherwise add him - var toBeDeleted bool - for _, assignee := range issue.Assignees { - if assignee.ID == assigneeID { - toBeDeleted = true + var i int + for i = 0; i < len(issue.Assignees); i++ { + if issue.Assignees[i].ID == assigneeID { break } } assigneeIn := IssueAssignees{AssigneeID: assigneeID, IssueID: issue.ID} + toBeDeleted := i < len(issue.Assignees) if toBeDeleted { + issue.Assignees = append(issue.Assignees[:i], issue.Assignees[i:]...) _, err = e.Delete(assigneeIn) if err != nil { return toBeDeleted, err } } else { + issue.Assignees = append(issue.Assignees, assignee) _, err = e.Insert(assigneeIn) if err != nil { return toBeDeleted, err diff --git a/models/pull.go b/models/pull.go index d23d885b6c..90b341907d 100644 --- a/models/pull.go +++ b/models/pull.go @@ -457,15 +457,18 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle log.Error(4, "LoadAttributes: %v", err) return nil } + + mode, _ := AccessLevel(doer.ID, pr.Issue.Repo) if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{ Action: api.HookIssueClosed, Index: pr.Index, PullRequest: pr.APIFormat(), - Repository: pr.Issue.Repo.APIFormat(AccessModeNone), + Repository: pr.Issue.Repo.APIFormat(mode), Sender: doer.APIFormat(), }); err != nil { log.Error(4, "PrepareWebhooks: %v", err) - return nil + } else { + go HookQueue.Add(pr.Issue.Repo.ID) } l, err := baseGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase) @@ -492,12 +495,14 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle After: mergeCommit.ID.String(), CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID), Commits: ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()), - Repo: pr.BaseRepo.APIFormat(AccessModeNone), + Repo: pr.BaseRepo.APIFormat(mode), Pusher: pr.HeadRepo.MustOwner().APIFormat(), Sender: doer.APIFormat(), } if err = PrepareWebhooks(pr.BaseRepo, HookEventPush, p); err != nil { - return fmt.Errorf("PrepareWebhooks: %v", err) + log.Error(4, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(pr.BaseRepo.ID) } return nil } @@ -782,16 +787,18 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str pr.Issue = pull pull.PullRequest = pr + mode, _ := AccessLevel(pull.Poster.ID, repo) if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{ Action: api.HookIssueOpened, Index: pull.Index, PullRequest: pr.APIFormat(), - Repository: repo.APIFormat(AccessModeNone), + Repository: repo.APIFormat(mode), Sender: pull.Poster.APIFormat(), }); err != nil { log.Error(4, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(repo.ID) } - go HookQueue.Add(repo.ID) return nil } diff --git a/models/release.go b/models/release.go index bc0260c71d..630995a741 100644 --- a/models/release.go +++ b/models/release.go @@ -207,6 +207,8 @@ func CreateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []stri Sender: rel.Publisher.APIFormat(), }); err != nil { log.Error(2, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(rel.Repo.ID) } } } @@ -371,7 +373,7 @@ func SortReleases(rels []*Release) { } // UpdateRelease updates information of a release. -func UpdateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []string) (err error) { +func UpdateRelease(doer *User, gitRepo *git.Repository, rel *Release, attachmentUUIDs []string) (err error) { if err = createTag(gitRepo, rel); err != nil { return err } @@ -382,8 +384,25 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []stri return err } + err = rel.loadAttributes(x) + if err != nil { + return err + } + err = addReleaseAttachments(rel.ID, attachmentUUIDs) + mode, _ := accessLevel(x, doer.ID, rel.Repo) + if err1 := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{ + Action: api.HookReleaseUpdated, + Release: rel.APIFormat(), + Repository: rel.Repo.APIFormat(mode), + Sender: rel.Publisher.APIFormat(), + }); err1 != nil { + log.Error(2, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(rel.Repo.ID) + } + return err } @@ -429,6 +448,18 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error { } } + mode, _ := accessLevel(x, u.ID, rel.Repo) + if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{ + Action: api.HookReleaseDeleted, + Release: rel.APIFormat(), + Repository: rel.Repo.APIFormat(mode), + Sender: rel.Publisher.APIFormat(), + }); err != nil { + log.Error(2, "PrepareWebhooks: %v", err) + } else { + go HookQueue.Add(rel.Repo.ID) + } + return nil } diff --git a/models/repo.go b/models/repo.go index f5ec1a9fdd..88e9f71742 100644 --- a/models/repo.go +++ b/models/repo.go @@ -2460,11 +2460,13 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R mode, _ := AccessLevel(doer.ID, repo) if err = PrepareWebhooks(oldRepo, HookEventFork, &api.ForkPayload{ - Forkee: repo.APIFormat(mode), - Repo: oldRepo.APIFormat(oldMode), + Forkee: oldRepo.APIFormat(oldMode), + Repo: repo.APIFormat(mode), Sender: doer.APIFormat(), }); err != nil { log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err) + } else { + go HookQueue.Add(oldRepo.ID) } if err = repo.UpdateSize(); err != nil { diff --git a/models/webhook_dingtalk.go b/models/webhook_dingtalk.go index 7eb189f9bb..06388a6ba2 100644 --- a/models/webhook_dingtalk.go +++ b/models/webhook_dingtalk.go @@ -43,7 +43,7 @@ func getDingtalkCreatePayload(p *api.CreatePayload) (*DingtalkPayload, error) { Text: title, Title: title, HideAvatar: "0", - SingleTitle: fmt.Sprintf("view branch %s", refName), + SingleTitle: fmt.Sprintf("view ref %s", refName), SingleURL: p.Repo.HTMLURL + "/src/" + refName, }, }, nil @@ -60,7 +60,7 @@ func getDingtalkDeletePayload(p *api.DeletePayload) (*DingtalkPayload, error) { Text: title, Title: title, HideAvatar: "0", - SingleTitle: fmt.Sprintf("view branch %s", refName), + SingleTitle: fmt.Sprintf("view ref %s", refName), SingleURL: p.Repo.HTMLURL + "/src/" + refName, }, }, nil @@ -153,23 +153,30 @@ func getDingtalkIssuesPayload(p *api.IssuePayload) (*DingtalkPayload, error) { title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) text = p.Issue.Body case api.HookIssueLabelUpdated: - title = fmt.Sprintf("[%s] Pull request 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 case api.HookIssueLabelCleared: - title = fmt.Sprintf("[%s] Pull request 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 case api.HookIssueSynchronized: - title = fmt.Sprintf("[%s] Pull request 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 + case api.HookIssueMilestoned: + title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) + text = p.Issue.Body + case api.HookIssueDemilestoned: + title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) text = p.Issue.Body } return &DingtalkPayload{ MsgType: "actionCard", ActionCard: dingtalk.ActionCard{ - Text: text, + Text: title + "\r\n\r\n" + text, + //Markdown: "# " + title + "\n" + text, Title: title, HideAvatar: "0", - SingleTitle: "view pull request", + SingleTitle: "view issue", SingleURL: p.Issue.URL, }, }, nil @@ -195,10 +202,10 @@ func getDingtalkIssueCommentPayload(p *api.IssueCommentPayload) (*DingtalkPayloa return &DingtalkPayload{ MsgType: "actionCard", ActionCard: dingtalk.ActionCard{ - Text: content, + Text: title + "\r\n\r\n" + content, Title: title, HideAvatar: "0", - SingleTitle: "view pull request", + SingleTitle: "view issue comment", SingleURL: url, }, }, nil @@ -243,12 +250,19 @@ func getDingtalkPullRequestPayload(p *api.PullRequestPayload) (*DingtalkPayload, case api.HookIssueSynchronized: title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) text = p.PullRequest.Body + case api.HookIssueMilestoned: + title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) + text = p.PullRequest.Body + 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 } return &DingtalkPayload{ MsgType: "actionCard", ActionCard: dingtalk.ActionCard{ - Text: text, + Text: title + "\r\n\r\n" + text, + //Markdown: "# " + title + "\n" + text, Title: title, HideAvatar: "0", SingleTitle: "view pull request", @@ -300,7 +314,34 @@ func getDingtalkReleasePayload(p *api.ReleasePayload) (*DingtalkPayload, error) Text: title, Title: title, HideAvatar: "0", - SingleTitle: "view repository", + SingleTitle: "view release", + SingleURL: url, + }, + }, nil + case api.HookReleaseUpdated: + title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) + url = p.Release.URL + return &DingtalkPayload{ + MsgType: "actionCard", + ActionCard: dingtalk.ActionCard{ + Text: title, + Title: title, + HideAvatar: "0", + SingleTitle: "view release", + SingleURL: url, + }, + }, nil + + case api.HookReleaseDeleted: + title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) + url = p.Release.URL + return &DingtalkPayload{ + MsgType: "actionCard", + ActionCard: dingtalk.ActionCard{ + Text: title, + Title: title, + HideAvatar: "0", + SingleTitle: "view release", SingleURL: url, }, }, nil diff --git a/models/webhook_discord.go b/models/webhook_discord.go index 04ebbc293f..95fca2ee6f 100644 --- a/models/webhook_discord.go +++ b/models/webhook_discord.go @@ -251,6 +251,14 @@ func getDiscordIssuesPayload(p *api.IssuePayload, meta *DiscordMeta) (*DiscordPa title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) text = p.Issue.Body color = warnColor + 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 + 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 } return &DiscordPayload{ @@ -362,6 +370,14 @@ func getDiscordPullRequestPayload(p *api.PullRequestPayload, meta *DiscordMeta) title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) text = p.PullRequest.Body color = warnColor + 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 + 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 } return &DiscordPayload{ @@ -422,6 +438,14 @@ func getDiscordReleasePayload(p *api.ReleasePayload, meta *DiscordMeta) (*Discor title = fmt.Sprintf("[%s] Release created", p.Release.TagName) url = p.Release.URL color = successColor + case api.HookReleaseUpdated: + title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) + url = p.Release.URL + color = successColor + case api.HookReleaseDeleted: + title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) + url = p.Release.URL + color = successColor } return &DiscordPayload{ diff --git a/models/webhook_slack.go b/models/webhook_slack.go index 7b18fe3278..23df17bf2c 100644 --- a/models/webhook_slack.go +++ b/models/webhook_slack.go @@ -213,7 +213,17 @@ func getSlackIssueCommentPayload(p *api.IssueCommentPayload, slack *SlackMeta) ( func getSlackReleasePayload(p *api.ReleasePayload, slack *SlackMeta) (*SlackPayload, error) { repoLink := SlackLinkFormatter(p.Repository.HTMLURL, p.Repository.Name) refLink := SlackLinkFormatter(p.Repository.HTMLURL+"/src/"+p.Release.TagName, p.Release.TagName) - text := fmt.Sprintf("[%s] new release %s published by %s", repoLink, refLink, p.Sender.UserName) + var text string + + switch p.Action { + case api.HookReleasePublished: + text = fmt.Sprintf("[%s] new release %s published by %s", repoLink, refLink, p.Sender.UserName) + case api.HookReleaseUpdated: + text = fmt.Sprintf("[%s] new release %s updated by %s", repoLink, refLink, p.Sender.UserName) + case api.HookReleaseDeleted: + text = fmt.Sprintf("[%s] new release %s deleted by %s", repoLink, refLink, p.Sender.UserName) + } + return &SlackPayload{ Channel: slack.Channel, Text: text, |