mirror of https://github.com/FabricMC/yarn.git
Now use the pull_request_target trigger, also update the branch and handle merge conflicts (#2113)
This commit is contained in:
parent
0ffc0f985e
commit
153c4572f3
|
@ -1,13 +1,12 @@
|
||||||
name: Update Base Branch
|
name: Update Base Branch
|
||||||
|
|
||||||
# Run every 20 mins or manually
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
pull_request_target:
|
||||||
- cron: '*/20 * * * *'
|
types: [ labeled ]
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update:
|
update:
|
||||||
|
if: ${{ github.event.label.name == 'update-base' }}
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@v3
|
- uses: actions/github-script@v3
|
||||||
|
@ -17,37 +16,32 @@ jobs:
|
||||||
const updateLabel = 'update-base';
|
const updateLabel = 'update-base';
|
||||||
const owner = context.repo.owner;
|
const owner = context.repo.owner;
|
||||||
const repo = context.repo.repo;
|
const repo = context.repo.repo;
|
||||||
|
const pull_number = issue_number = ${{ github.event.number }};
|
||||||
|
|
||||||
const response = await github.repos.get({ owner, repo })
|
const { data: repoData } = await github.repos.get({ owner, repo });
|
||||||
const base = response.data.default_branch
|
const base = repoData.default_branch;
|
||||||
|
|
||||||
async function updateBase(pull) {
|
const { data: pull } = await github.pulls.get({ owner, repo, pull_number });
|
||||||
const pull_number = issue_number = pull.number;
|
|
||||||
|
|
||||||
if (pull.base.ref == base) {
|
if (pull.base.ref == base) {
|
||||||
await github.issues.createComment({ owner, repo, issue_number, body: '🚨 Target branch is already set to ' + 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
|
} else {
|
||||||
await github.pulls.update({ owner, repo, pull_number, base });
|
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.createComment({ owner, repo, issue_number, body: '🚀 Target branch has been updated to ' + base });
|
||||||
await github.issues.removeLabel({ owner, repo, issue_number, name: updateLabel });
|
await github.issues.removeLabel({ owner, repo, issue_number, name: updateLabel });
|
||||||
}
|
|
||||||
|
|
||||||
// Query all of the open pull requests
|
try {
|
||||||
const pulls = await github.pulls.list({
|
// Updates the pull request with the latest upstream changes.
|
||||||
owner,
|
await github.pulls.updateBranch({ owner, repo, pull_number })
|
||||||
repo,
|
} catch (error) {
|
||||||
state: 'open'
|
// 422 is returned when there is a merge conflict
|
||||||
});
|
if (error.status === 422) {
|
||||||
|
await github.issues.createComment({ owner, repo, issue_number, body: '🚨 Please fix merge conflicts before this can be merged' });
|
||||||
|
await github.issues.addLabels({ owner, repo, issue_number, labels: ['outdated'] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Loop all of the pull requests, finding any with the target label.
|
throw error;
|
||||||
for (const pull of pulls.data) {
|
|
||||||
const requiresUpdate = pull.labels.some((label) => label.name === updateLabel);
|
|
||||||
|
|
||||||
if (requiresUpdate) {
|
|
||||||
await updateBase(pull);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue