diff --git a/.github/workflows/rebase-dependabot.yml b/.github/workflows/rebase-dependabot.yml new file mode 100644 index 00000000..ee289a4c --- /dev/null +++ b/.github/workflows/rebase-dependabot.yml @@ -0,0 +1,62 @@ +name: rebase-dependabot +on: + push: + branches: [ main ] + +jobs: + dependabot_rebase: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Recreate open dependabot pull-requests + uses: actions/github-script@v7 + with: + script: | + const { repo: { owner, repo } } = context; + const pull_requests = await github.rest.pulls.list({ + owner, + repo, + state: 'open', + sort: 'long-running', + direction: 'asc', + }) + + for (const { number: pull_number, user } of pull_requests.data) { + if (user.login !== 'dependabot[bot]') { + continue; + } + + console.log(`Inspecting pull request #${pull_number}`); + + const pull_request = await github.rest.pulls.get({ + owner, + repo, + pull_number, + }); + + console.log(pull_request); + + // Skip dependabot pull requests which are being worked on + if (pull_request.data.commits !== 1) { + console.log('Skipping pull request as it is being worked on'); + continue; + } + + if (pull_request.data.mergeable === true) { + console.log('Skipping mergeable pull request'); + continue; + } + + // Comment to re-create the PR and set no-test + github.rest.issues.addLabels({ + issue_number: pull_number, + owner, + repo, + labels: ['no-test'] + }); + + // Only process one dependabot at a time. + break; + }