aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_milestone.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-05-16 22:01:55 +0800
committerGitHub <noreply@github.com>2018-05-16 22:01:55 +0800
commit24941a10464dc27eaebafda2a208fa827b74ff8d (patch)
treec875dd6b7d659e2dbd926dbd3a04a036f9f41c94 /models/issue_milestone.go
parent188fe6c301f9c44d569b75cb339d6a6b3f6e03ad (diff)
downloadgitea-24941a10464dc27eaebafda2a208fa827b74ff8d.tar.gz
gitea-24941a10464dc27eaebafda2a208fa827b74ff8d.zip
Add more webhooks support and refactor webhook templates directory (#3929)
* add more webhook support * move hooks templates to standalone dir and add more webhooks ui * fix tests * update vendor checksum * add more webhook support * move hooks templates to standalone dir and add more webhooks ui * fix tests * update vendor checksum * update vendor Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * load attributes when created release * update comparsion doc
Diffstat (limited to 'models/issue_milestone.go')
-rw-r--r--models/issue_milestone.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index 8de1f97571..be55dc4f5b 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -5,6 +5,9 @@
package models
import (
+ "fmt"
+
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"
@@ -358,7 +361,49 @@ func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err
if err = changeMilestoneAssign(sess, doer, issue, oldMilestoneID); err != nil {
return err
}
- return sess.Commit()
+
+ if err = sess.Commit(); err != nil {
+ return fmt.Errorf("Commit: %v", err)
+ }
+
+ var hookAction api.HookIssueAction
+ if issue.MilestoneID > 0 {
+ hookAction = api.HookIssueMilestoned
+ } else {
+ hookAction = api.HookIssueDemilestoned
+ }
+
+ if err = issue.LoadAttributes(); err != nil {
+ return err
+ }
+
+ mode, _ := AccessLevel(doer.ID, issue.Repo)
+ if issue.IsPull {
+ err = issue.PullRequest.LoadIssue()
+ if err != nil {
+ log.Error(2, "LoadIssue: %v", err)
+ return
+ }
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: hookAction,
+ Index: issue.Index,
+ PullRequest: issue.PullRequest.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ })
+ } else {
+ err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
+ Action: hookAction,
+ Index: issue.Index,
+ Issue: issue.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ })
+ }
+ if err != nil {
+ log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
+ }
+ return nil
}
// DeleteMilestoneByRepoID deletes a milestone from a repository.