Skip to content

Commit 1d0f811

Browse files
authored
golint fixed for models/pull.go (#292)
1 parent fd3f166 commit 1d0f811

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

models/pull.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ import (
2121
"github.com/go-xorm/xorm"
2222
)
2323

24-
var PullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)
24+
var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)
2525

26+
// PullRequestType defines pull request type
2627
type PullRequestType int
2728

29+
// Enumerate all the pull request types
2830
const (
2931
PullRequestGitea PullRequestType = iota
3032
PullRequestGit
3133
)
3234

35+
// PullRequestStatus defines pull request status
3336
type PullRequestStatus int
3437

38+
// Enumerate all the pull request status
3539
const (
3640
PullRequestStatusConflict PullRequestStatus = iota
3741
PullRequestStatusChecking
@@ -65,10 +69,12 @@ type PullRequest struct {
6569
MergedUnix int64
6670
}
6771

72+
// BeforeUpdate is invoked from XORM before updating an object of this type.
6873
func (pr *PullRequest) BeforeUpdate() {
6974
pr.MergedUnix = pr.Merged.Unix()
7075
}
7176

77+
// AfterSet is invoked from XORM after setting the value of a field of this object.
7278
// Note: don't try to get Issue because will end up recursive querying.
7379
func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
7480
switch colName {
@@ -96,10 +102,12 @@ func (pr *PullRequest) loadAttributes(e Engine) (err error) {
96102
return nil
97103
}
98104

105+
// LoadAttributes loads pull request attributes from database
99106
func (pr *PullRequest) LoadAttributes() error {
100107
return pr.loadAttributes(x)
101108
}
102109

110+
// LoadIssue loads issue information from database
103111
func (pr *PullRequest) LoadIssue() (err error) {
104112
if pr.Issue != nil {
105113
return nil
@@ -109,7 +117,7 @@ func (pr *PullRequest) LoadIssue() (err error) {
109117
return err
110118
}
111119

112-
// This method assumes following fields have been assigned with valid values:
120+
// APIFormat assumes following fields have been assigned with valid values:
113121
// Required - Issue
114122
// Optional - Merger
115123
func (pr *PullRequest) APIFormat() *api.PullRequest {
@@ -150,10 +158,12 @@ func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
150158
return nil
151159
}
152160

161+
// GetHeadRepo loads the head repository
153162
func (pr *PullRequest) GetHeadRepo() error {
154163
return pr.getHeadRepo(x)
155164
}
156165

166+
// GetBaseRepo loads the target repository
157167
func (pr *PullRequest) GetBaseRepo() (err error) {
158168
if pr.BaseRepo != nil {
159169
return nil
@@ -538,7 +548,7 @@ func (pr *PullRequest) Update() error {
538548
return err
539549
}
540550

541-
// Update updates specific fields of pull request.
551+
// UpdateCols updates specific fields of pull request.
542552
func (pr *PullRequest) UpdateCols(cols ...string) error {
543553
_, err := x.Id(pr.ID).Cols(cols...).Update(pr)
544554
return err
@@ -623,14 +633,15 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
623633

624634
// AddToTaskQueue adds itself to pull request test task queue.
625635
func (pr *PullRequest) AddToTaskQueue() {
626-
go PullRequestQueue.AddFunc(pr.ID, func() {
636+
go pullRequestQueue.AddFunc(pr.ID, func() {
627637
pr.Status = PullRequestStatusChecking
628638
if err := pr.UpdateCols("status"); err != nil {
629639
log.Error(5, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
630640
}
631641
})
632642
}
633643

644+
// PullRequestList defines a list of pull requests
634645
type PullRequestList []*PullRequest
635646

636647
func (prs PullRequestList) loadAttributes(e Engine) error {
@@ -661,6 +672,7 @@ func (prs PullRequestList) loadAttributes(e Engine) error {
661672
return nil
662673
}
663674

675+
// LoadAttributes load all the prs attributes
664676
func (prs PullRequestList) LoadAttributes() error {
665677
return prs.loadAttributes(x)
666678
}
@@ -730,6 +742,7 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool
730742
}
731743
}
732744

745+
// ChangeUsernameInPullRequests changes the name of head_user_name
733746
func ChangeUsernameInPullRequests(oldUserName, newUserName string) error {
734747
pr := PullRequest{
735748
HeadUserName: strings.ToLower(newUserName),
@@ -750,7 +763,7 @@ func (pr *PullRequest) checkAndUpdateStatus() {
750763
}
751764

752765
// 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) {
754767
if err := pr.UpdateCols("status"); err != nil {
755768
log.Error(4, "Update[%d]: %v", pr.ID, err)
756769
}
@@ -786,9 +799,9 @@ func TestPullRequests() {
786799
}
787800

788801
// Start listening on new test requests.
789-
for prID := range PullRequestQueue.Queue() {
802+
for prID := range pullRequestQueue.Queue() {
790803
log.Trace("TestPullRequests[%v]: processing test task", prID)
791-
PullRequestQueue.Remove(prID)
804+
pullRequestQueue.Remove(prID)
792805

793806
pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64())
794807
if err != nil {
@@ -803,6 +816,7 @@ func TestPullRequests() {
803816
}
804817
}
805818

819+
// InitTestPullRequests runs the task to test all the checking status pull requests
806820
func InitTestPullRequests() {
807821
go TestPullRequests()
808822
}

0 commit comments

Comments
 (0)