-
Notifications
You must be signed in to change notification settings - Fork 273
168 lines (149 loc) · 6.47 KB
/
ci-gemini-pr.yml
File metadata and controls
168 lines (149 loc) · 6.47 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Gemini Auto PR
on:
workflow_dispatch:
issues:
types: [labeled]
pull_request:
types: [labeled]
issue_comment:
types: [created]
concurrency:
group: ci-gemini-pr-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
jobs:
analyze-and-pr:
runs-on: ubuntu-latest
if: >
(
github.event_name == 'issues' &&
github.event.action == 'labeled' &&
contains(github.event.issue.labels.*.name, 'auto-fix')
) || (
github.event_name == 'pull_request' &&
github.event.action == 'labeled' &&
contains(github.event.pull_request.labels.*.name, 'auto-fix')
) || (
github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '@gemini-cli') &&
contains(github.event.comment.body, '/fix')
)
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: "3.x"
- name: Install dependencies
run: flutter pub get
- name: Analyze issue and create PR if solvable
id: analyze-pr
uses: google-github-actions/run-gemini-cli@v0
timeout-minutes: 20
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
use_gemini_code_assist: true
gemini_model: "gemini-2.5-pro"
prompt: |
You are an expert Flutter developer helping with the flutter_inapp_purchase package.
Analyze the following issue: ${{ github.event.issue.title || github.event.pull_request.title }}
Issue description:
${{ github.event.issue.body || github.event.pull_request.body }}
Your task:
1. Determine if this issue can be automatically resolved with code changes
2. If it's a bug that can be fixed or a simple feature that can be implemented:
- Create a new branch named 'fix-issue-${{ github.event.issue.number }}' (only if it does not already exist)
- Make the necessary code changes following the CLAUDE.md guidelines
- Ensure all tests pass (flutter test)
- Ensure code is formatted (dart format .)
- Create a pull request that references issue #${{ github.event.issue.number }}
3. If the issue requires human intervention or discussion:
- Add a comment explaining why it cannot be automatically resolved
- Suggest what information or decisions are needed
Important:
- Follow the API changes and naming conventions in CLAUDE.md
- MUST comply with OpenIAP specification: https://openiap.dev
- APIs: https://openiap.dev/docs/apis
- Types: https://openiap.dev/docs/types
- Events: https://openiap.dev/docs/events
- Errors: https://openiap.dev/docs/errors
- Maintain backward compatibility unless explicitly mentioned in the issue
- Add tests for any new functionality
- Update documentation if needed
Idempotency and Safety Requirements:
- Before deleting any branch, first check existence using: `git rev-parse --verify <branch>`.
Only delete if it exists. Never loop on the same failing command.
- If branch creation fails once, stop and return an error with a single clear message.
- If the Gemini API returns a 429 (quota exceeded), stop immediately and surface the error; do not retry in a loop.
- Never attempt to switch to a branch you are already on; check current branch with `git rev-parse --abbrev-ref HEAD`.
- Keep commands minimal and fail-fast; no repeated attempts of the same action.
Only create a PR if you're confident the solution is correct and complete.
settings: |
{
"tools": [
{ "name": "gh" },
{ "name": "git" },
{ "name": "flutter" },
{ "name": "dart" }
],
"repositories": [
{ "path": ".", "instructions": "Refer to CLAUDE.md for conventions. Keep changes minimal, add tests, and follow pre-commit checks." }
],
"model": "gemini-1.5-flash"
}
- name: Comment on issue with result
if: always()
uses: actions/github-script@v7
with:
script: |
const issueNumber = context.issue.number;
const outputs = JSON.parse(process.env.ANALYZE_OUTPUTS || "{}");
const summary = outputs.summary || '';
const error = outputs.error || '';
let comment = '';
if (error) {
let friendly = '';
const lower = String(error).toLowerCase();
if (lower.includes('429') || lower.includes('resource_exhausted') || lower.includes('quota')) {
friendly = '\n\nIt looks like the Gemini API quota was exceeded. Please try again later or switch to a higher-quota model/key. You can retrigger by commenting `@gemini-cli /fix` once quota is available.';
}
comment = `Failed to analyze or fix the issue:${friendly}\n\n\`\`\`\n${error}\n\`\`\``;
} else if (summary) {
comment = `Gemini Analysis Result:\n${summary}`;
}
if (comment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: comment
});
}
env:
ANALYZE_OUTPUTS: ${{ toJSON(steps.analyze-pr.outputs) }}
auto-pr-on-comment:
runs-on: ubuntu-latest
if: >
github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '@gemini-cli') &&
contains(github.event.comment.body, '/fix')
steps:
- name: React to comment
uses: actions/github-script@v7
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});