-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (119 loc) · 4.72 KB
/
Copy pathcoderabbit.yml
File metadata and controls
145 lines (119 loc) · 4.72 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# CodeRabbit integration for pull requests and pushes to main.
#
# 1. GitHub App (recommended): install https://github.com/apps/coderabbitai on nowo-tech/DoctrineEncryptBundle.
# Reviews pull requests automatically (no workflow required).
# 2. CLI job (optional): set repository secret CODERABBIT_API_KEY (Agentic API key from CodeRabbit dashboard).
#
# Triggers:
# - pull_request → CLI review of the PR diff
# - push to main/master → CLI review of the pushed commits (no PR required)
# - workflow_run (after CI on a PR) → posts @coderabbitai review for the GitHub App
name: CodeRabbit
on:
pull_request:
branches: [main, master]
types: [opened, synchronize, reopened]
push:
branches: [main, master]
workflow_run:
workflows: [CI]
types: [completed]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: coderabbit-${{ github.event.pull_request.number || github.event.workflow_run.id || github.sha }}
cancel-in-progress: true
jobs:
cli-review:
name: CodeRabbit CLI
if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
- name: Install CodeRabbit CLI
run: curl -fsSL https://cli.coderabbit.ai/install.sh | sh
- name: Run CodeRabbit CLI review
env:
CODERABBIT_API_KEY: ${{ secrets.CODERABBIT_API_KEY }}
run: |
if [ -z "$CODERABBIT_API_KEY" ]; then
echo "::warning::CODERABBIT_API_KEY is not set. Skipping CLI review."
echo "Add an Agentic API key secret, or rely on the CodeRabbit GitHub App for PR reviews."
exit 0
fi
coderabbit auth login --api-key "$CODERABBIT_API_KEY"
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.ref }}"
elif [ "${{ github.event_name }}" = "push" ]; then
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
echo "Initial push to branch — reviewing against HEAD~1."
BASE="HEAD~1"
else
BASE="$BEFORE"
fi
else
BASE="main"
fi
echo "Reviewing changes against base: $BASE"
coderabbit review --plain --base "$BASE"
request-review-after-ci:
name: Request CodeRabbit review after CI
if: >
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Request CodeRabbit review on PR
uses: actions/github-script@v7
with:
script: |
const run = context.payload.workflow_run;
const pulls = run.pull_requests ?? [];
if (pulls.length === 0) {
core.info('No pull request linked to this CI workflow run.');
return;
}
const prNumber = pulls[0].number;
const { owner, repo } = context.repo;
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: prNumber,
per_page: 100,
});
const alreadyRequested = comments.some((comment) =>
comment.body?.includes('@coderabbitai review') &&
comment.user?.login === 'github-actions[bot]'
);
if (alreadyRequested) {
core.info(`CodeRabbit review already requested on PR #${prNumber}.`);
return;
}
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: '@coderabbitai review',
});
core.info(`Requested CodeRabbit review on PR #${prNumber} after CI success.`);
workflow-run-skipped:
name: CodeRabbit (no PR to review)
if: >
github.event_name == 'workflow_run' &&
github.event.workflow_run.event != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Explain skipped review
run: |
echo "CI completed on a push to main — there is no pull request for CodeRabbit to review."
echo "Open a PR to trigger PR reviews, or rely on the cli-review job on push (requires CODERABBIT_API_KEY)."
# Maintainer: Héctor Franco Aceituno (@HecFranco)
# Organization: nowo-tech (https://github.com/nowo-tech)