summaryrefslogtreecommitdiffstats
path: root/models/pull_list.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-12-07 10:44:10 +0800
committertechknowlogick <techknowlogick@gitea.io>2019-12-06 21:44:10 -0500
commit82e0383d2104f454af5b3e0e768f0497113f3b13 (patch)
tree0bb945b408668867e24db2429cc7099d57eaa6f6 /models/pull_list.go
parent1583c48e3a89fcb9aeb81a57295982ee64d5859f (diff)
downloadgitea-82e0383d2104f454af5b3e0e768f0497113f3b13.tar.gz
gitea-82e0383d2104f454af5b3e0e768f0497113f3b13.zip
Move some pull request functions from models to services (#9266)
* Move some pull request functions from models to services * Fix test
Diffstat (limited to 'models/pull_list.go')
-rw-r--r--models/pull_list.go71
1 files changed, 9 insertions, 62 deletions
diff --git a/models/pull_list.go b/models/pull_list.go
index 2c2f53f4a1..49d04ba0b8 100644
--- a/models/pull_list.go
+++ b/models/pull_list.go
@@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
- "github.com/unknwon/com"
+
"xorm.io/xorm"
)
@@ -68,6 +68,14 @@ func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequ
Find(&prs)
}
+// GetPullRequestsByCheckStatus returns all pull requests according the special checking status.
+func GetPullRequestsByCheckStatus(status PullRequestStatus) ([]*PullRequest, error) {
+ prs := make([]*PullRequest, 0, 10)
+ return prs, x.
+ Where("status=?", status).
+ Find(&prs)
+}
+
// PullRequests returns all pull requests for a base Repo by the given conditions
func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, int64, error) {
if opts.Page <= 0 {
@@ -161,64 +169,3 @@ func (prs PullRequestList) invalidateCodeComments(e Engine, doer *User, repo *gi
func (prs PullRequestList) InvalidateCodeComments(doer *User, repo *git.Repository, branch string) error {
return prs.invalidateCodeComments(x, doer, repo, branch)
}
-
-// TestPullRequests checks and tests untested patches of pull requests.
-// TODO: test more pull requests at same time.
-func TestPullRequests() {
- prs := make([]*PullRequest, 0, 10)
-
- err := x.Where("status = ?", PullRequestStatusChecking).Find(&prs)
- if err != nil {
- log.Error("Find Checking PRs: %v", err)
- return
- }
-
- var checkedPRs = make(map[int64]struct{})
-
- // Update pull request status.
- for _, pr := range prs {
- checkedPRs[pr.ID] = struct{}{}
- if err := pr.GetBaseRepo(); err != nil {
- log.Error("GetBaseRepo: %v", err)
- continue
- }
- if pr.manuallyMerged() {
- continue
- }
- if err := pr.testPatch(x); err != nil {
- log.Error("testPatch: %v", err)
- continue
- }
-
- pr.checkAndUpdateStatus()
- }
-
- // Start listening on new test requests.
- for prID := range pullRequestQueue.Queue() {
- log.Trace("TestPullRequests[%v]: processing test task", prID)
- pullRequestQueue.Remove(prID)
-
- id := com.StrTo(prID).MustInt64()
- if _, ok := checkedPRs[id]; ok {
- continue
- }
-
- pr, err := GetPullRequestByID(id)
- if err != nil {
- log.Error("GetPullRequestByID[%s]: %v", prID, err)
- continue
- } else if pr.manuallyMerged() {
- continue
- } else if err = pr.testPatch(x); err != nil {
- log.Error("testPatch[%d]: %v", pr.ID, err)
- continue
- }
-
- pr.checkAndUpdateStatus()
- }
-}
-
-// InitTestPullRequests runs the task to test all the checking status pull requests
-func InitTestPullRequests() {
- go TestPullRequests()
-}