Skip to content

Commit b848b09

Browse files
Merge pull request #254 from victoraugustofd/feat/workflow-auto-pr
Create auto-pr.yml
2 parents c3cab1c + a609af6 commit b848b09

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

.github/workflows/auto-pr.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Auto open pull request on challenge branches
2+
3+
on:
4+
push:
5+
branches:
6+
- 'challenge/201[5-9]-day-1[0-9]'
7+
- 'challenge/201[5-9]-day-2[0-5]'
8+
- 'challenge/201[5-9]-day-[1-9]'
9+
- 'challenge/20[2-9][0-9]-day-1[0-9]'
10+
- 'challenge/20[2-9][0-9]-day-2[0-5]'
11+
- 'challenge/20[2-9][0-9]-day-[1-9]'
12+
- 'challenge/2[1-9][0-9][0-9]-day-1[0-9]'
13+
- 'challenge/2[1-9][0-9][0-9]-day-2[0-5]'
14+
- 'challenge/2[1-9][0-9][0-9]-day-[1-9]'
15+
- 'challenge/[3-9][0-9][0-9][0-9]-day-1[0-9]'
16+
- 'challenge/[3-9][0-9][0-9][0-9]-day-2[0-5]'
17+
- 'challenge/[3-9][0-9][0-9][0-9]-day-[1-9]'
18+
19+
jobs:
20+
open-pull-request:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: get issue number
24+
id: get_issue_number
25+
run: |
26+
if [[ ${{ github.ref_name }} =~ challenge/([0-9]{4})-day-([1-9]|1[0-9]|2[0-5]) ]]; then
27+
year=${BASH_REMATCH[1]}
28+
day=${BASH_REMATCH[2]}
29+
30+
issue_number=$(gh issue list -S '[$year] [Day $day] in:title' --json number | jq '.[].number')
31+
32+
if [ -z "$issue_number" ]; then
33+
echo "::error::Issue not found!"
34+
exit 1
35+
else
36+
echo "issue_number=${issue_number}" >> $GITHUB_OUTPUT
37+
fi
38+
else
39+
echo "::error::Branch does not match the expected pattern"
40+
exit 1
41+
fi
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}
44+
- name: create pull request
45+
run: gh pr create -B ${{ GITHUB_DEFAULT_BRANCH }} -H ${{ github.ref_name }} --title 'Pull request to resolve #${{ steps.get_issue_number.outputs.issue_number }}'
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }}

0 commit comments

Comments
 (0)