diff --git a/actions/setup/js/update_pr_description_helpers.cjs b/actions/setup/js/update_pr_description_helpers.cjs index da13bdf042f..49e632bdcec 100644 --- a/actions/setup/js/update_pr_description_helpers.cjs +++ b/actions/setup/js/update_pr_description_helpers.cjs @@ -109,25 +109,20 @@ function updateBody(params) { if (operation === "replace-island") { // Try to find existing island for this workflow ID const island = findIsland(currentBody, workflowId); + const startMarker = buildIslandStartMarker(workflowId); + const endMarker = buildIslandEndMarker(workflowId); + const islandContent = `${startMarker}\n${contentWithCaution}${aiFooter}${workflowIdMarker}\n${endMarker}`; if (island.found) { // Replace the island content core.info(`Operation: replace-island (updating existing island for workflow ${workflowId})`); - const startMarker = buildIslandStartMarker(workflowId); - const endMarker = buildIslandEndMarker(workflowId); - const islandContent = `${startMarker}\n${contentWithCaution}${aiFooter}${workflowIdMarker}\n${endMarker}`; - const before = currentBody.substring(0, island.startIndex); const after = currentBody.substring(island.endIndex); return before + islandContent + after; } else { // Island not found, fall back to append mode core.info(`Operation: replace-island (island not found for workflow ${workflowId}, falling back to append)`); - const startMarker = buildIslandStartMarker(workflowId); - const endMarker = buildIslandEndMarker(workflowId); - const islandContent = `${startMarker}\n${contentWithCaution}${aiFooter}${workflowIdMarker}\n${endMarker}`; - const appendSection = `\n\n---\n\n${islandContent}`; - return currentBody + appendSection; + return currentBody + `\n\n---\n\n${islandContent}`; } } diff --git a/actions/setup/js/update_pr_description_helpers.test.cjs b/actions/setup/js/update_pr_description_helpers.test.cjs index 0a2e9c41c57..d29b8644a41 100644 --- a/actions/setup/js/update_pr_description_helpers.test.cjs +++ b/actions/setup/js/update_pr_description_helpers.test.cjs @@ -496,4 +496,62 @@ describe("update_pr_description_helpers.cjs", () => { expect(result).toContain(""); }); }); + + describe("historyUrl parameter", () => { + it("should pass historyUrl to the footer when provided", () => { + const result = updateBody({ + currentBody: "Original", + newContent: "New content", + operation: "append", + workflowName: "Test", + runUrl: "https://github.com/test/actions/runs/123", + workflowId: "test-workflow", + historyUrl: "https://github.com/search?q=test", + }); + expect(result).toContain("New content"); + // historyUrl should be included in the footer + expect(result).toContain("https://github.com/search?q=test"); + }); + + it("should work without historyUrl (optional parameter)", () => { + const result = updateBody({ + currentBody: "Original", + newContent: "New content", + operation: "append", + workflowName: "Test", + runUrl: "https://github.com/test/actions/runs/123", + workflowId: "test-workflow", + }); + expect(result).toContain("New content"); + expect(result).toContain("Original"); + }); + }); + + describe("workflowIdMarker - includeFooter false", () => { + it("should include workflow ID marker when includeFooter is false and workflowId is provided", () => { + const result = updateBody({ + currentBody: "Original", + newContent: "New content", + operation: "append", + workflowName: "Test", + runUrl: "https://github.com/test/actions/runs/123", + workflowId: "my-workflow", + includeFooter: false, + }); + expect(result).toContain(""); + }); + + it("should not include workflow ID marker when includeFooter is false and workflowId is empty", () => { + const result = updateBody({ + currentBody: "Original", + newContent: "New content", + operation: "append", + workflowName: "Test", + runUrl: "https://github.com/test/actions/runs/123", + workflowId: "", + includeFooter: false, + }); + expect(result).not.toContain("gh-aw-workflow-id"); + }); + }); });