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

Question - what mergeable_state: blocked means? #122

Open
jorgecotillo opened this issue Nov 10, 2020 · 17 comments · May be fixed by #228
Open

Question - what mergeable_state: blocked means? #122

jorgecotillo opened this issue Nov 10, 2020 · 17 comments · May be fixed by #228
Labels
question Further information is requested

Comments

@jorgecotillo
Copy link

I am testing that from a forked repo I cannot auto-merge a PR, the response I get is:

2020-11-10T19:46:56.465Z INFO Event name: pull_request
2020-11-10T19:46:56.780Z INFO Updating PR #1311 Bad PR
2020-11-10T19:46:56.781Z INFO No update done due to PR mergeable_state blocked
2020-11-10T19:46:56.781Z INFO Merging PR #1311 Bad PR
2020-11-10T19:46:56.781Z INFO Current PR status: mergeable_state: blocked
2020-11-10T19:46:56.781Z INFO Retrying after 5000 ms ... (1/6)
2020-11-10T19:47:02.115Z INFO Current PR status: mergeable_state: blocked
2020-11-10T19:47:02.115Z INFO Retrying after 5000 ms ... (2/6)
2020-11-10T19:47:07.482Z INFO Current PR status: mergeable_state: blocked

Not sure if I get blocked because the GITHUB_TOKEN is read only on forks or if is something else, just want to make sure that PRs coming from forks cannot get merged.

Any assistance will be appreciated.

@pascalgn pascalgn added the question Further information is requested label Dec 21, 2020
@alansemenov
Copy link

@pascalgn I have a similar issue. I have a setup where the PR is auto-approved and all of the required steps have successfully passed, and the last action is the auto-merge. However the auto-merge action keep saying "Current PR status: mergeable_state: blocked" and the PR never gets merged...

Screenshot 2021-02-01 at 14 06 12

Screenshot 2021-02-01 at 14 06 20

@nilsreichardt
Copy link

Same issue 😞

@henrycarteruk
Copy link

Same issue here, auto-approve PR and then merge doesn't happen, just the same mergeable_state: blocked status.

@pascalgn
Copy link
Owner

I'm really sorry, but this action can only use the info that the GitHub API is giving. The only way I see is to capture screenshots of the PR, together with outputs of the PR API at the same time and then raise the issue at https://github.community/ but from my experience this will not lead to a (fast) resolution 😞

@pascalgn
Copy link
Owner

this action can only use the info that the GitHub API is giving

This is technically not true, of course. The experience with the GH API has been quite frustrating, so at this point I would also be relatively open for a PR which replaces the call of the GH API with some undocumented API or even crawling the HTML view of GitHub and checking if the "Merge" button is green... But this would have other issues, of course, possibly breaking the action completely when GitHub changes too much

@0mnius
Copy link

0mnius commented Dec 7, 2021

I'm having the same issue and it doesn't look like GH issue to me (or maybe i'm missing something)
As far as i understand it, the PR is in "blocked" state while mandatory checks workflows are running (until passed),
so i increased wait and retry as follows to make sure automerge is running last in the list:

- name: 'Auto merge'
  uses: pascalgn/[email protected]
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    MERGE_LABELS: ''
    MERGE_METHOD: squash
    MERGE_RETRIES: "12"
    MERGE_RETRY_SLEEP: "10000"
    LOG: "TRACE"

During the run action debug prints the mergeable_state as blocked, see the more parts of the log:

...
2021-12-07T15:14:54.6981962Z ##[group]Run hmarr/auto-approve-action@v2
2021-12-07T15:14:54.6982782Z with:
2021-12-07T15:14:54.6983752Z   github-token: ***
2021-12-07T15:14:54.6984774Z ##[endgroup]
2021-12-07T15:14:56.0876391Z Creating approving review for pull request #36
2021-12-07T15:14:56.9184098Z Approved pull request #36
2021-12-07T15:14:56.9359796Z ##[group]Run pascalgn/[email protected]
2021-12-07T15:14:56.9360404Z env:
2021-12-07T15:14:56.9361755Z   GITHUB_TOKEN: ***
2021-12-07T15:14:56.9362170Z   MERGE_LABELS: 
2021-12-07T15:14:56.9362533Z   MERGE_METHOD: squash
2021-12-07T15:14:56.9362918Z   MERGE_RETRIES: 12
2021-12-07T15:14:56.9363284Z   MERGE_RETRY_SLEEP: 10000
2021-12-07T15:14:56.9364710Z   LOG: TRACE
2021-12-07T15:14:56.9365072Z ##[endgroup]
...
2021-12-07T15:14:57.0485066Z 2021-12-07T15:14:57.044Z INFO  Event name: pull_request
2021-12-07T15:14:57.0486458Z 2021-12-07T15:14:57.044Z TRACE Event data: {
...
2021-12-07T15:14:57.6248024Z   author_association: 'CONTRIBUTOR',
2021-12-07T15:14:57.6248662Z   auto_merge: null,
2021-12-07T15:14:57.6249243Z   active_lock_reason: null,
2021-12-07T15:14:57.6249894Z   merged: false,
2021-12-07T15:14:57.6250457Z   mergeable: true,
2021-12-07T15:14:57.6251015Z   rebaseable: true,
2021-12-07T15:14:57.6251628Z   mergeable_state: 'blocked',
2021-12-07T15:14:57.6252195Z   merged_by: null,
2021-12-07T15:14:57.6253244Z   comments: 0,
2021-12-07T15:14:57.6253785Z   review_comments: 0,
2021-12-07T15:14:57.6254416Z   maintainer_can_modify: false,
2021-12-07T15:14:57.6254990Z   commits: �1,
2021-12-07T15:14:57.6255496Z   additions: 1364,
2021-12-07T15:14:57.6256040Z   deletions: 3570,
2021-12-07T15:14:57.6256864Z   changed_files: �4
}
2021-12-07T15:14:57.1217700Z 2021-12-07T15:14:57.046Z DEBUG Getting pull request info for 36 ...
2021-12-07T15:14:57.5847290Z 2021-12-07T15:14:57.583Z TRACE Full PR: {
...
2021-12-07T15:14:57.6251628Z   mergeable_state: 'blocked',
}
2021-12-07T15:14:57.6258050Z 2021-12-07T15:14:57.584Z INFO  Skipping PR update, required label missing: automerge
2021-12-07T15:14:57.6258943Z 2021-12-07T15:14:57.585Z INFO  Merging PR #36 Cleanup obsolete objects
2021-12-07T15:14:57.6259780Z 2021-12-07T15:14:57.585Z INFO  Current PR status: mergeable_state: blocked
2021-12-07T15:14:57.6260527Z 2021-12-07T15:14:57.585Z INFO  Retrying after 10000 ms ... (1/12)
2021-12-07T15:15:07.5899564Z 2021-12-07T15:15:07.589Z DEBUG Getting latest PR data...
2021-12-07T15:15:08.0882622Z 2021-12-07T15:15:08.085Z TRACE PR: {
...
2021-12-07T15:15:08.1279402Z   mergeable_state: 'blocked',
}
2021-12-07T15:15:08.1284907Z 2021-12-07T15:15:08.086Z INFO  Current PR status: mergeable_state: blocked
2021-12-07T15:15:08.1285654Z 2021-12-07T15:15:08.086Z INFO  Retrying after 10000 ms ... (2/12)
2021-12-07T15:15:18.0950895Z 2021-12-07T15:15:18.094Z DEBUG Getting latest PR data...
2021-12-07T15:15:18.5552001Z 2021-12-07T15:15:18.552Z TRACE PR: {

And so on till the last retry:

2021-12-07T15:16:54.0570056Z 2021-12-07T15:16:54.017Z INFO  Current PR status: mergeable_state: blocked
2021-12-07T15:16:54.0570914Z 2021-12-07T15:16:54.017Z INFO  Retrying after 10000 ms ... (12/12)
2021-12-07T15:17:04.0286771Z 2021-12-07T15:17:04.028Z DEBUG Getting latest PR data...
2021-12-07T15:17:04.4607653Z 2021-12-07T15:17:04.459Z TRACE PR: {
...
2021-12-07T15:17:04.4987470Z   mergeable_state: 'blocked',
}
2021-12-07T15:17:04.4993384Z 2021-12-07T15:17:04.459Z INFO  Current PR status: mergeable_state: blocked
2021-12-07T15:17:04.4994191Z 2021-12-07T15:17:04.460Z INFO  PR not ready to be merged after 12 tries

During the same time i polled the GH pulls API (ref: https://docs.github.com/en/rest/reference/pulls#get-a-pull-request)
But i was getting a different mergeable_state then action:

{
  "author_association": "CONTRIBUTOR",
  "auto_merge": null,
  "active_lock_reason": null,
  "merged": false,
  "mergeable": true,
  "rebaseable": true,
  "mergeable_state": "unstable",
  "merged_by": null,
  "comments": 0,
  "review_comments": 0,
  "maintainer_can_modify": false,
  "commits": 1,
  "additions": 1364,
  "deletions": 3570,
  "changed_files": 4
}

So somehow we are getting cached response from github? or there is a bug in the action itself?

@pascalgn
Copy link
Owner

pascalgn commented Dec 7, 2021

I don't think it's a bug in the action, we are simply calling the API, using octokit (the official GH client)

https://github.com/pascalgn/automerge-action/blob/main/lib/merge.js#L270-L281

async function getPullRequest(octokit, pullRequest) {
  logger.debug("Getting latest PR data...");
  const { data: pr } = await octokit.pulls.get({
    owner: pullRequest.base.repo.owner.login,
    repo: pullRequest.base.repo.name,
    pull_number: pullRequest.number
  });

  logger.trace("PR:", pr);

  return pr;
}

However, your idea sounds good, so I searched for "cache" and found this issue octokit/octokit.js#890 so it looks like at least some replies may be cached.

From that issue, I think it could work if you changed the above function to

async function getPullRequest(octokit, pullRequest) {
  logger.debug("Getting latest PR data...");
  const { data: pr } = await octokit.pulls.get({
    owner: pullRequest.base.repo.owner.login,
    repo: pullRequest.base.repo.name,
    pull_number: pullRequest.number,
    headers: {
      "If-None-Match": ""
    }
  });

  logger.trace("PR:", pr);

  return pr;
}

You can create a PR for it if you like, or I can also try it

@0mnius
Copy link

0mnius commented Dec 7, 2021

Thank you! i'll test from fork and will open PR if it works!😊

@roryabraham
Copy link
Contributor

roryabraham commented Dec 15, 2021

Hi @pascalgn, thanks for maintaining this action, we've been using it in production over at Expensify for about a year now, and for the most part it works great! However, we've also been experiencing this particular issue, and I have two suggestions.


First, I noticed that when we reach https://github.com/pascalgn/automerge-action/blob/main/lib/merge.js#L245, the action fails silently, such that a later step in the workflow with if: ${{ failure() }} does not run. I suggest that if the action fails to determine the mergeability of the pull request and thus does not merge it, the action should fail with a non-zero exit status and use core.setFailed to set a meaningful error message.


Second, I'd like to posit that maybe this action doesn't need to use the (mostly) undocumented mergeable_state field of the pull request, and instead should just rely on the more officially supported mergeable field:

The value of the mergeable attribute can be true, false, or null. If the value is null, then GitHub has started a background job to compute the mergeability. After giving the job time to complete, resubmit the request. When the job finishes, you will see a non-null value for the mergeable attribute in the response.

For what it's worth, I wrote a small custom action that polls the GH API to determine the mergeability of pull request, and have seen some workflow runs where my action resolves the mergeability of a pull request to true while the mergeable_state reported by this action remains blocked, causing this action to fail silently as noted above.

Here's an example workflow run that demonstrates what I'm talking about: https://github.com/Expensify/App/runs/4488449197?check_suite_focus=true

And in case it's helpful, here's a simplified version of custom action that I use to check the mergeability of a pull request (translated to use async/await instead of promises and removing our other library code):

const core = require('@actions/core');
const github = require('@actions/github');

const MAX_RETRIES = 30;
const THROTTLE_DURATION = 5000;

const run = async function () {
    const token = core.getInput('GITHUB_TOKEN', {required: true});
    const octokit = github.getOctokit(token);
    const gitHubOwner = core.getInput('GITHUB_OWNER', {required: true});
    const gitHubRepo = core.getInput('GITHUB_REPO', {required: true});
    const pullRequestNumber = Number(core.getInput('PULL_REQUEST_NUMBER', {required: true}));
    
    let retryCount = 0;
    let isMergeable = false;
    let mergeabilityResolved = false;
    console.log(`Checking the mergeability of PR #${pullRequestNumber}`);
    while (!mergeabilityResolved && retryCount < MAX_RETRIES) {
        try {
            const mergeable = (
                await octokit.pulls.get({
                    owner: gitHubOwner,
                    repo: gitHubRepo,
                    pull_number: pullRequestNumber,
                })
            ).data.mergeable;

            if (mergeable === null) {
                console.log('Pull request mergeability is not yet resolved...');
                retryCount++;
                
                // Wait 5 seconds before trying again
                await new Promise(resolve => setTimeout(resolve, THROTTLE_DURATION));
            } else {
                mergeabilityResolved = true;
                isMergeable = mergeable;
            }
        } catch (apiError) {
            mergeabilityResolved = true;
            console.error(`An error occurred fetching the PR from Github: ${JSON.stringify(apiError)}`);
            core.setFailed(apiError);
            return;
        }
    }
    
    if (retryCount >= MAX_RETRIES) {
        console.error('Maximum retries reached, mergeability is undetermined);
        core.setFailed(new Error(`Mergeability could not be determined after ${retryCount} retries 😞`));
        return;
    }

    console.log(`Pull request #${pullRequestNumber} is ${isMergeable ? '' : 'not '}mergeable`);
    core.setOutput('IS_MERGEABLE', isMergeable);
};

if (require.main === module) {
    run();
}

module.exports = run;

Let me know your thoughts! If you agree with my suggestions, I can submit a pull request to implement these changes.

@roryabraham
Copy link
Contributor

For what it's worth, I think we discovered why this action was failing for us and mergeable_status was resulting in blocked. We had enabled a setting which disallowed merging unsigned commits into a protected branch, and were attempting to use this action to merge a PR containing unsigned commits from one of our bot users. So that explains why mergeable was resolving to true, but mergeable_status was resolving to blocked.

It still would be preferable if this situation resulted in a failure instead of failing silently, but this is no longer a critical issue for us.

@roryabraham
Copy link
Contributor

roryabraham commented Dec 21, 2021

I submitted a pull request to (loudly) fail the action if the pull request cannot be merged.

@D4nte
Copy link

D4nte commented Jan 10, 2022

Would it make sense to have an option so that the action checks mergeable instead of mergeable_status?

@pascalgn
Copy link
Owner

@D4nte Yes, why not! Feel free to create a PR for it! 👍

@alfnunes
Copy link

alfnunes commented Apr 19, 2022

Hi @pascalgn I have got the same issue about merge pull request, this is my step:

      - name: auto merge
        uses: pascalgn/[email protected]
        if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          MERGE_LABELS: "automerge,dependencies"
          UPDATE_LABELS: "automerge,dependencies"            
          MERGE_METHOD: squash
          MERGE_COMMIT_MESSAGE: "Dependabot pull request"
          MERGE_RETRIES: "12"
          MERGE_RETRY_SLEEP: "10000"
          LOG: "TRACE"

this is just for my develop branch where we have protection rules, but the pr was approved, but i don't know why is blocked

author_association: 'NONE',
auto_merge: null,
active_lock_reason: null,
merged: false,
mergeable: true,
rebaseable: true,
mergeable_state: 'blocked',
merged_by: null,
comments: 12,
review_comments: 0,
maintainer_can_modify: false,
commits: 1,
additions: 40,
deletions: 39,
changed_files: 2
}
2022-04-19T23:04:13.840Z INFO Current PR status: mergeable_state: blocked
2022-04-19T23:04:13.844Z INFO PR not ready to be merged after 12 tries
2022-04-19T23:04:13.845Z INFO Action result: { mergeResult: 'not_ready', pullRequestNumber: 2808 }

There is a solution to merge pull request in a protect branch?

@pascalgn
Copy link
Owner

@roryabraham Regarding this comment #122 (comment), I thought about it some more and I think it could make sense to switch to the mergeable field, so if you still want to provide a PR for it, feel free!

@yCodeTech
Copy link

It'd be great to get a fix for this soon please. The idea of this action is great, but it doesn't work as other comments mentioned. Would love to get this working asap, so I don't need to worry about dependabot prs any more.

@roryabraham
Copy link
Contributor

@pascalgn I don't have much time to devote to this, but here's a PR to get us started: #228

@roryabraham roryabraham linked a pull request Apr 27, 2023 that will close this issue
github-actions bot pushed a commit to monde-sistemas/xml_data_extractor that referenced this issue Dec 3, 2024
… no commit (#92)

issue [Configurar automerge dos PRs sem utilizar kodiak](monde-sistemas/melhorias#349)

No commit, estava mostrando apenas o título e os detalhes do PR. Não tinha o link do PR. Estou adicionando essa configuração para mostrar o link do PR no commit.
Também estou alterando a forma de fazer o merge, removendo o pascalgn/automerge-action porque ele estava [falhando em alguns PRs](https://github.com/monde-sistemas/m2/actions/runs/12121505151/job/33793229889). Encontrei pascalgn/automerge-action#122 sobre o problema.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants