forked from darkevilmac/pomf
-
Notifications
You must be signed in to change notification settings - Fork 0
47 lines (39 loc) · 1.93 KB
/
update-base.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: Update Base Branch
on:
pull_request_target:
types: [ labeled ]
jobs:
update:
if: ${{ github.event.label.name == 'update-base' }}
runs-on: ubuntu-20.04
steps:
- uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const updateLabel = 'update-base';
const owner = context.repo.owner;
const repo = context.repo.repo;
const pull_number = issue_number = ${{ github.event.number }};
const { data: repoData } = await github.repos.get({ owner, repo });
const base = repoData.default_branch;
const { data: pull } = await github.pulls.get({ owner, repo, pull_number });
if (pull.base.ref == base) {
await github.issues.createComment({ owner, repo, issue_number, body: '🚨 Target branch is already set to ' + base });
} else {
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 });
try {
// Updates the pull request with the latest upstream changes.
await github.pulls.updateBranch({ owner, repo, pull_number })
} catch (error) {
// 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;
}
throw error;
}
}