Skip to content

Commit ea56112

Browse files
Copilotswissspidy
andcommitted
Split workflow into reusable and calling workflows
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 7b6dc58 commit ea56112

2 files changed

Lines changed: 334 additions & 318 deletions

File tree

.github/workflows/issue-triage.yml

Lines changed: 4 additions & 318 deletions
Original file line numberDiff line numberDiff line change
@@ -16,322 +16,8 @@ name: Issue Triage
1616
required: false
1717
type: string
1818

19-
permissions:
20-
issues: write
21-
contents: read
22-
2319
jobs:
24-
triage-new-issue:
25-
name: Triage New Issue
26-
if: github.event_name == 'issues'
27-
runs-on: ubuntu-latest
28-
steps:
29-
- name: Get available labels
30-
id: get-labels
31-
uses: actions/github-script@v7
32-
with:
33-
script: |
34-
const labels = await github.rest.issues.listLabelsForRepo({
35-
owner: context.repo.owner,
36-
repo: context.repo.repo,
37-
per_page: 100
38-
});
39-
const labelNames = labels.data.map(label => label.name);
40-
return labelNames.join(', ');
41-
42-
- name: Set environment variables
43-
env:
44-
ISSUE_TITLE: ${{ github.event.issue.title }}
45-
ISSUE_BODY: ${{ github.event.issue.body }}
46-
LABELS_RESULT: ${{ steps.get-labels.outputs.result }}
47-
run: |
48-
{
49-
echo "AVAILABLE_LABELS=${LABELS_RESULT}"
50-
echo "ISSUE_TITLE=${ISSUE_TITLE}"
51-
echo "ISSUE_BODY<<EOF"
52-
echo "${ISSUE_BODY}"
53-
echo "EOF"
54-
} >> "$GITHUB_ENV"
55-
56-
- name: Analyze issue with AI
57-
id: ai-triage
58-
uses: actions/ai-inference@v1
59-
with:
60-
prompt: |
61-
## Role
62-
63-
You are an issue triage assistant. Analyze the current GitHub
64-
issue and identify the most appropriate existing labels. Use the
65-
available tools to gather information; do not ask for information
66-
to be provided.
67-
68-
## Guidelines
69-
70-
- Only use labels that are from the list of available labels.
71-
- You can choose multiple labels to apply.
72-
- When generating shell commands, you **MUST NOT** use command
73-
substitution with `$(...)`, `<(...)`, or `>(...)`. This is a
74-
security measure to prevent unintended command execution.
75-
76-
## Input Data
77-
78-
**Available Labels** (comma-separated):
79-
```
80-
${{ env.AVAILABLE_LABELS }}
81-
```
82-
83-
**Issue Title**:
84-
```
85-
${{ env.ISSUE_TITLE }}
86-
```
87-
88-
**Issue Body**:
89-
```
90-
${{ env.ISSUE_BODY }}
91-
```
92-
93-
## Steps
94-
95-
1. Review the issue title, issue body, and available labels
96-
provided above.
97-
98-
2. Based on the issue title and issue body, classify the issue
99-
and choose all appropriate labels from the list of available
100-
labels.
101-
102-
3. Return only the selected labels as a comma-separated list,
103-
with no additional text or explanation. For example:
104-
```
105-
label1, label2, label3
106-
```
107-
108-
- name: Apply labels
109-
if: steps.ai-triage.outputs.response != ''
110-
uses: actions/github-script@v7
111-
env:
112-
AI_RESPONSE: ${{ steps.ai-triage.outputs.response }}
113-
with:
114-
script: |
115-
const response = process.env.AI_RESPONSE;
116-
if (!response || response.trim() === '') {
117-
console.log('No labels selected by AI');
118-
return;
119-
}
120-
121-
const labels = response.split(',')
122-
.map(l => l.trim())
123-
.filter(l => l.length > 0);
124-
125-
if (labels.length > 0) {
126-
console.log(`Applying labels: ${labels.join(', ')}`);
127-
await github.rest.issues.addLabels({
128-
owner: context.repo.owner,
129-
repo: context.repo.repo,
130-
issue_number: context.issue.number,
131-
labels: labels
132-
});
133-
} else {
134-
console.log('No valid labels to apply');
135-
}
136-
137-
triage-unlabeled-issues:
138-
name: Triage Unlabeled Issues
139-
if: |
140-
github.event_name == 'workflow_dispatch' &&
141-
github.event.inputs.issue_number == ''
142-
runs-on: ubuntu-latest
143-
steps:
144-
- name: Find and dispatch triage for unlabeled issues
145-
uses: actions/github-script@v7
146-
with:
147-
script: |
148-
// Get all open issues
149-
const issues = await github.paginate(
150-
github.rest.issues.listForRepo,
151-
{
152-
owner: context.repo.owner,
153-
repo: context.repo.repo,
154-
state: 'open',
155-
per_page: 100
156-
}
157-
);
158-
159-
console.log(`Found ${issues.length} open issues`);
160-
161-
// Filter issues without labels
162-
const unlabeledIssues = issues.filter(issue =>
163-
!issue.pull_request && issue.labels.length === 0
164-
);
165-
166-
console.log(
167-
`Found ${unlabeledIssues.length} unlabeled issues`
168-
);
169-
170-
if (unlabeledIssues.length === 0) {
171-
console.log('No unlabeled issues to process');
172-
return;
173-
}
174-
175-
// Dispatch triage workflow for each unlabeled issue
176-
for (const issue of unlabeledIssues) {
177-
console.log(
178-
`Dispatching triage for issue #${issue.number}: ` +
179-
`"${issue.title}"`
180-
);
181-
182-
try {
183-
await github.rest.actions.createWorkflowDispatch({
184-
owner: context.repo.owner,
185-
repo: context.repo.repo,
186-
workflow_id: 'issue-triage.yml',
187-
ref: context.ref || 'main',
188-
inputs: {
189-
process_unlabeled: 'false',
190-
issue_number: issue.number.toString()
191-
}
192-
});
193-
} catch (error) {
194-
console.error(
195-
`Failed to dispatch triage for issue #${issue.number}: ` +
196-
`${error.message}`
197-
);
198-
}
199-
200-
// Add a small delay to avoid rate limiting
201-
await new Promise(resolve => setTimeout(resolve, 100));
202-
}
203-
204-
console.log('Finished dispatching triage workflows');
205-
206-
triage-single-issue:
207-
name: Triage Single Issue
208-
if: |
209-
github.event_name == 'workflow_dispatch' &&
210-
github.event.inputs.issue_number != ''
211-
runs-on: ubuntu-latest
212-
steps:
213-
- name: Get available labels
214-
id: get-labels
215-
uses: actions/github-script@v7
216-
with:
217-
script: |
218-
const labels = await github.rest.issues.listLabelsForRepo({
219-
owner: context.repo.owner,
220-
repo: context.repo.repo,
221-
per_page: 100
222-
});
223-
const labelNames = labels.data.map(label => label.name);
224-
return labelNames.join(', ');
225-
226-
- name: Get issue details
227-
id: get-issue
228-
uses: actions/github-script@v7
229-
with:
230-
script: |
231-
const issue = await github.rest.issues.get({
232-
owner: context.repo.owner,
233-
repo: context.repo.repo,
234-
issue_number: parseInt('${{ github.event.inputs.issue_number }}')
235-
});
236-
return {
237-
title: issue.data.title,
238-
body: issue.data.body || ''
239-
};
240-
241-
- name: Set environment variables
242-
env:
243-
ISSUE_TITLE: ${{ fromJSON(steps.get-issue.outputs.result).title }}
244-
ISSUE_BODY: ${{ fromJSON(steps.get-issue.outputs.result).body }}
245-
LABELS_RESULT: ${{ steps.get-labels.outputs.result }}
246-
run: |
247-
{
248-
echo "AVAILABLE_LABELS=${LABELS_RESULT}"
249-
echo "ISSUE_TITLE=${ISSUE_TITLE}"
250-
echo "ISSUE_BODY<<EOF"
251-
echo "${ISSUE_BODY}"
252-
echo "EOF"
253-
} >> "$GITHUB_ENV"
254-
255-
- name: Analyze issue with AI
256-
id: ai-triage
257-
uses: actions/ai-inference@v1
258-
with:
259-
prompt: |
260-
## Role
261-
262-
You are an issue triage assistant. Analyze the current GitHub
263-
issue and identify the most appropriate existing labels. Use the
264-
available tools to gather information; do not ask for information
265-
to be provided.
266-
267-
## Guidelines
268-
269-
- Only use labels that are from the list of available labels.
270-
- You can choose multiple labels to apply.
271-
- When generating shell commands, you **MUST NOT** use command
272-
substitution with `$(...)`, `<(...)`, or `>(...)`. This is a
273-
security measure to prevent unintended command execution.
274-
275-
## Input Data
276-
277-
**Available Labels** (comma-separated):
278-
```
279-
${{ env.AVAILABLE_LABELS }}
280-
```
281-
282-
**Issue Title**:
283-
```
284-
${{ env.ISSUE_TITLE }}
285-
```
286-
287-
**Issue Body**:
288-
```
289-
${{ env.ISSUE_BODY }}
290-
```
291-
292-
## Steps
293-
294-
1. Review the issue title, issue body, and available labels
295-
provided above.
296-
297-
2. Based on the issue title and issue body, classify the issue
298-
and choose all appropriate labels from the list of available
299-
labels.
300-
301-
3. Return only the selected labels as a comma-separated list,
302-
with no additional text or explanation. For example:
303-
```
304-
label1, label2, label3
305-
```
306-
307-
- name: Apply labels
308-
if: steps.ai-triage.outputs.response != ''
309-
uses: actions/github-script@v7
310-
env:
311-
AI_RESPONSE: ${{ steps.ai-triage.outputs.response }}
312-
ISSUE_NUMBER: ${{ github.event.inputs.issue_number }}
313-
with:
314-
script: |
315-
const response = process.env.AI_RESPONSE;
316-
const issueNumber = parseInt(process.env.ISSUE_NUMBER);
317-
318-
if (!response || response.trim() === '') {
319-
console.log('No labels selected by AI');
320-
return;
321-
}
322-
323-
const labels = response.split(',')
324-
.map(l => l.trim())
325-
.filter(l => l.length > 0);
326-
327-
if (labels.length > 0) {
328-
console.log(`Applying labels: ${labels.join(', ')}`);
329-
await github.rest.issues.addLabels({
330-
owner: context.repo.owner,
331-
repo: context.repo.repo,
332-
issue_number: issueNumber,
333-
labels: labels
334-
});
335-
} else {
336-
console.log('No valid labels to apply');
337-
}
20+
issue-triage:
21+
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main
22+
with:
23+
issue_number: ${{ inputs.issue_number }}

0 commit comments

Comments
 (0)