2021-02-28 11:27:59 -05:00
|
|
|
name: Update Base Branch
|
|
|
|
|
2021-02-28 13:35:52 -05:00
|
|
|
# Run every 20 mins or manually
|
2021-02-28 11:27:59 -05:00
|
|
|
on:
|
2021-02-28 13:35:52 -05:00
|
|
|
schedule:
|
|
|
|
- cron: '*/20 * * * *'
|
|
|
|
workflow_dispatch:
|
2021-02-28 11:27:59 -05:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
update:
|
|
|
|
runs-on: ubuntu-20.04
|
|
|
|
steps:
|
|
|
|
- uses: actions/github-script@v3
|
|
|
|
with:
|
|
|
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
|
|
|
script: |
|
2021-02-28 13:35:52 -05:00
|
|
|
const updateLabel = 'update-base';
|
2021-02-28 11:27:59 -05:00
|
|
|
const owner = context.repo.owner;
|
|
|
|
const repo = context.repo.repo;
|
|
|
|
|
2021-02-28 13:35:52 -05:00
|
|
|
const response = await github.repos.get({ owner, repo })
|
2021-02-28 11:27:59 -05:00
|
|
|
const base = response.data.default_branch
|
|
|
|
|
2021-02-28 13:35:52 -05:00
|
|
|
async function updateBase(pull) {
|
|
|
|
const pull_number = issue_number = pull.number;
|
|
|
|
|
|
|
|
if (pull.base.ref == base) {
|
|
|
|
await github.issues.createComment({ owner, repo, issue_number, body: '🚨 Target branch is already set to ' + base });
|
|
|
|
await github.issues.removeLabel({ owner, repo, issue_number, name: updateLabel });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update target PR 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: updateLabel });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query all of the open pull requests
|
|
|
|
const pulls = await github.pulls.list({
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
state: 'open'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Loop all of the pull requests, finding any with the target label.
|
|
|
|
for (const pull of pulls.data) {
|
|
|
|
const requiresUpdate = pull.labels.some((label) => label.name === updateLabel);
|
|
|
|
|
|
|
|
if (requiresUpdate) {
|
|
|
|
await updateBase(pull);
|
|
|
|
}
|
|
|
|
}
|