From 6bdc556b7f490be7360104b731ce817050cc1d80 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 21 May 2018 10:28:29 +0800 Subject: Fix some webhooks bugs (#3981) * fix some webhooks bugs * update vendor Signed-off-by: Bo-Yi Wu * 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 --- models/issue_assignees.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'models/issue_assignees.go') 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 } -- cgit v1.2.3