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
2 changes: 1 addition & 1 deletion actions/setup/js/add_comment.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ async function main(config = {}) {

if (includeFooter) {
// When footer is enabled, add full footer with attribution and XML markers
processedBody += generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringIssueNumber, triggeringPRNumber, triggeringDiscussionNumber, historyUrl).trimEnd();
processedBody += "\n\n" + generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringIssueNumber, triggeringPRNumber, triggeringDiscussionNumber, historyUrl).trimEnd();
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateFooterWithMessages(...) already starts with "\n\n" when there are no guard notices (i.e., the common non-warning case). Prepending another "\n\n" here changes the rendered output to include two blank paragraphs ("\n\n\n\n") before the normal attribution footer, which is a behavior change unrelated to the caution/admonition fix. Consider building the footer string first and only inserting an extra separator when the footer/guard content does not already begin on a new-paragraph boundary (e.g., when detection caution is present and the footer starts with "> [!CAUTION]").

Suggested change
processedBody += "\n\n" + generateFooterWithMessages(workflowName, runUrl, workflowSource, workflowSourceURL, triggeringIssueNumber, triggeringPRNumber, triggeringDiscussionNumber, historyUrl).trimEnd();
const footerWithMessages = generateFooterWithMessages(
workflowName,
runUrl,
workflowSource,
workflowSourceURL,
triggeringIssueNumber,
triggeringPRNumber,
triggeringDiscussionNumber,
historyUrl,
).trimEnd();
processedBody += footerWithMessages.startsWith("\n\n") || footerWithMessages.startsWith("\r\n\r\n")
? footerWithMessages
: "\n\n" + footerWithMessages;

Copilot uses AI. Check for mistakes.
} else {
// When footer is disabled, only add XML marker for searchability (no visible attribution text)
processedBody += "\n\n" + generateXMLMarker(workflowName, runUrl);
Expand Down
38 changes: 38 additions & 0 deletions actions/setup/js/add_comment.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,44 @@ describe("add_comment", () => {
delete process.env.GH_AW_WORKFLOW_NAME;
});

it("should add a blank line before injected security scanning caution footer", async () => {
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");

process.env.GH_AW_WORKFLOW_NAME = "Security Test Workflow";
process.env.GH_AW_DETECTION_CONCLUSION = "warning";
process.env.GH_AW_DETECTION_REASON = "threat_detected";

let capturedBody = null;
mockGithub.rest.issues.createComment = async params => {
capturedBody = params.body;
return {
data: {
id: 12345,
html_url: "https://github.com/owner/repo/issues/42#issuecomment-12345",
},
};
};

const handler = await eval(`(async () => { ${addCommentScript}; return await main({}); })()`);

const message = {
type: "add_comment",
body: "Comment body for warning case",
};

const result = await handler(message, {});

expect(result.success).toBe(true);
expect(capturedBody).toContain("Comment body for warning case\n\n> [!CAUTION]");
expect(capturedBody).toContain("**Security scanning requires review**");
expect(capturedBody).toContain("> Generated by [Security Test Workflow]");
expect(capturedBody).toMatch(/> \[!CAUTION\][\s\S]*\n\n> Generated by \[Security Test Workflow\]/);

delete process.env.GH_AW_WORKFLOW_NAME;
delete process.env.GH_AW_DETECTION_CONCLUSION;
delete process.env.GH_AW_DETECTION_REASON;
});

it("should sanitize user content but preserve system markers", async () => {
const addCommentScript = fs.readFileSync(path.join(__dirname, "add_comment.cjs"), "utf8");

Expand Down
Loading