-
Notifications
You must be signed in to change notification settings - Fork 17
56 lines (52 loc) · 1.94 KB
/
pr.yaml
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
48
49
50
51
52
53
54
55
56
name: Pull Request Flow
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
# tags-ignore and/or paths does not work with pull_request_target
# tags-ignore:
# - "automated pr"
# paths:
# - "packages/**"
jobs:
notify:
name: Notify snapshot update
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 10
submodules: true
- name: List up snapshots
id: snapshots
run: |
echo "::set-output name=snapshots::$(ls -1 snapshot-*.opam | sed -e 's/\.opam$//' | sort -n | tr '\n' ' ')"
- name: Update the PR body
uses: actions/github-script@v2
env:
SNAPSHOTS: ${{ steps.snapshots.outputs.snapshots }}
with:
github-token: ${{ github.token }}
script: |
const pullRequestId = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
};
const pull_request = await github.pulls.get(pullRequestId);
const actionHeader = '\n# Automatic follow-ups\n';
const body = (pull_request.data.body || '').replace(/\r?\n/g, '\n');
console.log('body', body);
const splitted = body.split(actionHeader);
const actionSectionMessage = 'Choose follow-up actions. Do not write anything after this section.';
const actions =
process.env.SNAPSHOTS
.split(' ')
.filter((snapshot) => snapshot)
.map((snapshot) => `- Add to snapshot \`${snapshot}\``);
const replacedBody = `${splitted[0]}${actionHeader}${actionSectionMessage}\n${actions.join('\n')}`;
console.log('replacedBody', replacedBody);
await github.pulls.update({
...pullRequestId,
body: replacedBody
});