|
|
@ -26,16 +26,16 @@ var PullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLe |
|
|
|
type PullRequestType int |
|
|
|
type PullRequestType int |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
PULL_REQUEST_GITEA PullRequestType = iota |
|
|
|
PullRequestGitea PullRequestType = iota |
|
|
|
PULL_REQUEST_GIT |
|
|
|
PullRequestGit |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type PullRequestStatus int |
|
|
|
type PullRequestStatus int |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
PULL_REQUEST_STATUS_CONFLICT PullRequestStatus = iota |
|
|
|
PullRequestStatusConflict PullRequestStatus = iota |
|
|
|
PULL_REQUEST_STATUS_CHECKING |
|
|
|
PullRequestStatusChecking |
|
|
|
PULL_REQUEST_STATUS_MERGEABLE |
|
|
|
PullRequestStatusMergeable |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// PullRequest represents relation between pull request and repositories.
|
|
|
|
// PullRequest represents relation between pull request and repositories.
|
|
|
@ -129,8 +129,8 @@ func (pr *PullRequest) APIFormat() *api.PullRequest { |
|
|
|
HasMerged: pr.HasMerged, |
|
|
|
HasMerged: pr.HasMerged, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if pr.Status != PULL_REQUEST_STATUS_CHECKING { |
|
|
|
if pr.Status != PullRequestStatusChecking { |
|
|
|
mergeable := pr.Status != PULL_REQUEST_STATUS_CONFLICT |
|
|
|
mergeable := pr.Status != PullRequestStatusConflict |
|
|
|
apiPullRequest.Mergeable = &mergeable |
|
|
|
apiPullRequest.Mergeable = &mergeable |
|
|
|
} |
|
|
|
} |
|
|
|
if pr.HasMerged { |
|
|
|
if pr.HasMerged { |
|
|
@ -168,12 +168,12 @@ func (pr *PullRequest) GetBaseRepo() (err error) { |
|
|
|
|
|
|
|
|
|
|
|
// IsChecking returns true if this pull request is still checking conflict.
|
|
|
|
// IsChecking returns true if this pull request is still checking conflict.
|
|
|
|
func (pr *PullRequest) IsChecking() bool { |
|
|
|
func (pr *PullRequest) IsChecking() bool { |
|
|
|
return pr.Status == PULL_REQUEST_STATUS_CHECKING |
|
|
|
return pr.Status == PullRequestStatusChecking |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CanAutoMerge returns true if this pull request can be merged automatically.
|
|
|
|
// CanAutoMerge returns true if this pull request can be merged automatically.
|
|
|
|
func (pr *PullRequest) CanAutoMerge() bool { |
|
|
|
func (pr *PullRequest) CanAutoMerge() bool { |
|
|
|
return pr.Status == PULL_REQUEST_STATUS_MERGEABLE |
|
|
|
return pr.Status == PullRequestStatusMergeable |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Merge merges pull request to base repository.
|
|
|
|
// Merge merges pull request to base repository.
|
|
|
@ -285,8 +285,8 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error |
|
|
|
log.Error(4, "LoadAttributes: %v", err) |
|
|
|
log.Error(4, "LoadAttributes: %v", err) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ |
|
|
|
if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{ |
|
|
|
Action: api.HOOK_ISSUE_CLOSED, |
|
|
|
Action: api.HookIssueClosed, |
|
|
|
Index: pr.Index, |
|
|
|
Index: pr.Index, |
|
|
|
PullRequest: pr.APIFormat(), |
|
|
|
PullRequest: pr.APIFormat(), |
|
|
|
Repository: pr.Issue.Repo.APIFormat(nil), |
|
|
|
Repository: pr.Issue.Repo.APIFormat(nil), |
|
|
@ -323,7 +323,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error |
|
|
|
Pusher: pr.HeadRepo.MustOwner().APIFormat(), |
|
|
|
Pusher: pr.HeadRepo.MustOwner().APIFormat(), |
|
|
|
Sender: doer.APIFormat(), |
|
|
|
Sender: doer.APIFormat(), |
|
|
|
} |
|
|
|
} |
|
|
|
if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil { |
|
|
|
if err = PrepareWebhooks(pr.BaseRepo, HookEventPush, p); err != nil { |
|
|
|
return fmt.Errorf("PrepareWebhooks: %v", err) |
|
|
|
return fmt.Errorf("PrepareWebhooks: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|
return nil |
|
|
@ -367,7 +367,7 @@ func (pr *PullRequest) testPatch() (err error) { |
|
|
|
return fmt.Errorf("UpdateLocalCopy: %v", err) |
|
|
|
return fmt.Errorf("UpdateLocalCopy: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pr.Status = PULL_REQUEST_STATUS_CHECKING |
|
|
|
pr.Status = PullRequestStatusChecking |
|
|
|
_, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(), |
|
|
|
_, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(), |
|
|
|
fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID), |
|
|
|
fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID), |
|
|
|
"git", "apply", "--check", patchPath) |
|
|
|
"git", "apply", "--check", patchPath) |
|
|
@ -376,7 +376,7 @@ func (pr *PullRequest) testPatch() (err error) { |
|
|
|
if strings.Contains(stderr, patchConflicts[i]) { |
|
|
|
if strings.Contains(stderr, patchConflicts[i]) { |
|
|
|
log.Trace("PullRequest[%d].testPatch (apply): has conflit", pr.ID) |
|
|
|
log.Trace("PullRequest[%d].testPatch (apply): has conflit", pr.ID) |
|
|
|
fmt.Println(stderr) |
|
|
|
fmt.Println(stderr) |
|
|
|
pr.Status = PULL_REQUEST_STATUS_CONFLICT |
|
|
|
pr.Status = PullRequestStatusConflict |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -414,8 +414,8 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str |
|
|
|
return fmt.Errorf("testPatch: %v", err) |
|
|
|
return fmt.Errorf("testPatch: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
// No conflict appears after test means mergeable.
|
|
|
|
// No conflict appears after test means mergeable.
|
|
|
|
if pr.Status == PULL_REQUEST_STATUS_CHECKING { |
|
|
|
if pr.Status == PullRequestStatusChecking { |
|
|
|
pr.Status = PULL_REQUEST_STATUS_MERGEABLE |
|
|
|
pr.Status = PullRequestStatusMergeable |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pr.IssueID = pull.ID |
|
|
|
pr.IssueID = pull.ID |
|
|
@ -430,7 +430,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str |
|
|
|
if err = NotifyWatchers(&Action{ |
|
|
|
if err = NotifyWatchers(&Action{ |
|
|
|
ActUserID: pull.Poster.ID, |
|
|
|
ActUserID: pull.Poster.ID, |
|
|
|
ActUserName: pull.Poster.Name, |
|
|
|
ActUserName: pull.Poster.Name, |
|
|
|
OpType: ACTION_CREATE_PULL_REQUEST, |
|
|
|
OpType: ActionCreatePullRequest, |
|
|
|
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title), |
|
|
|
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title), |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
@ -444,8 +444,8 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str |
|
|
|
|
|
|
|
|
|
|
|
pr.Issue = pull |
|
|
|
pr.Issue = pull |
|
|
|
pull.PullRequest = pr |
|
|
|
pull.PullRequest = pr |
|
|
|
if err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ |
|
|
|
if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{ |
|
|
|
Action: api.HOOK_ISSUE_OPENED, |
|
|
|
Action: api.HookIssueOpened, |
|
|
|
Index: pull.Index, |
|
|
|
Index: pull.Index, |
|
|
|
PullRequest: pr.APIFormat(), |
|
|
|
PullRequest: pr.APIFormat(), |
|
|
|
Repository: repo.APIFormat(nil), |
|
|
|
Repository: repo.APIFormat(nil), |
|
|
@ -618,7 +618,7 @@ func (pr *PullRequest) PushToBaseRepo() (err error) { |
|
|
|
// AddToTaskQueue adds itself to pull request test task queue.
|
|
|
|
// AddToTaskQueue adds itself to pull request test task queue.
|
|
|
|
func (pr *PullRequest) AddToTaskQueue() { |
|
|
|
func (pr *PullRequest) AddToTaskQueue() { |
|
|
|
go PullRequestQueue.AddFunc(pr.ID, func() { |
|
|
|
go PullRequestQueue.AddFunc(pr.ID, func() { |
|
|
|
pr.Status = PULL_REQUEST_STATUS_CHECKING |
|
|
|
pr.Status = PullRequestStatusChecking |
|
|
|
if err := pr.UpdateCols("status"); err != nil { |
|
|
|
if err := pr.UpdateCols("status"); err != nil { |
|
|
|
log.Error(5, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err) |
|
|
|
log.Error(5, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -693,8 +693,8 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool |
|
|
|
log.Error(4, "LoadAttributes: %v", err) |
|
|
|
log.Error(4, "LoadAttributes: %v", err) |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{ |
|
|
|
if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{ |
|
|
|
Action: api.HOOK_ISSUE_SYNCHRONIZED, |
|
|
|
Action: api.HookIssueSynchronized, |
|
|
|
Index: pr.Issue.Index, |
|
|
|
Index: pr.Issue.Index, |
|
|
|
PullRequest: pr.Issue.PullRequest.APIFormat(), |
|
|
|
PullRequest: pr.Issue.PullRequest.APIFormat(), |
|
|
|
Repository: pr.Issue.Repo.APIFormat(nil), |
|
|
|
Repository: pr.Issue.Repo.APIFormat(nil), |
|
|
@ -733,8 +733,8 @@ func ChangeUsernameInPullRequests(oldUserName, newUserName string) error { |
|
|
|
// and set to be either conflict or mergeable.
|
|
|
|
// and set to be either conflict or mergeable.
|
|
|
|
func (pr *PullRequest) checkAndUpdateStatus() { |
|
|
|
func (pr *PullRequest) checkAndUpdateStatus() { |
|
|
|
// Status is not changed to conflict means mergeable.
|
|
|
|
// Status is not changed to conflict means mergeable.
|
|
|
|
if pr.Status == PULL_REQUEST_STATUS_CHECKING { |
|
|
|
if pr.Status == PullRequestStatusChecking { |
|
|
|
pr.Status = PULL_REQUEST_STATUS_MERGEABLE |
|
|
|
pr.Status = PullRequestStatusMergeable |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make sure there is no waiting test to process before levaing the checking status.
|
|
|
|
// Make sure there is no waiting test to process before levaing the checking status.
|
|
|
@ -750,7 +750,7 @@ func (pr *PullRequest) checkAndUpdateStatus() { |
|
|
|
func TestPullRequests() { |
|
|
|
func TestPullRequests() { |
|
|
|
prs := make([]*PullRequest, 0, 10) |
|
|
|
prs := make([]*PullRequest, 0, 10) |
|
|
|
x.Iterate(PullRequest{ |
|
|
|
x.Iterate(PullRequest{ |
|
|
|
Status: PULL_REQUEST_STATUS_CHECKING, |
|
|
|
Status: PullRequestStatusChecking, |
|
|
|
}, |
|
|
|
}, |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
pr := bean.(*PullRequest) |
|
|
|
pr := bean.(*PullRequest) |
|
|
|