summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-02 06:51:22 +0800
committerzeripath <art27@cantab.net>2019-11-01 22:51:22 +0000
commit0e7f7df3cf176640c66ddf286ec052c7c13beb8a (patch)
tree16afa02dd0b3df428aa7d9daadd4796eef907332 /services
parentba336f6f456835f1f327ee967991079dd220266d (diff)
downloadgitea-0e7f7df3cf176640c66ddf286ec052c7c13beb8a.tar.gz
gitea-0e7f7df3cf176640c66ddf286ec052c7c13beb8a.zip
Move webhook to a standalone package under modules (#8747)
* Move webhook to a standalone package under modules * fix test * fix comments
Diffstat (limited to 'services')
-rw-r--r--services/issue/label.go7
-rw-r--r--services/milestone/milestone.go7
-rw-r--r--services/mirror/sync.go5
-rw-r--r--services/pull/merge.go5
-rw-r--r--services/pull/pull.go9
-rw-r--r--services/pull/review.go5
-rw-r--r--services/release/release.go13
7 files changed, 29 insertions, 22 deletions
diff --git a/services/issue/label.go b/services/issue/label.go
index b393e5d38c..bb36d58492 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/webhook"
)
func sendLabelUpdatedWebhook(issue *models.Issue, doer *models.User) {
@@ -34,7 +35,7 @@ func sendLabelUpdatedWebhook(issue *models.Issue, doer *models.User) {
log.Error("LoadIssue: %v", err)
return
}
- err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ err = webhook.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueLabelUpdated,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
@@ -42,7 +43,7 @@ func sendLabelUpdatedWebhook(issue *models.Issue, doer *models.User) {
Sender: doer.APIFormat(),
})
} else {
- err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
+ err = webhook.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
Action: api.HookIssueLabelUpdated,
Index: issue.Index,
Issue: issue.APIFormat(),
@@ -53,7 +54,7 @@ func sendLabelUpdatedWebhook(issue *models.Issue, doer *models.User) {
if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
- go models.HookQueue.Add(issue.RepoID)
+ go webhook.HookQueue.Add(issue.RepoID)
}
}
diff --git a/services/milestone/milestone.go b/services/milestone/milestone.go
index 68052e5a6c..d6d18ad985 100644
--- a/services/milestone/milestone.go
+++ b/services/milestone/milestone.go
@@ -8,6 +8,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/webhook"
)
// ChangeMilestoneAssign changes assignment of milestone for issue.
@@ -34,7 +35,7 @@ func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneI
log.Error("LoadIssue: %v", err)
return
}
- err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ err = webhook.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: hookAction,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
@@ -42,7 +43,7 @@ func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneI
Sender: doer.APIFormat(),
})
} else {
- err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
+ err = webhook.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
Action: hookAction,
Index: issue.Index,
Issue: issue.APIFormat(),
@@ -53,7 +54,7 @@ func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneI
if err != nil {
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
- go models.HookQueue.Add(issue.RepoID)
+ go webhook.HookQueue.Add(issue.RepoID)
}
return nil
}
diff --git a/services/mirror/sync.go b/services/mirror/sync.go
index 4bc153b47f..1bf36f5760 100644
--- a/services/mirror/sync.go
+++ b/services/mirror/sync.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/webhook"
)
func syncAction(opType models.ActionType, repo *models.Repository, refName string, data []byte) error {
@@ -28,7 +29,7 @@ func syncAction(opType models.ActionType, repo *models.Repository, refName strin
}
defer func() {
- go models.HookQueue.Add(repo.ID)
+ go webhook.HookQueue.Add(repo.ID)
}()
return nil
@@ -55,7 +56,7 @@ func SyncPushAction(repo *models.Repository, opts SyncPushActionOptions) error {
opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)
apiPusher := repo.MustOwner().APIFormat()
- if err := models.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{
+ if err := webhook.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{
Ref: opts.RefName,
Before: opts.OldCommitID,
After: opts.NewCommitID,
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 2e093eef86..f13638c292 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/webhook"
"github.com/mcuadros/go-version"
)
@@ -360,7 +361,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
}
mode, _ := models.AccessLevel(doer, pr.Issue.Repo)
- if err = models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ if err = webhook.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueClosed,
Index: pr.Index,
PullRequest: pr.APIFormat(),
@@ -369,7 +370,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
} else {
- go models.HookQueue.Add(pr.Issue.Repo.ID)
+ go webhook.HookQueue.Add(pr.Issue.Repo.ID)
}
return nil
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 8e6110ac36..65b78f4101 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/webhook"
issue_service "code.gitea.io/gitea/services/issue"
)
@@ -41,7 +42,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
pr.Issue = pull
pull.PullRequest = pr
mode, _ := models.AccessLevel(pull.Poster, repo)
- if err := models.PrepareWebhooks(repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ if err := webhook.PrepareWebhooks(repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueOpened,
Index: pull.Index,
PullRequest: pr.APIFormat(),
@@ -50,7 +51,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
} else {
- go models.HookQueue.Add(repo.ID)
+ go webhook.HookQueue.Add(repo.ID)
}
return nil
@@ -114,7 +115,7 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
log.Error("LoadAttributes: %v", err)
continue
}
- if err = models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ if err = webhook.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueSynchronized,
Index: pr.Issue.Index,
PullRequest: pr.Issue.PullRequest.APIFormat(),
@@ -124,7 +125,7 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
continue
}
- go models.HookQueue.Add(pr.Issue.Repo.ID)
+ go webhook.HookQueue.Add(pr.Issue.Repo.ID)
}
}
diff --git a/services/pull/review.go b/services/pull/review.go
index 3388e4bb56..cffe5da4dd 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -8,6 +8,7 @@ package pull
import (
"code.gitea.io/gitea/models"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/webhook"
)
// CreateReview creates a new review based on opts
@@ -55,7 +56,7 @@ func reviewHook(review *models.Review) error {
if err != nil {
return err
}
- if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
+ if err := webhook.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
Action: api.HookIssueSynchronized,
Index: review.Issue.Index,
PullRequest: pr.APIFormat(),
@@ -68,7 +69,7 @@ func reviewHook(review *models.Review) error {
}); err != nil {
return err
}
- go models.HookQueue.Add(review.Issue.Repo.ID)
+ go webhook.HookQueue.Add(review.Issue.Repo.ID)
return nil
}
diff --git a/services/release/release.go b/services/release/release.go
index b4f814a77f..42db1f3417 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/process"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/webhook"
)
func createTag(gitRepo *git.Repository, rel *models.Release) error {
@@ -84,7 +85,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
log.Error("LoadAttributes: %v", err)
} else {
mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
- if err := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
+ if err := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
Action: api.HookReleasePublished,
Release: rel.APIFormat(),
Repository: rel.Repo.APIFormat(mode),
@@ -92,7 +93,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
} else {
- go models.HookQueue.Add(rel.Repo.ID)
+ go webhook.HookQueue.Add(rel.Repo.ID)
}
}
}
@@ -121,7 +122,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
// even if attachments added failed, hooks will be still triggered
mode, _ := models.AccessLevel(doer, rel.Repo)
- if err1 := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
+ if err1 := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
Action: api.HookReleaseUpdated,
Release: rel.APIFormat(),
Repository: rel.Repo.APIFormat(mode),
@@ -129,7 +130,7 @@ func UpdateRelease(doer *models.User, gitRepo *git.Repository, rel *models.Relea
}); err1 != nil {
log.Error("PrepareWebhooks: %v", err)
} else {
- go models.HookQueue.Add(rel.Repo.ID)
+ go webhook.HookQueue.Add(rel.Repo.ID)
}
return err
@@ -187,7 +188,7 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
}
mode, _ := models.AccessLevel(doer, rel.Repo)
- if err := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
+ if err := webhook.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
Action: api.HookReleaseDeleted,
Release: rel.APIFormat(),
Repository: rel.Repo.APIFormat(mode),
@@ -195,7 +196,7 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
} else {
- go models.HookQueue.Add(rel.Repo.ID)
+ go webhook.HookQueue.Add(rel.Repo.ID)
}
return nil