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/issue.go | |
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/issue.go')
-rw-r--r-- | models/issue.go | 101 |
1 files changed, 93 insertions, 8 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 } |