-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (53 loc) · 1.7 KB
/
auto_pr.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
48
49
50
51
52
53
54
55
name: Auto PR
on:
push:
branches:
- staging
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const { repo, owner } = context.repo;
const title = '[Auto] Staging to main';
const {data:openPRs} = await await github.rest.pulls.list({
owner,
repo
});
const previouslyOpenedAutoPR = openPRs.filter(({title:_title}) => _title.includes(title));
if(previouslyOpenedAutoPR.length === 1) {
const pull_number = previouslyOpenedAutoPR[0].number;
await github.rest.pulls.update({
title,
owner,
repo,
pull_number,
head: '${{ github.ref_name }}',
base: 'main',
body: [
'This PR is auto-generated and updated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
return;
}
const result = await github.rest.pulls.create({
title,
owner,
repo,
head: '${{ github.ref_name }}',
base: 'main',
body: [
'This PR is auto-generated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['automated']
});