-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Auto merge pull requests when all checks succeeded via API #9307
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
Merged
Merged
Changes from all commits
Commits
Show all changes
307 commits
Select commit
Hold shift + click to select a range
341aef2
Fix indention
kolaente 10d2dd6
Add option to merge a pr right now without waiting for the checks to …
kolaente 6044bc6
Fix lint
kolaente 452310d
Add scheduled pr merge to tables used for testing
kolaente 72ae3de
Merge branch 'master' into feature/auto-merge
kolaente 7b14e16
Add status param to make GetPullRequestByHeadBranch reusable
kolaente 9b99253
Move "Merge now" to a seperate button to make the ui clearer
kolaente df39bcc
Update models/scheduled_pull_request_merge.go
kolaente 5f5c84c
Merge branch 'master' into feature/auto-merge
kolaente 2c3e2a6
Update web_src/js/index.js
kolaente 3321ad0
Merge branch 'master' into feature/auto-merge
kolaente eb63b61
Update web_src/js/index.js
kolaente e86a3ab
Merge branch 'master' into feature/auto-merge
kolaente 38278bb
Merge branch 'master' into feature/auto-merge
kolaente 2dbd642
Merge remote-tracking branch 'origin/feature/auto-merge' into feature…
kolaente 308d423
Re-add migration after merge
kolaente 81efbaf
Fix frontend lint
kolaente 1d54f4c
Fix version compare
kolaente d4337b2
Add vendored dependencies
kolaente 0c9a741
Add basic tets
kolaente 407bdab
Make sure the api route is capable of scheduling PRs for merging
kolaente 2ac0136
Merge branch 'master' into feature/auto-merge
kolaente 5f2d076
Fix comparing version
kolaente 1109de2
Merge branch 'feature/auto-merge' of github.com:kolaente/gitea into f…
kolaente 4cd7ba0
make vendor
kolaente 11cc7a0
Merge branch 'master' into feature/auto-merge
6543 f2c2547
adopt refactor
6543 7316455
apply suggestion: User -> Doer
6543 01cc62f
init var once
6543 5fe32f1
Fix Test
6543 c55d67a
Merge branch 'master' into feature/auto-merge
kolaente 6cfe63b
Merge branch 'master' into feature/auto-merge
6543 79667e9
Merge branch 'master' into feature/auto-merge
kolaente 9808a8b
Merge branch 'master' into feature/auto-merge
kolaente 8ffc978
Merge branch 'master' into feature/auto-merge
6543 5c99f8b
Merge branch 'master' into feature/auto-merge
6543 bbe51fb
Update templates/repo/issue/view_content/comments.tmpl
6543 4d1b77b
Merge branch 'master' into feature/auto-merge
6543 a21bc92
adopt
6543 fd290d1
Merge branch 'master' into feature/auto-merge
6543 673b657
Merge branch 'master' into feature/auto-merge
6543 f30ab00
Merge branch 'master' into feature/auto-merge
6543 a1dab29
nits
6543 f92385f
next
6543 738f66a
code format
6543 fe86285
lint
6543 b3f90f2
Merge branch 'master' into feature/auto-merge
6543 ac6c002
use same name schema; rm CreateUnScheduledPRToAutoMergeComment
6543 7745e74
API: can not create schedule twice
6543 b271c15
Add TestGetBranchNamesForSha
6543 b1a7f4d
Merge branch 'master' into feature/auto-merge
6543 0927f33
nits
6543 7029905
new go routine for each pull to merge
6543 003a0cd
Merge branch 'master' into feature/auto-merge
6543 d75691d
Merge branch 'master' into feature/auto-merge
6543 d1c1f31
Merge branch 'master' into feature/auto-merge
kolaente 6f00624
Merge branch 'main' into feature/auto-merge
kolaente c317e30
Merge branch 'main' into feature/auto-merge
6543 68475a3
Update models/pull.go
kolaente 1f0231f
Update models/scheduled_pull_request_merge.go
kolaente f0a4720
Merge branch 'main' into feature/auto-merge
6543 8432030
fix & add renaming sugestions
6543 55ac505
Update services/automerge/pull_auto_merge.go
6543 745b784
Merge branch 'main' into feature/auto-merge
kolaente efa97ce
Merge branch 'master' into feature/auto-merge
6543 38c9538
Merge branch 'main' into feature/auto-merge
6543 2a8d230
Merge branch 'master' into feature/auto-merge
6543 848990c
fix conflict relicts
6543 ab20836
Merge branch 'master' into feature/auto-merge
6543 4e52813
apply latest refactors
6543 6f1bee0
Merge branch 'main' into feature/auto-merge
kolaente cf0aea9
fix: migration after merge
kolaente f6c0cad
Merge branch 'main' into feature/auto-merge
6543 0b89b6c
Update models/error.go
kolaente 0b6724b
Update options/locale/locale_en-US.ini
kolaente 6d2bb4e
Update options/locale/locale_en-US.ini
kolaente 5abb112
Merge branch 'master' into feature/auto-merge
6543 8522e4c
Merge branch 'main' into feature/auto-merge
6543 4100e19
Merge branch 'master' into feature/auto-merge
6543 635abdd
adapt latest refactors
6543 af22476
fix test
6543 68c0bd7
Merge branch 'master' into feature/auto-merge
6543 dfc8a7a
use more context
6543 397bb67
skip potential edgecases
6543 c0fbcaa
document func usage
6543 529cf03
Merge branch 'master' into feature/auto-merge
6543 f63742e
GetBranchNamesForSha() -> GetRefsBySha()
6543 28295f7
start refactoring
6543 af9a58b
Merge branch 'master' into feature/auto-merge
6543 b2930ec
ajust to new changes
6543 47c815d
nit
6543 dcbd06d
docu nit
6543 9b9bd7b
Merge branch 'master' into feature/auto-merge
6543 03eb945
the great check move
6543 6a9dae2
Merge branch 'master' into feature/auto-merge
6543 d8e0686
move checks for branchprotection into own package
6543 6f15ec8
resolve todo now ...
6543 f17abd1
move & rename
6543 2a66e96
unexport if posible
6543 d2023d8
fix
6543 8292182
check if merge is allowed before merge on scheduled pull
6543 c8496aa
debugg
6543 80b63ee
Merge branch 'master' into feature/auto-merge
6543 a1073bc
Merge branch 'main' into single-place-to-enforce-protected-branch-rules
6543 52cb7c4
wording
6543 f4b4a0b
Merge branch 'main' into single-place-to-enforce-protected-branch-rules
6543 c0e932a
improve SetDefaults & nits
6543 6959e27
NotAllowedToMerge -> DisallowedToMerge
6543 4775c3a
fix test
6543 8c6a54f
Merge branch 'main' into single-place-to-enforce-protected-branch-rules
6543 943d1f2
merge files
6543 f7b89a5
Merge branch 'master' into single-place-to-enforce-protected-branch-r…
6543 19200ac
Merge branch 'master' into feature/auto-merge
6543 5d3f346
Merge branch 'single-place-to-enforce-protected-branch-rules' into fe…
6543 120d84d
use package "errors"
6543 d0a2312
merge files
6543 ce534e0
Merge branch 'single-place-to-enforce-protected-branch-rules' into fe…
6543 4c2460f
Merge branch 'master' into feature/auto-merge
6543 f187990
add string names
6543 e99481c
other implementation for gogit
6543 6a10944
Merge branch 'master' into feature/auto-merge
6543 ff93d83
Merge branch 'master' into feature/auto-merge
6543 3baf1d0
Merge branch 'main' into feature/auto-merge
6543 4f1344c
Merge branch 'master' into feature/auto-merge
6543 03cbafd
adapt refactor
6543 261b407
more context for models/pull.go
6543 90f96cf
GetUserRepoPermission use context
6543 505c2cd
Merge branch 'master' into feature/auto-merge
6543 1583951
more ctx
6543 ec11287
Merge branch 'master' into refactor-from-9307
6543 832d7d6
use context for loading pull head/base-repo
6543 abf5067
more ctx
6543 fea87e6
more ctx
6543 e3e3741
models.LoadIssueCtx()
6543 1013108
models.LoadIssueCtx()
6543 9088331
Handle pull_service.Merge in one DB transaction
6543 673a81a
add TODOs
6543 6765298
next
6543 82259d5
next
6543 0b2a290
next
6543 e283421
Merge branch 'master' into refactor-from-9307
6543 811e15a
more ctx
6543 bf432d8
more ctx
6543 fbb9f50
Merge branch 'main' into feature/auto-merge
6543 461bea5
Start refactoring structure of old pull code ...
6543 b226064
move code into new packages
6543 981cdde
shorter names ... and finish **restructure**
6543 0e56288
Update models/branches.go
6543 2d079ee
finish UpdateProtectBranch
6543 bc474bb
more and fix
6543 594517f
Merge branch 'refactor-from-9307' into feature/auto-merge
6543 7c411f4
update datum
6543 6d793b4
template: use "svg" helper
6543 fd58a14
rename prQueue 2 prPatchCheckerQueue
6543 cad41d2
handle automerge in queue
6543 fe4b06f
lock pull on git&db actions ...
6543 e6b7918
lock pull on git&db actions ...
6543 29319c4
add TODO notes
6543 524ece7
Merge branch 'pull_service-lock-per-pull' into feature/auto-merge
6543 a4d5f48
Merge branch 'main' into refactor-from-9307
6543 72ad384
Merge branch 'master' into refactor-from-9307
6543 4e74172
the regex
6543 61786f8
transaction in tests
6543 266f4b3
GetRepositoryByIDCtx
6543 20d00b8
Merge branch 'master' into feature/auto-merge
6543 76f0501
Merge branch 'refactor-from-9307' into feature/auto-merge
6543 b422328
shorter table name and lint fix
6543 cdc8706
Merge branch 'main' into refactor-from-9307
6543 1eb7812
Merge branch 'master' into refactor-from-9307
6543 ef4fcbe
close transaction bevore notify
6543 c856a2e
Merge branch 'refactor-from-9307' into feature/auto-merge
6543 6c9ff86
Merge branch 'master' into feature/auto-merge
6543 545d33e
Merge branch 'master' into feature/auto-merge
6543 ddf1157
Update models/pull.go
6543 35b3071
Merge branch 'master' into feature/auto-merge
6543 b5b8ca3
Merge branch 'main' into feature/auto-merge
6543 02abd0c
next
6543 10b277b
CheckPullMergable check all branch protections!
6543 9330ec4
Merge branch 'main' into feature/auto-merge
6543 d9c07c9
Update routers/web/repo/pull.go
6543 22f7a4b
CheckPullMergable check all branch protections!
6543 2003602
Revert "PullService lock via pullID (#19520)" (for now...)
6543 8411cc9
Merge branch 'CheckPullMergable_check_all_branch_protections' into fe…
6543 ceda060
Merge branch 'master' into feature/auto-merge
6543 faa06f1
Update services/pull/check.go
6543 b09b46b
Use for a repo action one database transaction
6543 04207b9
Apply suggestions from code review
6543 a6a335a
Merge branch 'main' into more-context-again
6543 cd48d31
Apply suggestions from code review
6543 54e849a
Update services/issue/status.go
6543 48b76f9
Merge branch 'master' into more-context-again
6543 443168a
Update services/issue/status.go
6543 419f064
use db.WithTx()
6543 0312d2f
gofmt
6543 427ba1e
Merge branch 'master' into more-context-again
6543 cdb4683
Merge branch 'master' into feature/auto-merge
6543 9cc0d28
Merge branch 'more-context-again' into feature/auto-merge
6543 7538993
make pr.GetDefaultMergeMessage() context aware
6543 ca8c1f1
make MergePullRequestForm.SetDefaults context aware
6543 e188963
use db.WithTx()
6543 3d3b847
pull.SetMerged only with context
6543 5d0a243
fix deadlock in `test-sqlite\#TestAPIBranchProtection`
6543 7741935
dont forget templates
6543 244f3f2
db.WithTx allow to set the parentCtx
6543 95df0f2
handle db transaction in service packages but not router
6543 58a7322
issue_service.ChangeStatus just had caused another deadlock :/
6543 4e099bd
if we merge a pull in one database transaktion, we get a lock, becaus…
6543 9813c63
Merge branch 'more-context-again' into feature/auto-merge
6543 d127b81
Merge branch 'master' into feature/auto-merge
6543 6d60e05
ajust to current master
6543 d3cc762
Apply suggestions from code review
6543 6e30456
dont open db transaction in router
6543 b0b8ed6
make generate-swagger
6543 713796e
one _success less
6543 1db379f
wording nit
6543 8bb0bd6
rm
6543 27ce2b0
adapt
6543 a47cd88
Merge branch 'main' into feature/auto-merge
6543 7ce6963
remove not needed test files
6543 faef76e
rm less diff & use attr in JS
6543 7456862
...
6543 01cebae
Merge branch 'main' into feature/auto-merge
6543 3911dcf
Update services/repository/files/commit.go
6543 4c0a287
Merge branch 'main' into feature/auto-merge
6543 16c7bbb
Merge branch 'main' into feature/auto-merge
6543 6633101
Merge branch 'master' into feature/auto-merge
6543 07ebb0d
ajust db schema for PullAutoMerge
6543 6eec790
skip broken pull refs
6543 5cf709d
more context in error messages
6543 9f43fc9
remove webUI part for another pull
6543 6566141
remove more WebUI only parts
6543 93702a4
API: add CancleAutoMergePR
6543 89670eb
Apply suggestions from code review
6543 23e2b84
Merge branch 'main' into feature/auto-merge
6543 f5458d2
fix lint
6543 34d0600
Merge branch 'main' into feature/auto-merge
6543 e4922f7
Apply suggestions from code review
zeripath 3fa4840
cancle -> cancel
6543 1e17e83
Merge branch 'main' into feature/auto-merge
6543 cd522b3
change queue identifyer
6543 a57444e
fix swagger
6543 4f97aa1
prevent nil issue
6543 e374f9f
Merge branch 'master' into feature/auto-merge
6543 ea5e940
fix and dont drop error
6543 8df24af
as per @zeripath
6543 bbbcf40
Update integrations/git_test.go
6543 2364692
Update integrations/git_test.go
6543 749df65
more declarative integration tests (dedup code)
6543 95052c9
use assert.False/True helper
6543 5fd0d6f
Merge branch 'main' into feature/auto-merge
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ func testGit(t *testing.T, u *url.URL) { | |
|
||
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "master", "test/head")) | ||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath)) | ||
t.Run("AutoMerge", doAutoPRMerge(&httpContext, dstPath)) | ||
t.Run("CreatePRAndSetManuallyMerged", doCreatePRAndSetManuallyMerged(httpContext, httpContext, dstPath, "master", "test-manually-merge")) | ||
t.Run("MergeFork", func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
@@ -615,6 +616,88 @@ func doBranchDelete(ctx APITestContext, owner, repo, branch string) func(*testin | |
} | ||
} | ||
|
||
func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
||
ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame) | ||
|
||
t.Run("CheckoutProtected", doGitCheckoutBranch(dstPath, "protected")) | ||
t.Run("PullProtected", doGitPull(dstPath, "origin", "protected")) | ||
t.Run("GenerateCommit", func(t *testing.T) { | ||
_, err := generateCommitWithNewData(littleSize, dstPath, "[email protected]", "User Two", "branch-data-file-") | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected3")) | ||
var pr api.PullRequest | ||
var err error | ||
t.Run("CreatePullRequest", func(t *testing.T) { | ||
pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, "protected", "unprotected3")(t) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
// Request repository commits page | ||
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d/commits", baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
resp := ctx.Session.MakeRequest(t, req, http.StatusOK) | ||
doc := NewHTMLParser(t, resp.Body) | ||
|
||
// Get first commit URL | ||
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Last().Attr("href") | ||
assert.True(t, exists) | ||
assert.NotEmpty(t, commitURL) | ||
|
||
commitID := path.Base(commitURL) | ||
|
||
// Call API to add Pending status for commit | ||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusPending)) | ||
|
||
// Cancel not existing auto merge | ||
ctx.ExpectedCode = http.StatusNotFound | ||
t.Run("CancelAutoMergePR", doAPICancelAutoMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
|
||
// Add auto merge request | ||
ctx.ExpectedCode = http.StatusCreated | ||
t.Run("AutoMergePR", doAPIAutoMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
|
||
// Can not create schedule twice | ||
ctx.ExpectedCode = http.StatusConflict | ||
t.Run("AutoMergePRTwice", doAPIAutoMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
|
||
// Cancel auto merge request | ||
ctx.ExpectedCode = http.StatusNoContent | ||
t.Run("CancelAutoMergePR", doAPICancelAutoMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
|
||
// Add auto merge request | ||
ctx.ExpectedCode = http.StatusCreated | ||
t.Run("AutoMergePR", doAPIAutoMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) | ||
|
||
// Check pr status | ||
ctx.ExpectedCode = 0 | ||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) | ||
assert.NoError(t, err) | ||
assert.False(t, pr.HasMerged) | ||
|
||
// Call API to add Failure status for commit | ||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusFailure)) | ||
|
||
// Check pr status | ||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) | ||
assert.NoError(t, err) | ||
assert.False(t, pr.HasMerged) | ||
|
||
// Call API to add Success status for commit | ||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusSuccess)) | ||
|
||
// wait to let gitea merge stuff | ||
time.Sleep(time.Second) | ||
|
||
// test pr status | ||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) | ||
assert.NoError(t, err) | ||
assert.True(t, pr.HasMerged) | ||
} | ||
} | ||
|
||
func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headBranch string) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
defer PrintCurrentTest(t)() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func addAutoMergeTable(x *xorm.Engine) error { | ||
type MergeStyle string | ||
type PullAutoMerge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
PullID int64 `xorm:"UNIQUE"` | ||
DoerID int64 `xorm:"NOT NULL"` | ||
MergeStyle MergeStyle `xorm:"varchar(30)"` | ||
Message string `xorm:"LONGTEXT"` | ||
CreatedUnix int64 `xorm:"created"` | ||
} | ||
|
||
return x.Sync2(&PullAutoMerge{}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.