Skip to content

Commit a9de5fd

Browse files
Add workflow_dispatch trigger to triage feedback workflow (#1017)
* Add workflow_dispatch trigger to collect-corrections workflow The triage feedback slash command is a preview feature only available in private repos. Add a workflow_dispatch trigger with issue_number and feedback inputs so the workflow can be dispatched manually from the Actions UI. - Add workflow_dispatch trigger with required inputs to collect-corrections.yml - Fall back to context.payload.inputs when client_payload is absent - Add integration test for the workflow_dispatch payload path * Rename collect-corrections workflow to Submit triage agent feedback * Validate issue_number is a finite positive integer in resolveContext
1 parent 7897a0c commit a9de5fd

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

.github/workflows/collect-corrections.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
name: Collect triage agent corrections
1+
name: Submit triage agent feedback
22

33
on:
44
repository_dispatch:
55
types: [triage_feedback]
6+
workflow_dispatch:
7+
inputs:
8+
issue_number:
9+
description: "Issue number to submit feedback for"
10+
required: true
11+
type: string
12+
feedback:
13+
description: "Feedback text describing what the triage agent got wrong"
14+
required: true
15+
type: string
616

717
concurrency:
818
group: collect-corrections

scripts/corrections/collect-corrections.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ function resolveContext(payload, sender) {
8282
throw new Error("Missing feedback in payload");
8383
}
8484

85-
return { issueNumber: Number(issueNumber), feedback, sender };
85+
const parsed = Number(issueNumber);
86+
if (!Number.isFinite(parsed) || parsed < 1 || !Number.isInteger(parsed)) {
87+
throw new Error(`Invalid issue_number: ${issueNumber}`);
88+
}
89+
90+
return { issueNumber: parsed, feedback, sender };
8691
}
8792

8893
/**
@@ -203,7 +208,7 @@ async function maybeAssignCCA(github, owner, repo, trackingIssue, correctionCoun
203208
*/
204209
module.exports = async ({ github, context }) => {
205210
const { owner, repo } = context.repo;
206-
const payload = context.payload.client_payload ?? {};
211+
const payload = context.payload.client_payload ?? context.payload.inputs ?? {};
207212
const sender = context.payload.sender?.login ?? "unknown";
208213

209214
const correction = resolveContext(payload, sender);

scripts/corrections/test/collect-corrections.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi } from "vitest";
1+
import { describe, expect, it, vi } from "vitest";
22

33
const mod = await import("../collect-corrections.js");
44
const {
@@ -134,6 +134,24 @@ describe("resolveContext", () => {
134134
resolveContext({ issue_number: "1" }, "u"),
135135
).toThrow("Missing feedback");
136136
});
137+
138+
it("throws on non-numeric issue number", () => {
139+
expect(() =>
140+
resolveContext({ issue_number: "abc", feedback: "test" }, "u"),
141+
).toThrow("Invalid issue_number: abc");
142+
});
143+
144+
it("throws on negative issue number", () => {
145+
expect(() =>
146+
resolveContext({ issue_number: "-1", feedback: "test" }, "u"),
147+
).toThrow("Invalid issue_number: -1");
148+
});
149+
150+
it("throws on decimal issue number", () => {
151+
expect(() =>
152+
resolveContext({ issue_number: "1.5", feedback: "test" }, "u"),
153+
).toThrow("Invalid issue_number: 1.5");
154+
});
137155
});
138156

139157
// ---------------------------------------------------------------------------
@@ -304,6 +322,42 @@ describe("appendCorrection", () => {
304322
});
305323
});
306324

325+
describe("module entrypoint - workflow_dispatch", () => {
326+
it("processes feedback from workflow_dispatch inputs", async () => {
327+
const github = mockGitHub({
328+
listForRepo: vi.fn().mockResolvedValue({
329+
data: [{ number: 50, assignees: [], body: trackingBodyForEntrypoint }],
330+
}),
331+
});
332+
const context = {
333+
repo: { owner: OWNER, repo: REPO },
334+
payload: {
335+
// workflow_dispatch has no client_payload; inputs carry the data
336+
inputs: { issue_number: "7", feedback: "Should be enhancement" },
337+
sender: { login: "dispatcher" },
338+
},
339+
};
340+
341+
await mod.default({ github, context });
342+
343+
// Verify the correction was appended referencing the right issue
344+
expect(github.rest.issues.update).toHaveBeenCalledWith(
345+
expect.objectContaining({
346+
issue_number: 50,
347+
body: expect.stringContaining("[#7]"),
348+
}),
349+
);
350+
});
351+
});
352+
353+
const trackingBodyForEntrypoint = [
354+
"# Triage Agent Corrections",
355+
"",
356+
"| Issue | Feedback | Submitted by | Date |",
357+
"|-------|----------|--------------|------|",
358+
"",
359+
].join("\n");
360+
307361
describe("maybeAssignCCA", () => {
308362
it("assigns CCA when threshold is reached", async () => {
309363
const github = mockGitHub();

0 commit comments

Comments
 (0)