Skip to content

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

Closed

Conversation

a1012112796
Copy link
Member

@a1012112796 a1012112796 commented Nov 27, 2022

follow #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 #19528

todo:

  • maybe remove manually-merged merge option after this pr.

Signed-off-by: a1012112796 1012112796@qq.com

example:
quickly_merge

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>
@a1012112796 a1012112796 added the type/enhancement An improvement of existing functionality label Nov 27, 2022
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 27, 2022
a1012112796 and others added 2 commits November 28, 2022 07:57
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Signed-off-by: a1012112796 <1012112796@qq.com>
@yardenshoham yardenshoham added this to the 1.19.0 milestone Nov 28, 2022
Comment on lines 832 to 843
// 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
}
Copy link
Contributor

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?

Copy link
Member Author

@a1012112796 a1012112796 Dec 16, 2022

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.

Comment on lines 117 to 125
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
}
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

@a1012112796 a1012112796 Dec 19, 2022

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeripath how about use version for sync? Thanks. b8ffb32

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@4d20a4a). Click here to learn what that means.
The diff coverage is 13.63%.

📣 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           
Impacted Files Coverage Δ
models/issues/pull.go 49.35% <0.00%> (ø)
routers/private/hook_post_receive.go 58.70% <5.26%> (ø)
modules/private/hook.go 3.20% <18.18%> (ø)
services/pull/check.go 27.54% <37.50%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lunny
Copy link
Member

lunny commented Feb 3, 2023

Please resolve the conflicts

Comment on lines 33 to 35
GitPushOptionRepoPrivate = "repo.private"
GitPushOptionRepoTemplate = "repo.template"
GitPushOptionMergePulls = "merge-pulls"
Copy link
Member

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>
@yardenshoham
Copy link
Member

yardenshoham commented Feb 5, 2023

L-G-T-M but I don't know enough about the codebase to approve. BTW you should update the PR description

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 5, 2023
@yardenshoham
Copy link
Member

oops, did not know the bot would do that

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 5, 2023
@a1012112796 a1012112796 removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Feb 5, 2023
@a1012112796
Copy link
Member Author

L-G-T-M but I don't know enough about the codebase to approve. BTW you should update the PR description

#19528 is the reason of this pull requst. I think it will be better solution than #12543 (after pushing mark pull as manually merged)

@yardenshoham yardenshoham modified the milestones: 1.19.0, 1.20.0 Feb 22, 2023
@delvh delvh removed this from the 1.20.0 milestone Jun 4, 2023
@a1012112796 a1012112796 closed this Nov 6, 2023
@a1012112796 a1012112796 deleted the zzc/dev/merge-pull-manually-quick branch November 6, 2023 01:42
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different behavior of "Mark PR as manually merged" and "Autodetect manual merge"
7 participants