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

surface merge conflicts in pr status #5999

Merged
merged 5 commits into from
Oct 3, 2022
Merged

Conversation

mntlty
Copy link
Collaborator

@mntlty mntlty commented Jul 25, 2022

closes #872

The field mergeStateStatus does not indicate if a merge is blocked due to a merge conflict. As an example, here is the response on a PR that has conflicts

{
	"data": {
		"repository": {
			"pullRequest": {
				"id": "PR_XXX",
				"mergeStateStatus": "DIRTY",
				"mergeable": "CONFLICTING"
			}
		}
	}
}

It is also in a preview and subject to change. The field mergeable indicates if there a conflict with the pull request, and is already part of the api.PullRequest struct.

Screen Shot 2022-09-29 at 8 15 24 AM

I'm not sure if the color, icon and text are the best to display this information, open to feedback!

Update:

Following this comment from @samcoe I've added a flag called show-conflicts with the intent that the additional field mergeable can be easily rolled into the default fields.

The flag will be effectively ignored if the user also passes --json, as that argument list will take precedence over the default fields, which is the current behavior without the flag.

@mntlty mntlty requested a review from a team as a code owner July 25, 2022 23:24
@mntlty mntlty requested review from samcoe and removed request for a team July 25, 2022 23:24
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Jul 25, 2022
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Jul 25, 2022
@mntlty
Copy link
Collaborator Author

mntlty commented Jul 25, 2022

tested using the -R flag in a different repo, and with the current branch

@samcoe samcoe self-assigned this Jul 26, 2022
@@ -189,7 +189,7 @@ func pullRequestStatus(httpClient *http.Client, repo ghrepo.Interface, options r
func pullRequestFragment(httpClient *http.Client, hostname string) (string, error) {
fields := []string{
"number", "title", "state", "url", "isDraft", "isCrossRepository",
"headRefName", "headRepositoryOwner", "mergeStateStatus",
"headRefName", "headRepositoryOwner", "mergeable", "mergeStateStatus",
Copy link
Contributor

Choose a reason for hiding this comment

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

Requesting the mergeable field kicks off a potentially expensive (and sometimes async) job of calculating mergeability of a PR. Requesting this field on all records when fetching PRs in bulk might have negative consequences. Do you have thoughts about that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mislav I'll check with my team about this concern and see if any of the experts have concerns or can suggest an alternative.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we're making internal changes that will improve the cost of this operation. let's revisit at the end of august and see where things are with that work

@vilmibm
Copy link
Contributor

vilmibm commented Aug 22, 2022

Marking blocked until end of august

@samcoe samcoe removed the blocked label Sep 19, 2022
@samcoe
Copy link
Contributor

samcoe commented Sep 28, 2022

@mntlty We discussed this offline as a team, with the still unknowns around the performance impact of the mergeable field on GHES and no easy way from the code to detect if a version of GHES has the performance changes implemented, we would like to see this PR changed to include a flag so users can opt into displaying merge conflicts rather than do it by default.

In the future we can start to include it by default and deprecate the flag but feel like this is the best path forward so that all our users have a good experience with pr status command.

@mntlty
Copy link
Collaborator Author

mntlty commented Sep 28, 2022

@mntlty We discussed this offline as a team, with the still unknowns around the performance impact of the mergeable field on GHES and no easy way from the code to detect if a version of GHES has the performance changes implemented, we would like to see this PR changed to include a flag so users can opt into displaying merge conflicts rather than do it by default.

In the future we can start to include it by default and deprecate the flag but feel like this is the best path forward so that all our users have a good experience with pr status command.

@samcoe that makes sense! Do you have a suggestion for what the flag should be called?

@samcoe
Copy link
Contributor

samcoe commented Sep 28, 2022

I don't think we need to overthink it. Calling it something like show-conflicts seem reasonable to me. From the docs it looks like the mergable field only shows if the pull request cannot be merged due to merge conflicts so having "conflicts" in the name seems like the right move.

@@ -186,12 +187,16 @@ func pullRequestStatus(httpClient *http.Client, repo ghrepo.Interface, options r
return &payload, nil
}

func pullRequestFragment(httpClient *http.Client, hostname string) (string, error) {
func pullRequestFragment(hostname string, showConflicts bool) (string, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is private function made sense to change the signature to support this change

@@ -186,12 +187,16 @@ func pullRequestStatus(httpClient *http.Client, repo ghrepo.Interface, options r
return &payload, nil
}

func pullRequestFragment(httpClient *http.Client, hostname string) (string, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

httpClient isn't used in this function

@mntlty
Copy link
Collaborator Author

mntlty commented Sep 29, 2022

@samcoe I've tested this with the new flag and without, with the json flag and without. I think this is ready for review 🙏

@@ -57,6 +58,7 @@ func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Co
},
}

cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Show merge conflicts on pull requests")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does it make sense for this to have a short alias, maybe -c?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense to add the short alias since --show-conflicts is a bit verbose.

Suggested change
cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Show merge conflicts on pull requests")
cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Display pull request merge conflict status")

I am not sure my wording is the best but I wanted the long description to clarify that this flag will show an indicator if the pull request has a merge conflict and not have confusion where people expect the whole merge conflict to be displayed.

Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

@mntlty Thanks for making the requested changed. Code looks good to me. Left a couple questions regarding UX for follow up. Once those are answered I think this is good to go.

@@ -57,6 +58,7 @@ func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Co
},
}

cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Show merge conflicts on pull requests")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense to add the short alias since --show-conflicts is a bit verbose.

Suggested change
cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Show merge conflicts on pull requests")
cmd.Flags().BoolVar(&opts.ShowConflicts, "show-conflicts", false, "Display pull request merge conflict status")

I am not sure my wording is the best but I wanted the long description to clarify that this flag will show an indicator if the pull request has a merge conflict and not have confusion where people expect the whole merge conflict to be displayed.

@@ -264,6 +268,10 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
fmt.Fprint(w, cs.Green(fmt.Sprintf("✓ %s Approved", s)))
}

if pr.Mergeable == "CONFLICTING" {
fmt.Fprintf(w, " %s", cs.Red("× Merge conflicts"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should display if there are no merge conflicts? I feel like all the other status indicators displayed have a success status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think having explicit colors and text for each of the possible states, mergeable, conflicting and unknown is an improvement 👍

fmt.Fprintf(w, " %s", cs.Green("✓ No merge conflicts"))
} else if pr.Mergeable == "CONFLICTING" {
fmt.Fprintf(w, " %s", cs.Red("× Merge conflicts"))
} else if pr.Mergeable == "UNKNOWN" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should be explicit rather than a default "else" or we will end up showing it on all PRs when the user doesn't provide a flag

Image

Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

@mntlty This is great thanks for making the requested changes, I pushed a small polish commit, I think this is ready to ship.

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Oct 3, 2022
@samcoe samcoe enabled auto-merge (squash) October 3, 2022 09:26
@mntlty
Copy link
Collaborator Author

mntlty commented Oct 3, 2022

@mntlty This is great thanks for making the requested changes, I pushed a small polish commit, I think this is ready to ship.

@samcoe thanks for all the feedback!

@samcoe samcoe merged commit 577d422 into trunk Oct 3, 2022
@samcoe samcoe deleted the mntlty/pr_status_conflicts branch October 3, 2022 09:32
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Oct 3, 2022
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

Information if PR has a conflicts
5 participants