-
Notifications
You must be signed in to change notification settings - Fork 70
71 lines (63 loc) · 2.59 KB
/
code-review.yml
File metadata and controls
71 lines (63 loc) · 2.59 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
name: Gemini AI Code Review
# pull_request_target is needed to access the Gemini key and modify (set/remove labels, comment on)
# the pull request.
on: # zizmor: ignore[dangerous-triggers]
pull_request_target:
types: [opened, synchronize, reopened, labeled]
# TODO: Assign permissions in individual jobs rather than at the
# workflow level to avoid blindly handing out `pull-requests: write`
# at the workflow level to all jobs (particularly if new jobs are
# added in this workflow in the future).
permissions:
contents: read
pull-requests: write # zizmor: ignore[excessive-permissions]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
handle-label:
runs-on: ubuntu-latest
outputs:
should_run_review: ${{ steps.prep.outputs.should_run_review }}
# For future use
additional_context: ""
permissions:
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Handle review label
id: prep
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
LABEL_JSON: ${{ toJSON(github.event.pull_request.labels.*.name) }}
EVENT_ACTION: ${{ github.event.action }}
run: |
HAS_LABEL=$(jq -n 'env.LABEL_JSON | fromjson | any(. == "gemini-review")')
if [[ "${HAS_LABEL}" == "true" && "${EVENT_ACTION}" != "labeled" ]]; then
echo "gemini-review label found on a '${EVENT_ACTION}' event. Removing label and skipping review."
gh pr edit "${PR_NUMBER}" --remove-label "gemini-review"
echo "should_run_review=false" >> "${GITHUB_OUTPUT}"
elif [[ "${HAS_LABEL}" == "true" ]]; then
echo "gemini-review label found. Proceeding with review."
echo "should_run_review=true" >> "${GITHUB_OUTPUT}"
else
echo "gemini-review label not found. Skipping review."
echo "should_run_review=false" >> "${GITHUB_OUTPUT}"
fi
gemini-code-review:
needs: [handle-label]
if: needs.handle-label.outputs.should_run_review == 'true'
uses: './.github/workflows/gemini-review.yml'
permissions:
contents: 'read'
id-token: 'write'
issues: 'write'
pull-requests: 'write'
with:
additional_context: '${{ needs.handle-label.outputs.additional_context }}'
secrets:
GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}'