@@ -55,15 +55,30 @@ jobs:
55
55
app-id : ' ${{ vars.APP_ID }}'
56
56
private-key : ' ${{ secrets.APP_PRIVATE_KEY }}'
57
57
58
- - name : ' Run Gemini Issue Triage'
58
+ - name : ' Get Repository Labels'
59
+ id : ' get_labels'
60
+ uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea'
61
+ with :
62
+ github-token : ' ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
63
+ script : |-
64
+ const { data: labels } = await github.rest.issues.listLabelsForRepo({
65
+ owner: context.repo.owner,
66
+ repo: context.repo.repo,
67
+ });
68
+ const labelNames = labels.map(label => label.name);
69
+ core.setOutput('available_labels', labelNames.join(','));
70
+ console.log(`Found ${labelNames.length} labels:`, labelNames);
71
+ return labelNames;
72
+
73
+ - name : ' Run Gemini Issue Analysis'
59
74
uses : ' ./'
60
- id : ' gemini_issue_triage '
75
+ id : ' gemini_issue_analysis '
61
76
env :
62
- GITHUB_TOKEN : ' ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
63
77
ISSUE_TITLE : ' ${{ github.event.issue.title }}'
64
78
ISSUE_BODY : ' ${{ github.event.issue.body }}'
65
79
ISSUE_NUMBER : ' ${{ github.event.issue.number }}'
66
80
REPOSITORY : ' ${{ github.repository }}'
81
+ AVAILABLE_LABELS : ' ${{ steps.get_labels.outputs.available_labels }}'
67
82
with :
68
83
gemini_cli_version : ' ${{ vars.GEMINI_CLI_VERSION }}'
69
84
gcp_workload_identity_provider : ' ${{ vars.GCP_WIF_PROVIDER }}'
77
92
{
78
93
"maxSessionTurns": 25,
79
94
"coreTools": [
80
- "run_shell_command(echo)",
81
- "run_shell_command(gh label list)",
82
- "run_shell_command(gh issue edit)"
95
+ "run_shell_command(echo)"
83
96
],
84
97
"telemetry": {
85
98
"enabled": true,
@@ -90,41 +103,92 @@ jobs:
90
103
## Role
91
104
92
105
You are an issue triage assistant. Analyze the current GitHub issue
93
- and apply the most appropriate existing labels. Use the available
106
+ and identify the most appropriate existing labels. Use the available
94
107
tools to gather information; do not ask for information to be
95
108
provided.
96
109
97
110
## Steps
98
111
99
- 1. Run: `gh label list` to get all available labels .
112
+ 1. Review the available labels in the environment variable: "${AVAILABLE_LABELS}" .
100
113
2. Review the issue title and body provided in the environment
101
114
variables: "${ISSUE_TITLE}" and "${ISSUE_BODY}".
102
- 3. Classify issues by their kind (bug, enhancement, documentation,
103
- cleanup, etc) and their priority (p0, p1, p2, p3). Set the
104
- labels accoridng to the format `kind/*` and `priority/*` patterns.
105
- 4. Apply the selected labels to this issue using:
106
- `gh issue edit "${ISSUE_NUMBER}" --add-label "label1,label2"`
107
- 5. If the "status/needs-triage" label is present, remove it using:
108
- `gh issue edit "${ISSUE_NUMBER}" --remove-label "status/needs-triage"`
115
+ 3. Classify issue by the appropriate labels from the available labels.
116
+ 4. Output the appropriate labels for this issue in JSON format, for example:
117
+ ```
118
+ {"labels_to_add": ["kind/bug", "priority/p2"], "labels_to_remove": ["status/needs-triage"]}
119
+ ```
120
+ 5. If the issue cannot be classified using the available labels, output:
121
+ ```
122
+ {"labels_to_add": [], "labels_to_remove": []}
123
+ ```
109
124
110
125
## Guidelines
111
126
112
127
- Only use labels that already exist in the repository
113
- - Do not add comments or modify the issue content
114
- - Triage only the current issue
115
128
- Assign all applicable labels based on the issue content
116
129
- Reference all shell variables as "${VAR}" (with quotes and braces)
130
+ - Output only valid JSON format
131
+ - Do not include any explanation or additional text, just the JSON
117
132
118
- - name : ' Post Issue Triage Failure Comment '
133
+ - name : ' Apply Labels to Issue '
119
134
if : |-
120
- ${{ failure() && steps.gemini_issue_triage.outcome == 'failure' }}
135
+ ${{ steps.gemini_issue_analysis.outputs.summary != '' }}
136
+ env :
137
+ REPOSITORY : ' ${{ github.repository }}'
138
+ ISSUE_NUMBER : ' ${{ github.event.issue.number }}'
139
+ LABELS_OUTPUT : ' ${{ steps.gemini_issue_analysis.outputs.summary }}'
140
+ uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea'
141
+ with :
142
+ github-token : ' ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
143
+ script : |-
144
+ // Strip code block markers if present
145
+ let labelsJson = process.env.LABELS_OUTPUT;
146
+ labelsJson = labelsJson.replace(/^```(?:json)?\s*/, '').replace(/\s*```$/, '').trim();
147
+ const triageResult = JSON.parse(labelsJson);
148
+ console.log('Triage result:', triageResult);
149
+
150
+ // Apply labels
151
+ if (triageResult.labels_to_add && triageResult.labels_to_add.length > 0) {
152
+ await github.rest.issues.addLabels({
153
+ owner: context.repo.owner,
154
+ repo: context.repo.repo,
155
+ issue_number: parseInt(process.env.ISSUE_NUMBER),
156
+ labels: triageResult.labels_to_add
157
+ });
158
+ console.log(`Applied labels: ${triageResult.labels_to_add.join(', ')}`);
159
+ }
160
+
161
+ // Remove labels
162
+ if (triageResult.labels_to_remove && triageResult.labels_to_remove.length > 0) {
163
+ for (const label of triageResult.labels_to_remove) {
164
+ try {
165
+ await github.rest.issues.removeLabel({
166
+ owner: context.repo.owner,
167
+ repo: context.repo.repo,
168
+ issue_number: parseInt(process.env.ISSUE_NUMBER),
169
+ name: label
170
+ });
171
+ console.log(`Removed label: ${label}`);
172
+ } catch (error) {
173
+ // Label might not exist on the issue, which is fine
174
+ console.log(`Could not remove label ${label}: ${error.message}`);
175
+ }
176
+ }
177
+ }
178
+
179
+ - name : ' Post Issue Analysis Failure Comment'
180
+ if : |-
181
+ ${{ failure() && steps.gemini_issue_analysis.outcome == 'failure' }}
182
+ env :
183
+ ISSUE_NUMBER : ' ${{ github.event.issue.number }}'
184
+ RUN_URL : ' ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
121
185
uses : ' actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea'
122
186
with :
123
187
github-token : ' ${{ steps.generate_token.outputs.token || secrets.GITHUB_TOKEN }}'
124
188
script : |-
125
189
github.rest.issues.createComment({
126
- owner: '${{ github.repository }}'.split('/')[0] ,
127
- repo: '${{ github.repository }}'.split('/')[1] ,
128
- issue_number: '${{ github.event.issue.number }}' ,
129
- body: 'There is a problem with the Gemini CLI issue triaging. Please check the [action logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id } }) for details.'
190
+ owner: context.repo.owner ,
191
+ repo: context.repo.repo ,
192
+ issue_number: parseInt(process.env.ISSUE_NUMBER) ,
193
+ body: 'There is a problem with the Gemini CLI issue triaging. Please check the [action logs](${process.env.RUN_URL }) for details.'
130
194
})
0 commit comments