-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 1.73 KB
/
issue-to-empty-commit.yml
File metadata and controls
58 lines (46 loc) · 1.73 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
name: Issue to Empty Commit
on:
issues:
types: [opened, edited]
permissions:
contents: write
issues: write
jobs:
issue_to_commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Extract issue data
run: |
jq . "$GITHUB_EVENT_PATH" > event.json
echo "ISSUE_NUMBER=$(jq -r .issue.number event.json)" >> $GITHUB_ENV
echo "ISSUE_TITLE=$(jq -r .issue.title event.json)" >> $GITHUB_ENV
jq -r .issue.body event.json > issue_body.txt
- name: Generate commit message
run: |
echo "issue(#$ISSUE_NUMBER): $ISSUE_TITLE" > commit_message.txt
echo "" >> commit_message.txt
echo "Issue link: https://github.com/$GITHUB_REPOSITORY/issues/$ISSUE_NUMBER" >> commit_message.txt
echo "" >> commit_message.txt
echo "Body:" >> commit_message.txt
cat issue_body.txt >> commit_message.txt
echo "Commit message:"
cat commit_message.txt
- name: Configure git
run: |
git config user.name "issue-bot"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create empty commit
run: |
git commit --allow-empty -F commit_message.txt || echo "nothing to commit"
- name: Push commit
run: |
git push origin HEAD:main
- name: Close issue
run: |
curl -s -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${ISSUE_NUMBER} \
-d '{"state":"closed","state_reason":"completed"}'