@@ -16,7 +16,6 @@ import (
16
16
"strings"
17
17
"time"
18
18
19
- "code.gitea.io/gitea/modules/base"
20
19
"code.gitea.io/gitea/modules/git"
21
20
"code.gitea.io/gitea/modules/log"
22
21
"code.gitea.io/gitea/modules/process"
@@ -26,7 +25,6 @@ import (
26
25
"code.gitea.io/gitea/modules/timeutil"
27
26
28
27
"github.com/unknwon/com"
29
- "xorm.io/xorm"
30
28
)
31
29
32
30
var pullRequestQueue = sync .NewUniqueQueue (setting .Repository .PullRequestQueueLength )
@@ -753,66 +751,6 @@ func newPullRequestAttempt(repo *Repository, pull *Issue, labelIDs []int64, uuid
753
751
return nil
754
752
}
755
753
756
- // PullRequestsOptions holds the options for PRs
757
- type PullRequestsOptions struct {
758
- Page int
759
- State string
760
- SortType string
761
- Labels []string
762
- MilestoneID int64
763
- }
764
-
765
- func listPullRequestStatement (baseRepoID int64 , opts * PullRequestsOptions ) (* xorm.Session , error ) {
766
- sess := x .Where ("pull_request.base_repo_id=?" , baseRepoID )
767
-
768
- sess .Join ("INNER" , "issue" , "pull_request.issue_id = issue.id" )
769
- switch opts .State {
770
- case "closed" , "open" :
771
- sess .And ("issue.is_closed=?" , opts .State == "closed" )
772
- }
773
-
774
- if labelIDs , err := base .StringsToInt64s (opts .Labels ); err != nil {
775
- return nil , err
776
- } else if len (labelIDs ) > 0 {
777
- sess .Join ("INNER" , "issue_label" , "issue.id = issue_label.issue_id" ).
778
- In ("issue_label.label_id" , labelIDs )
779
- }
780
-
781
- if opts .MilestoneID > 0 {
782
- sess .And ("issue.milestone_id=?" , opts .MilestoneID )
783
- }
784
-
785
- return sess , nil
786
- }
787
-
788
- // PullRequests returns all pull requests for a base Repo by the given conditions
789
- func PullRequests (baseRepoID int64 , opts * PullRequestsOptions ) ([]* PullRequest , int64 , error ) {
790
- if opts .Page <= 0 {
791
- opts .Page = 1
792
- }
793
-
794
- countSession , err := listPullRequestStatement (baseRepoID , opts )
795
- if err != nil {
796
- log .Error ("listPullRequestStatement: %v" , err )
797
- return nil , 0 , err
798
- }
799
- maxResults , err := countSession .Count (new (PullRequest ))
800
- if err != nil {
801
- log .Error ("Count PRs: %v" , err )
802
- return nil , maxResults , err
803
- }
804
-
805
- prs := make ([]* PullRequest , 0 , ItemsPerPage )
806
- findSession , err := listPullRequestStatement (baseRepoID , opts )
807
- sortIssuesSession (findSession , opts .SortType )
808
- if err != nil {
809
- log .Error ("listPullRequestStatement: %v" , err )
810
- return nil , maxResults , err
811
- }
812
- findSession .Limit (ItemsPerPage , (opts .Page - 1 )* ItemsPerPage )
813
- return prs , maxResults , findSession .Find (& prs )
814
- }
815
-
816
754
// GetUnmergedPullRequest returns a pull request that is open and has not been merged
817
755
// by given head/base and repo/branch.
818
756
func GetUnmergedPullRequest (headRepoID , baseRepoID int64 , headBranch , baseBranch string ) (* PullRequest , error ) {
@@ -831,17 +769,6 @@ func GetUnmergedPullRequest(headRepoID, baseRepoID int64, headBranch, baseBranch
831
769
return pr , nil
832
770
}
833
771
834
- // GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
835
- // by given head information (repo and branch).
836
- func GetUnmergedPullRequestsByHeadInfo (repoID int64 , branch string ) ([]* PullRequest , error ) {
837
- prs := make ([]* PullRequest , 0 , 2 )
838
- return prs , x .
839
- Where ("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ?" ,
840
- repoID , branch , false , false ).
841
- Join ("INNER" , "issue" , "issue.id = pull_request.issue_id" ).
842
- Find (& prs )
843
- }
844
-
845
772
// GetLatestPullRequestByHeadInfo returns the latest pull request (regardless of its status)
846
773
// by given head information (repo and branch).
847
774
func GetLatestPullRequestByHeadInfo (repoID int64 , branch string ) (* PullRequest , error ) {
@@ -856,17 +783,6 @@ func GetLatestPullRequestByHeadInfo(repoID int64, branch string) (*PullRequest,
856
783
return pr , err
857
784
}
858
785
859
- // GetUnmergedPullRequestsByBaseInfo returns all pull requests that are open and has not been merged
860
- // by given base information (repo and branch).
861
- func GetUnmergedPullRequestsByBaseInfo (repoID int64 , branch string ) ([]* PullRequest , error ) {
862
- prs := make ([]* PullRequest , 0 , 2 )
863
- return prs , x .
864
- Where ("base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?" ,
865
- repoID , branch , false , false ).
866
- Join ("INNER" , "issue" , "issue.id=pull_request.issue_id" ).
867
- Find (& prs )
868
- }
869
-
870
786
// GetPullRequestByIndex returns a pull request by the given index
871
787
func GetPullRequestByIndex (repoID int64 , index int64 ) (* PullRequest , error ) {
872
788
pr := & PullRequest {
@@ -1035,72 +951,6 @@ func (pr *PullRequest) AddToTaskQueue() {
1035
951
})
1036
952
}
1037
953
1038
- // PullRequestList defines a list of pull requests
1039
- type PullRequestList []* PullRequest
1040
-
1041
- func (prs PullRequestList ) loadAttributes (e Engine ) error {
1042
- if len (prs ) == 0 {
1043
- return nil
1044
- }
1045
-
1046
- // Load issues.
1047
- issueIDs := prs .getIssueIDs ()
1048
- issues := make ([]* Issue , 0 , len (issueIDs ))
1049
- if err := e .
1050
- Where ("id > 0" ).
1051
- In ("id" , issueIDs ).
1052
- Find (& issues ); err != nil {
1053
- return fmt .Errorf ("find issues: %v" , err )
1054
- }
1055
-
1056
- set := make (map [int64 ]* Issue )
1057
- for i := range issues {
1058
- set [issues [i ].ID ] = issues [i ]
1059
- }
1060
- for i := range prs {
1061
- prs [i ].Issue = set [prs [i ].IssueID ]
1062
- }
1063
- return nil
1064
- }
1065
-
1066
- func (prs PullRequestList ) getIssueIDs () []int64 {
1067
- issueIDs := make ([]int64 , 0 , len (prs ))
1068
- for i := range prs {
1069
- issueIDs = append (issueIDs , prs [i ].IssueID )
1070
- }
1071
- return issueIDs
1072
- }
1073
-
1074
- // LoadAttributes load all the prs attributes
1075
- func (prs PullRequestList ) LoadAttributes () error {
1076
- return prs .loadAttributes (x )
1077
- }
1078
-
1079
- func (prs PullRequestList ) invalidateCodeComments (e Engine , doer * User , repo * git.Repository , branch string ) error {
1080
- if len (prs ) == 0 {
1081
- return nil
1082
- }
1083
- issueIDs := prs .getIssueIDs ()
1084
- var codeComments []* Comment
1085
- if err := e .
1086
- Where ("type = ? and invalidated = ?" , CommentTypeCode , false ).
1087
- In ("issue_id" , issueIDs ).
1088
- Find (& codeComments ); err != nil {
1089
- return fmt .Errorf ("find code comments: %v" , err )
1090
- }
1091
- for _ , comment := range codeComments {
1092
- if err := comment .CheckInvalidation (repo , doer , branch ); err != nil {
1093
- return err
1094
- }
1095
- }
1096
- return nil
1097
- }
1098
-
1099
- // InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
1100
- func (prs PullRequestList ) InvalidateCodeComments (doer * User , repo * git.Repository , branch string ) error {
1101
- return prs .invalidateCodeComments (x , doer , repo , branch )
1102
- }
1103
-
1104
954
// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
1105
955
// and set to be either conflict or mergeable.
1106
956
func (pr * PullRequest ) checkAndUpdateStatus () {
@@ -1152,64 +1002,3 @@ func (pr *PullRequest) GetWorkInProgressPrefix() string {
1152
1002
}
1153
1003
return ""
1154
1004
}
1155
-
1156
- // TestPullRequests checks and tests untested patches of pull requests.
1157
- // TODO: test more pull requests at same time.
1158
- func TestPullRequests () {
1159
- prs := make ([]* PullRequest , 0 , 10 )
1160
-
1161
- err := x .Where ("status = ?" , PullRequestStatusChecking ).Find (& prs )
1162
- if err != nil {
1163
- log .Error ("Find Checking PRs: %v" , err )
1164
- return
1165
- }
1166
-
1167
- var checkedPRs = make (map [int64 ]struct {})
1168
-
1169
- // Update pull request status.
1170
- for _ , pr := range prs {
1171
- checkedPRs [pr .ID ] = struct {}{}
1172
- if err := pr .GetBaseRepo (); err != nil {
1173
- log .Error ("GetBaseRepo: %v" , err )
1174
- continue
1175
- }
1176
- if pr .manuallyMerged () {
1177
- continue
1178
- }
1179
- if err := pr .testPatch (x ); err != nil {
1180
- log .Error ("testPatch: %v" , err )
1181
- continue
1182
- }
1183
-
1184
- pr .checkAndUpdateStatus ()
1185
- }
1186
-
1187
- // Start listening on new test requests.
1188
- for prID := range pullRequestQueue .Queue () {
1189
- log .Trace ("TestPullRequests[%v]: processing test task" , prID )
1190
- pullRequestQueue .Remove (prID )
1191
-
1192
- id := com .StrTo (prID ).MustInt64 ()
1193
- if _ , ok := checkedPRs [id ]; ok {
1194
- continue
1195
- }
1196
-
1197
- pr , err := GetPullRequestByID (id )
1198
- if err != nil {
1199
- log .Error ("GetPullRequestByID[%s]: %v" , prID , err )
1200
- continue
1201
- } else if pr .manuallyMerged () {
1202
- continue
1203
- } else if err = pr .testPatch (x ); err != nil {
1204
- log .Error ("testPatch[%d]: %v" , pr .ID , err )
1205
- continue
1206
- }
1207
-
1208
- pr .checkAndUpdateStatus ()
1209
- }
1210
- }
1211
-
1212
- // InitTestPullRequests runs the task to test all the checking status pull requests
1213
- func InitTestPullRequests () {
1214
- go TestPullRequests ()
1215
- }
0 commit comments