-
-
Notifications
You must be signed in to change notification settings - Fork 206
100 lines (80 loc) · 2.91 KB
/
commit-suggest.yaml
File metadata and controls
100 lines (80 loc) · 2.91 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: commit-suggest.yaml
on:
workflow_run:
workflows: ["rcc"]
types:
- completed
permissions:
contents: write
pull-requests: write
jobs:
commit-suggest:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Show event payload
run: |
echo '${{ toJson(github.event) }}' | jq .
shell: bash
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Download artifact
uses: actions/download-artifact@v6
with:
name: changes-patch
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
continue-on-error: true
- name: Check if artifact exists
id: check-artifact
run: |
if [ -f changes.patch ]; then
echo "has_diff=true" >> $GITHUB_OUTPUT
else
echo "has_diff=false" >> $GITHUB_OUTPUT
echo "No changes-patch artifact found"
fi
shell: bash
- name: Find PR number for branch from correct head repository
id: find-pr
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
PR_NUMBER=$(gh pr list --head ${{ github.event.workflow_run.head_branch }} --state open --json number,headRepositoryOwner --jq '.[] | select(.headRepositoryOwner.login == "${{ github.event.workflow_run.head_repository.owner.login }}") | .number' || echo "")
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
shell: bash
- name: Generate comment body
if: steps.check-artifact.outputs.has_diff == 'true'
id: comment-body
run: |
cat << 'EOF' > comment.md
## Formatting suggestions available
A patch file with formatting suggestions has been generated. You can apply it using one of these methods:
### Method 1: Apply via gh CLI
```bash
# Download and apply the patch directly
gh run download ${{ github.event.workflow_run.id }} --repo ${{ github.repository }} --name changes-patch && patch -p1 < changes.patch && rm changes.patch
```
### Method 2: View the patch
<details>
<summary>Click to see the patch contents</summary>
```diff
EOF
cat changes.patch >> comment.md
cat << 'EOF' >> comment.md
```
</details>
---
*This comment was automatically generated by the commit-suggester workflow.*
EOF
shell: bash
- name: Post or update comment
if: steps.check-artifact.outputs.has_diff == 'true'
uses: thollander/actions-comment-pull-request@v3
with:
pr-number: ${{ steps.find-pr.outputs.pr_number }}
file-path: comment.md
comment-tag: formatting-suggestions
mode: recreate