-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (62 loc) · 2.45 KB
/
process-issue-zip.yml
File metadata and controls
74 lines (62 loc) · 2.45 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Process Issue Attachments
on:
issue_comment:
types: [ created ]
jobs:
handle-upload:
if: |
contains(github.event.comment.body, '.zip)')) &&
contains(fromJSON('["pftg"]'), github.event.comment.user.login)
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Parse comment
id: parse
run: |
ZIP_URL=$(echo "${{ github.event.comment.body }}" |
grep -oP '\[.*?\]\((https?://.*?\.zip)\)' |
grep -oP '(https?://.*?\.zip)')
echo "url=$ZIP_URL" >> $GITHUB_OUTPUT
echo "issue=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
- name: Download and process ZIP
if: steps.parse.outputs.url != ''
run: |
wget "${{ steps.parse.outputs.url }}" -O upload.zip
mkdir -p "tmp/posts/${{ steps.parse.outputs.issue }}"
unzip upload.zip -d "tmp/posts/${{ steps.parse.outputs.issue }}"
rm upload.zip
- name: Create branch and commit files
if: steps.parse.outputs.url != ''
run: |
git config --global user.name "Issue Processor"
git config --global user.email "actions@github.com"
# Create a new branch
BRANCH_NAME="add-files-issue-${{ steps.parse.outputs.issue }}"
git checkout -b $BRANCH_NAME
git add .
git commit -m "Add files from issue #${{ steps.parse.outputs.issue }}"
git push origin $BRANCH_NAME
- name: Create Pull Request
if: steps.parse.outputs.url != ''
id: create_pr
env:
GH_TOKEN: ${{ github.token }}
run: |
pr_url=$(gh pr create --base master \
--title "Add files from issue #${{ steps.parse.outputs.issue }}" \
--body "This PR adds files uploaded in issue #${{ steps.parse.outputs.issue }}. \
Automatically created by the Process Issue Attachments workflow.")
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
- name: Update issue
if: steps.parse.outputs.issue != '' && steps.create_pr.outputs.pr_url != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
gh issue comment ${{ steps.parse.outputs.issue }} \
--body "✅ Files processed and a Pull Request has been created! \
View PR: ${{ steps.create_pr.outputs.pr_url }}"