-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
allow mark PR as manually merged by push option #21951
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
allow mark PR as manually merged by push option #21951
Conversation
follow go-gitea#12543 when push with push option `merge-pulls=pull_index1[,pull_index2,...]` will mark chosed pull requests as `manually_merge_pull_confirmed`, then in `manuallyMerged` check, will skip config.AutodetectManualMerge and continue check whether these prs has been manually merged, if yes, the result will be same as `Autodetect manual merge`, else will reset the `manually_merge_pull_confirmed` flag. I think this enhancement can make "Mark PR as manually merged" and "Autodetect manual merge" have same behavior. Thanks. fix go-gitea#19528 Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
models/issues/pull.go
Outdated
// ManuallyMergePullConfirm confirm manually merge pulls by repo id and indexes | ||
func ManuallyMergePullConfirmByIndexes(ctx context.Context, repoID int64, indexes []int64) error { | ||
_, err := db.GetEngine(ctx).Where(builder.And( | ||
builder.Eq{"base_repo_id": repoID}, | ||
builder.Eq{"has_merged": false}, | ||
builder.In("`index`", indexes), | ||
)).Cols("manually_merge_pull_confirmed").Update(&PullRequest{ | ||
ManuallyMergePullConfirmed: true, | ||
}) | ||
|
||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't appear to do any permissions chcek?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, In my view, This is in the post hook, that meaning the permission check of pushing to the base branch has passed in pre-recevice
hoook. So not need check it again.if the pull request isn't be merged,nothing will happend after pull check.
routers/private/hook_post_receive.go
Outdated
mergePullIndexes := opts.GitPushOptions.Int64Array(private.GitPushOptionMergePulls) | ||
if len(mergePullIndexes) > 0 { | ||
if err := issues_model.ManuallyMergePullConfirmByIndexes(ctx, repo.ID, mergePullIndexes); err != nil { | ||
log.Error("Failed to manually merge pull confirm: %s/%s Error: %v", ownerName, repoName, err) | ||
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ | ||
Err: fmt.Sprintf("Failed to manually merge pull confirm: %s/%s Error: %v", ownerName, repoName, err), | ||
}) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't appear to do any permissions checks?
Why not just do the manualMerge checks here instead of hacking in this new ManuallyMergePullConfirm flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if do it here, It will be duplicate with the 'pull check' logic. add a single flag to ignore AutodetectManualMerge
config is the more simple way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an extern limit,only mark pull request as merge confirmed if the base branch is updated in this push event, How about this state?
0b3ef59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But by not doing the check when processing the receive-hook you risk the flag being reset to false before the pull is actually processed. Remember these two things are occurring in totally different goroutines and may be occurring semi-concurrently.
There's no guarantee that the next time manuallyMerged() is run relates to this particular push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, But checking pull reuest will cost much time, should not do it in hook. it's really a hard problem ...
maybe use a counter instead of a boolen flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: a1012112796 <1012112796@qq.com>
Signed-off-by: a1012112796 <1012112796@qq.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #21951 +/- ##
=======================================
Coverage ? 47.26%
=======================================
Files ? 1111
Lines ? 149456
Branches ? 0
=======================================
Hits ? 70636
Misses ? 70431
Partials ? 8389
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Please resolve the conflicts |
modules/private/hook.go
Outdated
GitPushOptionRepoPrivate = "repo.private" | ||
GitPushOptionRepoTemplate = "repo.template" | ||
GitPushOptionMergePulls = "merge-pulls" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to name it pulls.merge
to keep using the same naming convention?
Signed-off-by: a1012112796 <1012112796@qq.com>
Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
L-G-T-M but I don't know enough about the codebase to approve. BTW you should update the PR description |
oops, did not know the bot would do that |
follow #12543
when push with push option
merge-pulls=pull_index1[,pull_index2,...]
will mark chosed pull requests asmanually_merge_pull_confirmed
, then inmanuallyMerged
check, will skip config.AutodetectManualMerge and continue check whether these prs has been manually merged, if yes, the result will be same asAutodetect manual merge
, else will reset themanually_merge_pull_confirmed
flag. I think this enhancement can make "Mark PR as manually merged" and "Autodetect manual merge" have same behavior. Thanks.fix #19528
todo:
manually-merged
merge option after this pr.Signed-off-by: a1012112796 1012112796@qq.com
example:
