hrvey / combine-prs-workflow

Combine/group together PRs (for example from Dependabot and similar services)
https://www.hrvey.com/blog/combine-dependabot-prs
MIT License
296 stars 51 forks source link

Status check of PRs is broken #9

Closed algomaster99 closed 2 years ago

algomaster99 commented 2 years ago

Hey! Thanks for the workflow, first of all. I integrated it into https://github.com/SpoonLabs/sorald/ and it worked quite well. However, I had to fix the checking of CI status for each PR in the workflow. The URL here kept returning pending even though I am sure the CI was completed with exit code 0. This has also been reported on GitHub community forum.

mherger commented 2 years ago

@algomaster99 could you please share how you fixed that issue?

algomaster99 commented 2 years ago

Hi @mherger !

I did something like this:

if(${{ github.event.inputs.mustBeGreen }}) {
  console.log('Checking green status: ' + branch);
-  const statusResponse = await github.rest.repos.getCombinedStatusForRef({
+  const check_runs = await github.paginate('GET /repos/{owner}/{repo}/commits/{ref}/check-runs', {
    owner: context.repo.owner,
    repo: context.repo.repo,
    ref: branch
  });
- const state = statusResponse['data']['state'];
-  console.log('Validating status: ' + state);
-  if(state != 'success') {
-    console.log('Discarding ' + branch + ' with status ' + state);
-    statusOK = false;
+  for (const cr of check_runs.data.check_runs) {
+     console.log('Validating check conclusion: ' + cr.conclusion);
+     if(cr.conclusion != 'success') {
+       console.log('Discarding ' + branch + ' with check conclusion ' + cr.conclusion);
+       statusOK = false;
      }
}

Reference: https://github.com/SpoonLabs/sorald/blob/fd3db17453ace78fca5f8802f2a1cf7c32c780bd/.github/workflows/combine_prs.yml#L78-L95

martingjaldbaek commented 2 years ago

Hey, the latest release, 1.3.0, uses a new API that checks the PR/branch status in a way that works both for statuses set with GitHub Actions CI, and external tools. As such this issue should be fixed now. If for any reason it doesn't work for you, let me know!

algomaster99 commented 2 years ago

Thanks @martingjaldbaek ! I will incorporate the latest changes in our workflow.