summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-09-27 08:22:36 +0800
committerGitHub <noreply@github.com>2019-09-27 08:22:36 +0800
commiteb11ca68470e4ab60ed4ec31f4d170a4b36a528e (patch)
tree48347da8ba6c78d6ca30ac6ae5949fa93bb4c459
parentd958b9db4fa0f1910b3ca82338e3d68a70efedd9 (diff)
downloadgitea-eb11ca68470e4ab60ed4ec31f4d170a4b36a528e.tar.gz
gitea-eb11ca68470e4ab60ed4ec31f4d170a4b36a528e.zip
Extract actions on new pull request from models to pulls service and move code.gitea.io/gitea/modules/pull to code.gitea.io/gitea/services/pull (#8218)
* extract actions on new pull request from models to pulls service * improve code * move code.gitea.io/gitea/modules/pull to code.gitea.io/gitea/services/pull * fix fmt * Rename pulls.go to pull.go
-rw-r--r--models/pull.go27
-rw-r--r--routers/api/v1/repo/pull.go7
-rw-r--r--routers/repo/pull.go7
-rw-r--r--routers/repo/pull_review.go2
-rw-r--r--services/pull/commit_status.go (renamed from modules/pull/commit_status.go)0
-rw-r--r--services/pull/lfs.go (renamed from modules/pull/lfs.go)0
-rw-r--r--services/pull/merge.go (renamed from modules/pull/merge.go)0
-rw-r--r--services/pull/pull.go49
-rw-r--r--services/pull/review.go (renamed from modules/pull/review.go)0
9 files changed, 56 insertions, 36 deletions
diff --git a/models/pull.go b/models/pull.go
index 2f7218f415..60ccb144f5 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -700,33 +700,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
return fmt.Errorf("Commit: %v", err)
}
- if err = NotifyWatchers(&Action{
- ActUserID: pull.Poster.ID,
- ActUser: pull.Poster,
- OpType: ActionCreatePullRequest,
- Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
- RepoID: repo.ID,
- Repo: repo,
- IsPrivate: repo.IsPrivate,
- }); err != nil {
- log.Error("NotifyWatchers: %v", err)
- }
-
- pr.Issue = pull
- pull.PullRequest = pr
- mode, _ := AccessLevel(pull.Poster, repo)
- if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
- Action: api.HookIssueOpened,
- Index: pull.Index,
- PullRequest: pr.APIFormat(),
- Repository: repo.APIFormat(mode),
- Sender: pull.Poster.APIFormat(),
- }); err != nil {
- log.Error("PrepareWebhooks: %v", err)
- } else {
- go HookQueue.Add(repo.ID)
- }
-
return nil
}
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 0f9eab2f50..978c8a3f1f 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -15,11 +15,10 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
- "code.gitea.io/gitea/modules/pull"
- pull_service "code.gitea.io/gitea/modules/pull"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
milestone_service "code.gitea.io/gitea/services/milestone"
+ pull_service "code.gitea.io/gitea/services/pull"
)
// ListPullRequests returns a list of all PRs
@@ -288,7 +287,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
return
}
- if err := models.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch, assigneeIDs); err != nil {
+ if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch, assigneeIDs); err != nil {
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err)
return
@@ -602,7 +601,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
message += "\n\n" + form.MergeMessageField
}
- if err := pull.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
+ if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
if models.IsErrInvalidMergeStyle(err) {
ctx.Status(405)
return
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 180d592e3d..72d2ffcaa7 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -21,11 +21,10 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
- "code.gitea.io/gitea/modules/pull"
- pull_service "code.gitea.io/gitea/modules/pull"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
+ pull_service "code.gitea.io/gitea/services/pull"
"github.com/unknwon/com"
)
@@ -676,7 +675,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}
- if err = pull.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
+ if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
if models.IsErrInvalidMergeStyle(err) {
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
@@ -789,7 +788,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
// instead of 500.
- if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
+ if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
return
diff --git a/routers/repo/pull_review.go b/routers/repo/pull_review.go
index d4e3a3326a..5eb0dfe9a7 100644
--- a/routers/repo/pull_review.go
+++ b/routers/repo/pull_review.go
@@ -12,8 +12,8 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
- pull_service "code.gitea.io/gitea/modules/pull"
comment_service "code.gitea.io/gitea/services/comments"
+ pull_service "code.gitea.io/gitea/services/pull"
)
// CreateCodeComment will create a code comment including an pending review if required
diff --git a/modules/pull/commit_status.go b/services/pull/commit_status.go
index bdadc329d6..bdadc329d6 100644
--- a/modules/pull/commit_status.go
+++ b/services/pull/commit_status.go
diff --git a/modules/pull/lfs.go b/services/pull/lfs.go
index 2706d3a200..2706d3a200 100644
--- a/modules/pull/lfs.go
+++ b/services/pull/lfs.go
diff --git a/modules/pull/merge.go b/services/pull/merge.go
index 6150c1518e..6150c1518e 100644
--- a/modules/pull/merge.go
+++ b/services/pull/merge.go
diff --git a/services/pull/pull.go b/services/pull/pull.go
new file mode 100644
index 0000000000..0dbd8fcd1a
--- /dev/null
+++ b/services/pull/pull.go
@@ -0,0 +1,49 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package pull
+
+import (
+ "fmt"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/log"
+ api "code.gitea.io/gitea/modules/structs"
+)
+
+// NewPullRequest creates new pull request with labels for repository.
+func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, patch []byte, assigneeIDs []int64) error {
+ if err := models.NewPullRequest(repo, pull, labelIDs, uuids, pr, patch, assigneeIDs); err != nil {
+ return err
+ }
+
+ if err := models.NotifyWatchers(&models.Action{
+ ActUserID: pull.Poster.ID,
+ ActUser: pull.Poster,
+ OpType: models.ActionCreatePullRequest,
+ Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
+ RepoID: repo.ID,
+ Repo: repo,
+ IsPrivate: repo.IsPrivate,
+ }); err != nil {
+ log.Error("NotifyWatchers: %v", err)
+ }
+
+ pr.Issue = pull
+ pull.PullRequest = pr
+ mode, _ := models.AccessLevel(pull.Poster, repo)
+ if err := models.PrepareWebhooks(repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueOpened,
+ Index: pull.Index,
+ PullRequest: pr.APIFormat(),
+ Repository: repo.APIFormat(mode),
+ Sender: pull.Poster.APIFormat(),
+ }); err != nil {
+ log.Error("PrepareWebhooks: %v", err)
+ } else {
+ go models.HookQueue.Add(repo.ID)
+ }
+
+ return nil
+}
diff --git a/modules/pull/review.go b/services/pull/review.go
index 3fdfaaff84..3fdfaaff84 100644
--- a/modules/pull/review.go
+++ b/services/pull/review.go