Skip to content

Commit 4728d84

Browse files
authored
fix(safe-outputs): emit created_issue_* outputs from handler manager (#20130)
1 parent 1646db2 commit 4728d84

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

actions/setup/js/safe_output_handler_manager.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const { createReviewBuffer } = require("./pr_review_buffer.cjs");
2121
const { sanitizeContent } = require("./sanitize_content.cjs");
2222
const { createManifestLogger, ensureManifestExists, extractCreatedItemFromResult } = require("./safe_output_manifest.cjs");
2323
const { loadCustomSafeOutputJobTypes } = require("./safe_output_helpers.cjs");
24+
const { emitSafeOutputActionOutputs } = require("./safe_outputs_action_outputs.cjs");
2425

2526
/**
2627
* Handler map configuration
@@ -1017,6 +1018,10 @@ async function main() {
10171018
core.info(`Exported ${codePushFailureCount} code push failure(s)`);
10181019
}
10191020

1021+
// Emit named action outputs (e.g. created_issue_number, created_issue_url)
1022+
// for the first successful result of each safe output type.
1023+
emitSafeOutputActionOutputs(processingResult);
1024+
10201025
// Ensure the manifest file always exists for artifact upload (even if no items were created).
10211026
// Skip in staged mode — no real items were created so no manifest should be emitted.
10221027
// Note: createManifestLogger() also calls ensureManifestExists() when the logger is created,

actions/setup/js/safe_output_handler_manager.test.cjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,4 +973,45 @@ describe("Safe Output Handler Manager", () => {
973973
expect(result.codePushFailures).toHaveLength(0);
974974
});
975975
});
976+
977+
describe("output emission via emitSafeOutputActionOutputs", () => {
978+
it("processMessages result includes create_issue result with number and url for emission", async () => {
979+
const messages = [{ type: "create_issue", title: "My Issue" }];
980+
const mockHandler = vi.fn().mockResolvedValue({ number: 42, url: "https://github.com/owner/repo/issues/42" });
981+
const handlers = new Map([["create_issue", mockHandler]]);
982+
983+
const result = await processMessages(handlers, messages);
984+
985+
const issueResult = result.results.find(r => r.type === "create_issue" && r.success);
986+
expect(issueResult).toBeDefined();
987+
expect(issueResult.result.number).toBe(42);
988+
expect(issueResult.result.url).toBe("https://github.com/owner/repo/issues/42");
989+
});
990+
991+
it("processMessages result with failed create_issue does not include success result for emission", async () => {
992+
const messages = [{ type: "create_issue", title: "Failing Issue" }];
993+
const mockHandler = vi.fn().mockRejectedValue(new Error("API error"));
994+
const handlers = new Map([["create_issue", mockHandler]]);
995+
996+
const result = await processMessages(handlers, messages);
997+
998+
const successfulIssueResult = result.results.find(r => r.type === "create_issue" && r.success);
999+
expect(successfulIssueResult).toBeUndefined();
1000+
});
1001+
1002+
it("core.setOutput is called with created_issue_number when create_issue succeeds", async () => {
1003+
const messages = [{ type: "create_issue", title: "My Issue" }];
1004+
const mockHandler = vi.fn().mockResolvedValue({ number: 7, url: "https://github.com/owner/repo/issues/7" });
1005+
const handlers = new Map([["create_issue", mockHandler]]);
1006+
1007+
const result = await processMessages(handlers, messages);
1008+
1009+
// Simulate what main() does: call emitSafeOutputActionOutputs with the result
1010+
const { emitSafeOutputActionOutputs } = await import("./safe_outputs_action_outputs.cjs");
1011+
emitSafeOutputActionOutputs(result);
1012+
1013+
expect(global.core.setOutput).toHaveBeenCalledWith("created_issue_number", "7");
1014+
expect(global.core.setOutput).toHaveBeenCalledWith("created_issue_url", "https://github.com/owner/repo/issues/7");
1015+
});
1016+
});
9761017
});

0 commit comments

Comments
 (0)