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
9 changes: 5 additions & 4 deletions actions/setup/js/update_pr_description_helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function updateBody(params) {
// When footer is enabled use the full footer (includes install instructions, XML marker, etc.)
// When footer is disabled still add standalone workflow-id marker for searchability
const aiFooter = includeFooter ? buildAIFooter(workflowName, runUrl, historyUrl) : "";
const footerSection = aiFooter ? `\n\n${aiFooter}` : "";
const workflowIdMarker = !includeFooter && workflowId ? `\n\n${generateWorkflowIdMarker(workflowId)}` : "";

// Sanitize new content to prevent injection attacks
Expand All @@ -115,15 +116,15 @@ function updateBody(params) {
if (operation === "replace") {
// Replace: use new content with optional AI footer
core.info("Operation: replace (full body replacement)");
return contentWithCaution + aiFooter + workflowIdMarker;
return contentWithCaution + footerSection + workflowIdMarker;
}

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}`;
const islandContent = `${startMarker}\n${contentWithCaution}${footerSection}${workflowIdMarker}\n${endMarker}`;

if (island.found) {
// Replace the island content
Expand All @@ -141,13 +142,13 @@ function updateBody(params) {
if (operation === "prepend") {
// Prepend: add content, AI footer (if enabled), and horizontal line at the start
core.info("Operation: prepend (add to start with separator)");
const prependSection = `${contentWithCaution}${aiFooter}${workflowIdMarker}\n\n---\n\n`;
const prependSection = `${contentWithCaution}${footerSection}${workflowIdMarker}\n\n---\n\n`;
return prependSection + currentBody;
}

// Default to append
core.info("Operation: append (add to end with separator)");
const appendSection = `\n\n---\n\n${contentWithCaution}${aiFooter}${workflowIdMarker}`;
const appendSection = `\n\n---\n\n${contentWithCaution}${footerSection}${workflowIdMarker}`;
return currentBody + appendSection;
}

Expand Down
56 changes: 56 additions & 0 deletions actions/setup/js/update_pr_description_helpers.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ describe("update_pr_description_helpers.cjs", () => {
expect(result).toContain("https://github.com/test/actions/runs/123");
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("replace"));
});

it("separates replacement content from the generated footer with a blank line", () => {
const result = updateBody({
currentBody: "Old content",
newContent: "run: https://github.com/owner/repo/actions/runs/123",
operation: "replace",
workflowName: "Test",
runUrl: "https://github.com/test/actions/runs/123",
workflowId: "test-workflow",
});

expect(result).toContain("run: https://github.com/owner/repo/actions/runs/123\n\n> Generated by [Test]");
expect(result).not.toContain("runs/123> Generated by [Test]");
});
});

describe("updateBody - append operation", () => {
Expand Down Expand Up @@ -212,6 +226,20 @@ describe("update_pr_description_helpers.cjs", () => {
expect(result.indexOf("Original content")).toBeLessThan(result.indexOf("New content"));
});

it("separates appended content from the generated footer with a blank line", () => {
const result = updateBody({
currentBody: "Original content",
newContent: "run: https://github.com/owner/repo/actions/runs/123",
operation: "append",
workflowName: "Test",
runUrl: "https://github.com/test/actions/runs/123",
workflowId: "test-workflow",
});

expect(result).toContain("run: https://github.com/owner/repo/actions/runs/123\n\n> Generated by [Test]");
expect(result).not.toContain("runs/123> Generated by [Test]");
});

it("should preserve markdown formatting", () => {
const result = updateBody({
currentBody: "# Title\n\n**Bold**",
Expand Down Expand Up @@ -258,6 +286,20 @@ describe("update_pr_description_helpers.cjs", () => {
expect(result).toContain("New content");
expect(result.indexOf("New content")).toBeLessThan(result.indexOf("Original content"));
});

it("separates prepended content from the generated footer with a blank line", () => {
const result = updateBody({
currentBody: "Original content",
newContent: "run: https://github.com/owner/repo/actions/runs/123",
operation: "prepend",
workflowName: "Test",
runUrl: "https://github.com/test/actions/runs/123",
workflowId: "test-workflow",
});

expect(result).toContain("run: https://github.com/owner/repo/actions/runs/123\n\n> Generated by [Test]");
expect(result).not.toContain("runs/123> Generated by [Test]");
});
});

describe("updateBody - replace-island operation", () => {
Expand Down Expand Up @@ -299,6 +341,20 @@ describe("update_pr_description_helpers.cjs", () => {
expect(mockCore.info).toHaveBeenCalledWith(expect.stringContaining("updating existing island"));
});

it("separates island content from the generated footer with a blank line", () => {
const result = updateBody({
currentBody: "Original content",
newContent: "run: https://github.com/owner/repo/actions/runs/123",
operation: "replace-island",
workflowName: "Test",
runUrl: "https://github.com/test/actions/runs/123",
workflowId: "test-workflow",
});

expect(result).toContain("run: https://github.com/owner/repo/actions/runs/123\n\n> Generated by [Test]");
expect(result).not.toContain("runs/123> Generated by [Test]");
});

it("should preserve content outside island when replacing", () => {
const currentBody = "# Title\n\nSome intro\n\n<!-- gh-aw-island-start:test-workflow -->\nOld\n<!-- gh-aw-island-end:test-workflow -->\n\n## Footer\n\nMore content";
const result = updateBody({
Expand Down
Loading