-
Notifications
You must be signed in to change notification settings - Fork 2.5k
92 lines (75 loc) · 2.85 KB
/
pr-review-companion.yml
File metadata and controls
92 lines (75 loc) · 2.85 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
name: PR Review Companion
on:
pull_request_target:
permissions:
# Post comment in pull request.
pull-requests: write
concurrency:
group: pr-review-companion-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
diff:
runs-on: ubuntu-latest
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version-file: ".nvmrc"
package-manager-cache: false
- name: Install
run: npm ci
- name: Diff (by change)
run: npm run diff:flat -- $PR_NUMBER
env:
FORCE_COLOR: 3
- name: Diff (by change, mirroring applied)
run: npm run diff:flat -- $PR_NUMBER --mirror
env:
FORCE_COLOR: 3
- name: Diff (by feature)
run: npm run diff:flat -- $PR_NUMBER --no-group
env:
FORCE_COLOR: 3
- name: Diff (by feature, mirroring applied)
run: npm run diff:flat -- $PR_NUMBER --no-group --mirror
env:
FORCE_COLOR: 3
- name: Determine job url
id: job
run: |
job_id=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs --jq '.jobs[0].id')
echo "JOB_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${job_id}?pr=$PR_NUMBER" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Post message in PR
run: |
AUTHOR="github-actions"
MARKER="<!-- pr-review-companion -->"
BODY="${MARKER}
${COMMENT}"
COMMENT_ID=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --comments --json comments \
--jq ".comments | sort_by(.createdAt) | map(select(.author.login == \"$AUTHOR\" and (.body | contains(\"$MARKER\")))) | .[0].id")
if [ -n "$COMMENT_ID" ]; then
gh api graphql -f query='
mutation($id:ID!, $body:String!) {
updateIssueComment(input:{id:$id, body:$body}) {
issueComment {
id
}
}
}' -f id="$COMMENT_ID" -f body="$BODY"
else
gh pr comment "$PR_NUMBER" --repo "${{ github.repository }}" --body "$BODY"
fi
env:
COMMENT: |
_Tip_: Review these changes [grouped by change][1] (recommended for most PRs), or [grouped by feature][2] (for large PRs).
[1]: ${{ steps.job.outputs.JOB_URL }}#step:5:1
[2]: ${{ steps.job.outputs.JOB_URL }}#step:7:1
GITHUB_TOKEN: ${{ github.token }}