From 81afc7a3f967b607e28812ab0c4ce8c6d1e811a8 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 28 Feb 2021 16:27:59 +0000 Subject: [PATCH] Add a workflow to handle updating the target branch when the update-base label is applied to a PR. --- .github/workflows/update-base.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/update-base.yml diff --git a/.github/workflows/update-base.yml b/.github/workflows/update-base.yml new file mode 100644 index 0000000000..cd92072e64 --- /dev/null +++ b/.github/workflows/update-base.yml @@ -0,0 +1,27 @@ +name: Update Base Branch + +on: + pull_request: + types: [ labeled ] + +jobs: + update: + if: ${{ github.event.label.name == 'update-base' }} + runs-on: ubuntu-20.04 + steps: + - uses: actions/github-script@v3 + id: default-branch + with: + github-token: ${{secrets.GITHUB_TOKEN}} + result-encoding: string + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const pull_number = issue_number = ${{github.event.number}}; + + const response = await github.repos.get({owner, repo}) + const base = response.data.default_branch + + await github.pulls.update({ owner, repo, pull_number, base}); + await github.issues.createComment({ owner, repo, issue_number, body: '🚀 Target branch has been updated to ' + base}); + await github.issues.removeLabel({owner, repo, issue_number, name: 'update-base'}); \ No newline at end of file