Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/triage-context.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const report = {
url: event.issue.html_url,
labels: labelsFor(event.issue),
user: event.issue.user?.login,
isPullRequest: Boolean(event.issue.pull_request),
}
: null,
...(isPullRequestEvent && {
Expand Down
40 changes: 40 additions & 0 deletions scripts/triage-context.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ test("keeps issue context behavior and filters PR-shaped issues from openIssues"
url: "https://github.com/perfect-panel/frontend/issues/7",
labels: ["bug"],
user: "alice",
isPullRequest: false,
});
assert.deepEqual(report.openIssues, [
{
Expand All @@ -144,6 +145,45 @@ test("keeps issue context behavior and filters PR-shaped issues from openIssues"
}
});

test("marks issue comments attached to pull requests for PR routing", async () => {
const event = {
action: "created",
issue: {
number: 42,
title: "Improve billing",
body: "PR body",
html_url: "https://github.com/perfect-panel/frontend/pull/42",
labels: [],
user: { login: "carol" },
pull_request: {},
},
};
const fixture = await withGithubFixture({
"/repos/perfect-panel/frontend/issues?state=open&per_page=50": [],
});
const { workspace, eventPath } = makeWorkspace(event);

try {
const result = await runContext({
cwd: workspace,
env: {
TRIAGE_TOKEN: "token",
GITHUB_API_BASE_URL: fixture.baseUrl,
GITHUB_EVENT_NAME: "issue_comment",
GITHUB_EVENT_PATH: eventPath,
GITHUB_REPOSITORY: "perfect-panel/frontend",
},
});
assert.equal(result.code, 0, result.stderr);
const report = JSON.parse(
readFileSync(join(workspace, ".automation", "context.json"), "utf8")
);
assert.equal(report.trigger.issue.isPullRequest, true);
} finally {
await fixture.close();
}
});

test("builds pull_request_target context with trigger PR and open PR list from injectable GitHub API base", async () => {
const event = {
action: "synchronize",
Expand Down
10 changes: 7 additions & 3 deletions scripts/triage-webhook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ if (!(webhookUrl && webhookSecret)) {

const context = JSON.parse(readFileSync(".automation/context.json", "utf8"));
const githubEventName = process.env.GITHUB_EVENT_NAME || "unknown";
const isPullRequest = githubEventName === "pull_request_target";
const isPullRequest =
githubEventName === "pull_request_target" ||
context.trigger?.issue?.isPullRequest === true;
const explicitEventType = process.env.AUTOMATION_EVENT_TYPE;
const eventType =
explicitEventType || (isPullRequest ? "triage.pull_request" : "triage.issue");
const dryRun = process.env.AUTOMATION_DRY_RUN === "true";
const payloadContext = dryRun ? { ...context, test: true } : context;

const payload = {
eventType,
dryRun: process.env.AUTOMATION_DRY_RUN === "true",
dryRun,
repo: "perfect-panel/frontend",
source: "github-actions",
trigger: {
kind: isPullRequest ? "pull_request" : githubEventName === "push" ? "push" : "issue",
eventName: githubEventName,
eventAction: process.env.GITHUB_EVENT_ACTION || "",
},
context,
context: payloadContext,
};

const rawBody = JSON.stringify(payload);
Expand Down
26 changes: 26 additions & 0 deletions scripts/triage-webhook.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ test("sends pull_request_target events as triage.pull_request", async () => {
}
});

test("routes issue comments attached to pull requests as triage.pull_request", async () => {
const server = await withServer((_record, response) => {
response.writeHead(202);
response.end("accepted");
});

try {
const result = await runSender({
cwd: makeWorkspace({ trigger: { issue: { isPullRequest: true } } }),
env: {
AUTOMATION_WEBHOOK_URL: server.url,
AUTOMATION_WEBHOOK_SECRET: "test-secret",
GITHUB_EVENT_NAME: "issue_comment",
GITHUB_EVENT_ACTION: "created",
},
});
assert.equal(result.code, 0, result.stderr);
const payload = JSON.parse(server.requests[0].body);
assert.equal(payload.eventType, "triage.pull_request");
assert.equal(payload.trigger.kind, "pull_request");
} finally {
await server.close();
}
});

test("supports explicit automation event type override for openapi adaptation without changing GitHub headers", async () => {
const secret = "test-secret";
const server = await withServer((_record, response) => {
Expand All @@ -159,6 +184,7 @@ test("supports explicit automation event type override for openapi adaptation wi
const payload = JSON.parse(body);
assert.equal(payload.eventType, "openapi.adapt");
assert.equal(payload.dryRun, true);
assert.equal(payload.context.test, true);
assert.equal(payload.repo, "perfect-panel/frontend");
assert.equal(payload.trigger.kind, "push");
assert.equal(payload.trigger.eventName, "push");
Expand Down
Loading