Skip to content

pr merge: added --admin flag#4071

Merged
mislav merged 2 commits intocli:trunkfrom
rsteube:gh-merge-admin
Aug 3, 2021
Merged

pr merge: added --admin flag#4071
mislav merged 2 commits intocli:trunkfrom
rsteube:gh-merge-admin

Conversation

@rsteube
Copy link
Contributor

@rsteube rsteube commented Aug 2, 2021

Fixes #1198

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this!

switch status {
case "BLOCKED":
return !admin
case "BEHIND":
Copy link
Contributor

Choose a reason for hiding this comment

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

Does BEHIND allow the admin override? I've never tested this in the web UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that was just my assumption to what you wrote in #1198 (comment).
Probably wrong then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://stackoverflow.com/questions/34463895/git-this-branch-is-behind-after-pull-request BEHIND seems to be rather informational only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not too sure how to force the BEHIND state yet (for a test).

isPRAlreadyMerged := pr.State == "MERGED"
if blocked := blockedReason(pr.MergeStateStatus); !opts.AutoMergeEnable && !isPRAlreadyMerged && blocked != "" {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d is not mergeable: %s.\n", cs.FailureIcon(), pr.Number, blocked)
if !opts.AutoMergeEnable && !isPRAlreadyMerged && isBlocked(pr.MergeStateStatus, opts.Admin) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a new function isBlocked which mostly duplicates blockedReason, could blockedReason simply accept an extra Admin argument and adjust logic accordingly?

Copy link
Contributor Author

@rsteube rsteube Aug 2, 2021

Choose a reason for hiding this comment

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

Agree on that, thought about a double return as well after i commited it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed blockedReason accordingly but i am not to sure about the additional bool return (keeps it concise though).
Open for ideas.

if !opts.AutoMergeEnable && !isPRAlreadyMerged && isBlocked(pr.MergeStateStatus, opts.Admin) {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d is not mergeable: %s.\n", cs.FailureIcon(), pr.Number, blockedReason(pr.MergeStateStatus))
fmt.Fprintf(opts.IO.ErrOut, "To have the pull request merged after all the requirements have been met, add the `--auto` flag.\n")
if !opts.Admin && !isBlocked(pr.MergeStateStatus, true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of !isBlocked(pr.MergeStateStatus, true), which might be hard to parse for a human, what do you think about a new function called allowsAdminOverride(pr.MergeStateStatus)? I think something like that could communicate intent better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

BodySet bool
Editor editor

Admin bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be called UseAdmin so it reads better? The cli flag can stay the same for simplicity 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

@rsteube rsteube force-pushed the gh-merge-admin branch 2 times, most recently from a020b8a to baa18c1 Compare August 2, 2021 10:59
@mislav mislav enabled auto-merge August 3, 2021 13:51
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you!

@mislav mislav merged commit fbdebe8 into cli:trunk Aug 3, 2021
Copy link

@Phongsak5903 Phongsak5903 left a comment

Choose a reason for hiding this comment

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

@03-65

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confirm administrator privileges to merge a pull request when a repository requires it

4 participants