@@ -21,17 +21,21 @@ import (
21
21
"github.com/go-xorm/xorm"
22
22
)
23
23
24
- var PullRequestQueue = sync .NewUniqueQueue (setting .Repository .PullRequestQueueLength )
24
+ var pullRequestQueue = sync .NewUniqueQueue (setting .Repository .PullRequestQueueLength )
25
25
26
+ // PullRequestType defines pull request type
26
27
type PullRequestType int
27
28
29
+ // Enumerate all the pull request types
28
30
const (
29
31
PullRequestGitea PullRequestType = iota
30
32
PullRequestGit
31
33
)
32
34
35
+ // PullRequestStatus defines pull request status
33
36
type PullRequestStatus int
34
37
38
+ // Enumerate all the pull request status
35
39
const (
36
40
PullRequestStatusConflict PullRequestStatus = iota
37
41
PullRequestStatusChecking
@@ -65,10 +69,12 @@ type PullRequest struct {
65
69
MergedUnix int64
66
70
}
67
71
72
+ // BeforeUpdate is invoked from XORM before updating an object of this type.
68
73
func (pr * PullRequest ) BeforeUpdate () {
69
74
pr .MergedUnix = pr .Merged .Unix ()
70
75
}
71
76
77
+ // AfterSet is invoked from XORM after setting the value of a field of this object.
72
78
// Note: don't try to get Issue because will end up recursive querying.
73
79
func (pr * PullRequest ) AfterSet (colName string , _ xorm.Cell ) {
74
80
switch colName {
@@ -96,10 +102,12 @@ func (pr *PullRequest) loadAttributes(e Engine) (err error) {
96
102
return nil
97
103
}
98
104
105
+ // LoadAttributes loads pull request attributes from database
99
106
func (pr * PullRequest ) LoadAttributes () error {
100
107
return pr .loadAttributes (x )
101
108
}
102
109
110
+ // LoadIssue loads issue information from database
103
111
func (pr * PullRequest ) LoadIssue () (err error ) {
104
112
if pr .Issue != nil {
105
113
return nil
@@ -109,7 +117,7 @@ func (pr *PullRequest) LoadIssue() (err error) {
109
117
return err
110
118
}
111
119
112
- // This method assumes following fields have been assigned with valid values:
120
+ // APIFormat assumes following fields have been assigned with valid values:
113
121
// Required - Issue
114
122
// Optional - Merger
115
123
func (pr * PullRequest ) APIFormat () * api.PullRequest {
@@ -150,10 +158,12 @@ func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
150
158
return nil
151
159
}
152
160
161
+ // GetHeadRepo loads the head repository
153
162
func (pr * PullRequest ) GetHeadRepo () error {
154
163
return pr .getHeadRepo (x )
155
164
}
156
165
166
+ // GetBaseRepo loads the target repository
157
167
func (pr * PullRequest ) GetBaseRepo () (err error ) {
158
168
if pr .BaseRepo != nil {
159
169
return nil
@@ -538,7 +548,7 @@ func (pr *PullRequest) Update() error {
538
548
return err
539
549
}
540
550
541
- // Update updates specific fields of pull request.
551
+ // UpdateCols updates specific fields of pull request.
542
552
func (pr * PullRequest ) UpdateCols (cols ... string ) error {
543
553
_ , err := x .Id (pr .ID ).Cols (cols ... ).Update (pr )
544
554
return err
@@ -623,14 +633,15 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
623
633
624
634
// AddToTaskQueue adds itself to pull request test task queue.
625
635
func (pr * PullRequest ) AddToTaskQueue () {
626
- go PullRequestQueue .AddFunc (pr .ID , func () {
636
+ go pullRequestQueue .AddFunc (pr .ID , func () {
627
637
pr .Status = PullRequestStatusChecking
628
638
if err := pr .UpdateCols ("status" ); err != nil {
629
639
log .Error (5 , "AddToTaskQueue.UpdateCols[%d].(add to queue): %v" , pr .ID , err )
630
640
}
631
641
})
632
642
}
633
643
644
+ // PullRequestList defines a list of pull requests
634
645
type PullRequestList []* PullRequest
635
646
636
647
func (prs PullRequestList ) loadAttributes (e Engine ) error {
@@ -661,6 +672,7 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
661
672
return nil
662
673
}
663
674
675
+ // LoadAttributes load all the prs attributes
664
676
func (prs PullRequestList ) LoadAttributes () error {
665
677
return prs .loadAttributes (x )
666
678
}
@@ -730,6 +742,7 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool
730
742
}
731
743
}
732
744
745
+ // ChangeUsernameInPullRequests changes the name of head_user_name
733
746
func ChangeUsernameInPullRequests (oldUserName , newUserName string ) error {
734
747
pr := PullRequest {
735
748
HeadUserName : strings .ToLower (newUserName ),
@@ -750,7 +763,7 @@ func (pr *PullRequest) checkAndUpdateStatus() {
750
763
}
751
764
752
765
// Make sure there is no waiting test to process before levaing the checking status.
753
- if ! PullRequestQueue .Exist (pr .ID ) {
766
+ if ! pullRequestQueue .Exist (pr .ID ) {
754
767
if err := pr .UpdateCols ("status" ); err != nil {
755
768
log .Error (4 , "Update[%d]: %v" , pr .ID , err )
756
769
}
@@ -786,9 +799,9 @@ func TestPullRequests() {
786
799
}
787
800
788
801
// Start listening on new test requests.
789
- for prID := range PullRequestQueue .Queue () {
802
+ for prID := range pullRequestQueue .Queue () {
790
803
log .Trace ("TestPullRequests[%v]: processing test task" , prID )
791
- PullRequestQueue .Remove (prID )
804
+ pullRequestQueue .Remove (prID )
792
805
793
806
pr , err := GetPullRequestByID (com .StrTo (prID ).MustInt64 ())
794
807
if err != nil {
@@ -803,6 +816,7 @@ func TestPullRequests() {
803
816
}
804
817
}
805
818
819
+ // InitTestPullRequests runs the task to test all the checking status pull requests
806
820
func InitTestPullRequests () {
807
821
go TestPullRequests ()
808
822
}
0 commit comments