Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check for conflicts/merging if the PR has not been merged in the interim #10132

Merged
merged 37 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ef1a8a5
Only check for merging if the PR has not been merged in the interim
zeripath Feb 3, 2020
e29a6de
fixup! Only check for merging if the PR has not been merged in the in…
zeripath Feb 3, 2020
1205165
Try to fix test failure
zeripath Feb 3, 2020
ee7d5f7
Use PR2 not PR1 in tests as PR1 merges automatically
zeripath Feb 4, 2020
4c00eb6
Merge branch 'master' into improve-pr-check
zeripath Feb 4, 2020
9a90443
return already merged error
zeripath Feb 4, 2020
ad20cd2
Merge branch 'master' into improve-pr-check
zeripath Feb 5, 2020
fdc055e
enforce locking
zeripath Feb 6, 2020
0f9e498
enforce locking - fix-test
zeripath Feb 6, 2020
5551c6d
enforce locking - fix-testx2
zeripath Feb 6, 2020
7d5772f
enforce locking - fix-testx3
zeripath Feb 6, 2020
76f7eef
move pullrequest checking to after merge
zeripath Feb 9, 2020
a60c5b8
Remove minor race with getting merge commit id
zeripath Feb 9, 2020
87f5793
fixup
zeripath Feb 9, 2020
f8f886f
move check pr after merge
zeripath Feb 9, 2020
389342c
Remove unnecessary prepareTestEnv - onGiteaRun does this for us
zeripath Feb 9, 2020
203ff71
Add information about when merging occuring
zeripath Feb 9, 2020
bd6badc
Merge remote-tracking branch 'origin/master' into improve-pr-check
zeripath Feb 9, 2020
ab79a00
fix fmt
zeripath Feb 9, 2020
9c79c73
More logging
zeripath Feb 9, 2020
36c3771
Attempt to fix mysql
zeripath Feb 9, 2020
3a9768f
Try MySQL fix again
zeripath Feb 9, 2020
f055a73
try again
zeripath Feb 9, 2020
ca9103d
Try again?!
zeripath Feb 9, 2020
22631c2
Try again?!
zeripath Feb 9, 2020
fa8f010
Sigh
zeripath Feb 9, 2020
441ff1a
remove the count - perhaps that will help
zeripath Feb 9, 2020
52cd67c
next remove the update id
zeripath Feb 9, 2020
8373df4
next remove the update id - make it updated_unix instead
zeripath Feb 9, 2020
c8c5809
On failure to merge ensure that the pr is rechecked for conflict errors
zeripath Feb 9, 2020
f505332
On failure to merge ensure that the pr is rechecked for conflict errors
zeripath Feb 9, 2020
0140315
Merge branch 'master' into improve-pr-check
zeripath Feb 9, 2020
bd7c2eb
Merge branch 'master' into improve-pr-check
lafriks Feb 9, 2020
7486e16
Update models/pull.go
zeripath Feb 9, 2020
7955006
Update models/pull.go
zeripath Feb 9, 2020
6bd8699
Apply suggestions from code review
zeripath Feb 9, 2020
1ffd6bc
Merge branch 'master' into improve-pr-check
zeripath Feb 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,20 @@ func (pr *PullRequest) SetMerged() (err error) {
return err
}

if count, err := sess.Where("id = ? AND has_merged != ?", pr.ID, true).Count(new(PullRequest)); err != nil {
lafriks marked this conversation as resolved.
Show resolved Hide resolved
return err
} else if count < 1 {
return nil
}

if err = pr.loadIssue(sess); err != nil {
return err
}

if pr.Issue.IsClosed {
return nil
}

if err = pr.Issue.loadRepo(sess); err != nil {
return err
}
Expand Down Expand Up @@ -707,6 +717,12 @@ func (pr *PullRequest) UpdateCols(cols ...string) error {
return err
}

// UpdateColsIfNotMerged updates specific fields of a pull request if it has not been merged
func (pr *PullRequest) UpdateColsIfNotMerged(cols ...string) error {
_, err := x.ID(pr.ID).Where("has_merged = ?", false).Cols(cols...).Update(pr)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
return err
}

// IsWorkInProgress determine if the Pull Request is a Work In Progress by its title
func (pr *PullRequest) IsWorkInProgress() bool {
if err := pr.LoadIssue(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions services/pull/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func AddToTaskQueue(pr *models.PullRequest) {
go func() {
err := prQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
pr.Status = models.PullRequestStatusChecking
err := pr.UpdateCols("status")
err := pr.UpdateColsIfNotMerged("status")
if err != nil {
log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
} else {
Expand Down Expand Up @@ -205,7 +205,7 @@ func handle(data ...queue.Data) {
if err != nil {
log.Error("GetPullRequestByID[%s]: %v", prID, err)
continue
} else if pr.Status != models.PullRequestStatusChecking {
} else if pr.HasMerged {
lafriks marked this conversation as resolved.
Show resolved Hide resolved
continue
} else if manuallyMerged(pr) {
continue
Expand Down