Skip to content

gh pr merge $pr_number --auto --merge fails if a required status check has failed. #8206

Description

@Bikram-DoorDash

Describe the feature or problem you’d like to solve

Say my pull request has 3 required status checks; one of them has already passed, one is currently running and one has failed.
I run this command -
gh pr merge $pr_number --auto --merge

This command fails with this error -
GraphQL: Required status check "check name" is failing. (mergePullRequest)

When I'm enabling auto-merge on a pull request, my intention is to automatically merge the PR when all required status checks pass; emphasis on "automatically merge". In the above example, I would've expected the auto-merge to be enabled on the PR, irrespective of the current status of the status checks. The PR won't be merged, but auto-merged should've been enabled, so that when the cause of the failed status check is fixed, the status check passes and the PR gets automatically merged.

Proposed solution

Enable auto-merge irrespective of the current status of the status checks.
If the auto-merge is not enabled because a status check is "failed", then the user will have to manually merge it later.
This also has potential of breaking CIs.

Activity

  1. Bikram-DoorDash commented on Oct 17, 2023

    @Bikram-DoorDash
    Author

    Huh...!! I'm checking more of my different CI job logs and I see the above behavior has happened only in one job while the auto-merge was enabled for other pull requests even when they too had one status check failure.

    I thought this might've been due to race-condition between the two jobs (status check job and the job that enables auto-merge). So, I manually ran the command on a PR which currently has a failed status check and it still enabled the auto-merge. 🤷🏼‍♂️

    So now I'm wondering why did it fail in that one job with the error msg clearly saying it failed because the other status check has failed!

  2. added
    gh-prrelating to the gh pr command
    and removed
    enhancementa request to improve CLI
    on Oct 24, 2023
  3. williammartin commented on Oct 24, 2023

    @williammartin
    Member

    Hi @bikram-agarwal, thanks for raising this and sorry you're running into issues. Is it possible for you to reproduce this, and if so can you show us the output with GH_DEBUG=api?

    Looking at the code I can only imagine one way that the CLI might have lead to this failure.

    We fetch the state of the PR here:

    pr, baseRepo, err := opts.Finder.Find(findOptions)

    Then we set autoMerge if you've provided the flag and it's not immediately mergeable:

    autoMerge: opts.AutoMergeEnable && !isImmediatelyMergeable(pr.MergeStateStatus),

    This conditional just checks the PR status field:

    switch status {
    case MergeStateStatusClean, MergeStateStatusHasHooks, MergeStateStatusUnstable:

    We then pass that field directly through as part of the merge payload:

    if payload.auto {
    var mutation struct {
    EnablePullRequestAutoMerge struct {
    ClientMutationId string
    } `graphql:"enablePullRequestAutoMerge(input: $input)"`
    }
    variables["input"] = EnablePullRequestAutoMergeInput{input}
    return gql.Mutate(payload.repo.RepoHost(), "PullRequestAutoMerge", &mutation, variables)
    }

    You can see that after sending that we exit and don't even try to merge the PR. However, your error indicates that we hit a mutation further down:

    var mutation struct {
    MergePullRequest struct {
    ClientMutationId string
    } `graphql:"mergePullRequest(input: $input)"`
    }
    return gql.Mutate(payload.repo.RepoHost(), "PullRequestMerge", &mutation, variables)

    However, I can't find any reason why the platform would indicate that we are in one of those states (mergeable) and then later become unmergeable. That said, I can't speak for the platform's consistency here. It wouldn't be the first time it didn't behave as expected.

    I think without further logs from GH_DEBUG=api on an error we will have difficult investigating this.

  4. added
    more-info-neededMore info needed from user/contributor
    and removed on Oct 24, 2023
  5. williammartin commented on Oct 24, 2023

    @williammartin
    Member

    Just to double check, on your failed case are you absolutely sure that you provided the --auto flag correctly?

  6. andyfeller commented on Nov 20, 2023

    @andyfeller
    Contributor

    @bikram-agarwal : Can you confirm this is still a problem, or can it be closed? Have you been able to recreate the issue and capture debug logs?

    Given Will's walkthrough and the error message you received, the GitHub GraphQL API return that error when trying to enable the auto merge on the PR.

  7. Bikram-DoorDash commented on Nov 20, 2023

    @Bikram-DoorDash
    Author

    Hi. Sorry about not responding here earlier.
    I have been monitoring the output of my CI since going live, and we haven't had this issue again. I am unable to reproduce this issue. Guess it was just a one-time fluke caused by something unknown.
    This issue can be closed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    gh-prrelating to the gh pr commandmore-info-neededMore info needed from user/contributor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions