Skip to content

feat: place threat detection CAUTION alert at top of PR body and add agentic-threat-detected label#28429

Merged
pelikhan merged 4 commits intomainfrom
copilot/change-rendering-order-pr-body
Apr 25, 2026
Merged

feat: place threat detection CAUTION alert at top of PR body and add agentic-threat-detected label#28429
pelikhan merged 4 commits intomainfrom
copilot/change-rendering-order-pr-body

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

Summary

Changes the rendering order of the pull request body so that the threat detection warning/caution alert appears at the top of the body (immediately visible to reviewers) rather than just before the footer. Also adds an agentic-threat-detected label to the PR when threat detection produces a warning.

Changes

actions/setup/js/messages_footer.cjs

  • Merged duplicate JSDoc blocks into a single JSDoc comment (with @param {GenerateFooterOptions} [options] and @returns {string}) immediately preceding generateFooterWithMessages
  • Added GenerateFooterOptions typedef with a skipDetectionCaution property
  • Added optional options parameter to generateFooterWithMessages
  • When skipDetectionCaution: true is passed, the caution alert is omitted from the footer (avoids duplication when the caller has already placed it at the top of the body)

actions/setup/js/create_pull_request.cjs

  • Imports getDetectionCautionAlert from messages_footer.cjs
  • After workflowName/runUrl are resolved, gets the detection caution alert
  • If threat is detected, prepends the caution alert to the very top of bodyLines (before any agent-generated content) with two blank separator lines for proper visual spacing
  • Adds agentic-threat-detected label to the PR's label list when a threat warning is present
  • Passes { skipDetectionCaution: true } to generateFooterWithMessages to prevent the alert from being duplicated in the footer

actions/setup/js/create_pull_request.test.cjs

  • Added a new create_pull_request - threat detection caution describe block with 5 tests:
    • Caution alert is prepended before agent body content when GH_AW_DETECTION_CONCLUSION=warning
    • No caution alert in PR body when conclusion is not warning
    • agentic-threat-detected label is included in addLabels call when warning
    • agentic-threat-detected label is absent when conclusion is not warning
    • At least two blank lines separate the caution block from body content

Before / After

Before (threat detected):

### Agent-generated title

Main body content...

> [!CAUTION]
> **Security scanning requires review**

> Generated by [Workflow](...)

After (threat detected):

> [!CAUTION]
> **Security scanning requires review**


### Agent-generated title

Main body content...

> Generated by [Workflow](...)

Labels on PR now include: agentic-threat-detected

Testing

  • All 71 JavaScript tests pass (5 new threat-detection tests added)
  • TypeScript type checks clean
  • make fmt passes

Copilot AI and others added 2 commits April 25, 2026 11:02
…agentic-threat-detected label

- Prepend the threat detection caution alert to the very top of the PR body
  in `create_pull_request.cjs` so it is immediately visible to reviewers
- Add `agentic-threat-detected` label to the PR when threat detection
  produces a warning
- Add `skipDetectionCaution` option to `generateFooterWithMessages` in
  `messages_footer.cjs` to avoid duplicating the caution alert in the footer
  when it has already been placed at the top of the body
- Import `getDetectionCautionAlert` in `create_pull_request.cjs`
- All 7045 JS tests pass, TypeScript checks clean

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d90da164-04bf-4b03-8ae9-c721d2b3e1b7

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot ensure extra new lines when caution inserted

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 25, 2026

@copilot ensure extra new lines when caution inserted

Fixed in 39f92b3 — changed unshift(detectionCaution, "") to unshift(detectionCaution, "", "") so two blank lines separate the caution alert from the main body content.

@pelikhan pelikhan marked this pull request as ready for review April 25, 2026 11:15
Copilot AI review requested due to automatic review settings April 25, 2026 11:15
@github-actions github-actions Bot mentioned this pull request Apr 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PR body rendering so threat-detection CAUTION alerts are immediately visible at the top of the PR description, and tags PRs with a dedicated label when a threat warning is present.

Changes:

  • Add an options parameter to generateFooterWithMessages to allow omitting the detection caution from the footer.
  • Prepend the threat-detection CAUTION block to the top of newly created PR bodies when detection concludes “warning”.
  • Add agentic-threat-detected to the PR label list when a threat warning is present.
Show a summary per file
File Description
actions/setup/js/messages_footer.cjs Adds skipDetectionCaution option to prevent duplicating the detection CAUTION in the footer.
actions/setup/js/create_pull_request.cjs Prepends detection CAUTION to the top of PR body and appends an agentic-threat-detected label on warning.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

actions/setup/js/messages_footer.cjs:422

  • skipDetectionCaution adds new behavior (omitting the detection caution from the footer), but there doesn’t appear to be any test coverage exercising the new options parameter. Please add a unit test (e.g., in actions/setup/js/messages.test.cjs) that sets GH_AW_DETECTION_CONCLUSION=warning and asserts the caution is present by default and absent when { skipDetectionCaution: true } is passed.
  const { skipDetectionCaution = false } = options || {};

  // Collect guard notices to show BEFORE the attribution footer
  let guardNotices = "";

actions/setup/js/create_pull_request.cjs:930

  • bodyLines.unshift(detectionCaution, "", "") results in two blank lines between the caution block and the rest of the body (because the caution string is followed by three consecutive \n when joined). If the intent is a single blank separator line (as described), consider unshifting only one empty string (or update the comment/PR description to reflect the extra spacing).
      // unshift(caution, "", "") places the caution alert at index 0 and two blank
      // separator lines so the main body content follows after a full empty line.
      bodyLines.unshift(detectionCaution, "", "");
    }
  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment thread actions/setup/js/messages_footer.cjs Outdated
Comment on lines 370 to 372
* @param {string|null|undefined} [historyUrl] - GitHub search URL for items created by this workflow
* @returns {string} Complete footer text
*/
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

There are now two JSDoc blocks describing generateFooterWithMessages back-to-back (one ending at @returns here, then another starting below). The first block is effectively orphaned/duplicative after inserting the typedef and can confuse tooling/ts-check—please remove it or merge into a single JSDoc immediately preceding the function.

This issue also appears on line 418 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +922 to +926
// Prepend threat detection caution alert at the very top of the PR body so it is
// immediately visible to reviewers. The caution is omitted from the footer to
// avoid duplication (skipDetectionCaution is passed to generateFooterWithMessages).
const detectionCaution = getDetectionCautionAlert(workflowName, runUrl);
if (detectionCaution) {
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

The new behavior of prepending the threat-detection caution to the top of the PR body isn’t covered by tests in create_pull_request.test.cjs (no scenarios set GH_AW_DETECTION_CONCLUSION=warning and assert body ordering). Please add a test that verifies the caution appears at the very beginning of the generated PR body when detection is warning, and that it is absent when detection is not warning.

This issue also appears on line 927 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +991 to +994
// Add agentic-threat-detected label when threat detection produced a warning
if (detectionCaution && !labels.includes("agentic-threat-detected")) {
labels.push("agentic-threat-detected");
}
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

Adding the agentic-threat-detected label based on threat-detection warnings is new behavior, but there’s no test coverage in create_pull_request.test.cjs asserting the label set includes it when GH_AW_DETECTION_CONCLUSION=warning (and does not include it otherwise). Please add/extend a test to validate the labels passed to issues.addLabels in both cases.

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot Review all tests

…essages_footer

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/f36dc55f-6578-4446-b624-09990dcd9eca

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 25, 2026

@copilot Review all tests

Done in 2000285. Added 5 new tests in a create_pull_request - threat detection caution describe block covering:

  • Caution alert prepended to top of PR body when GH_AW_DETECTION_CONCLUSION=warning
  • No caution alert when conclusion is not warning
  • agentic-threat-detected label added when warning
  • agentic-threat-detected label absent when not warning
  • At least 2 blank lines separating the caution block from body content

Also fixed the duplicate JSDoc block in messages_footer.cjs (merged the two back-to-back JSDoc comments into a single block with the @returns tag).

@pelikhan pelikhan merged commit d57a99d into main Apr 25, 2026
@pelikhan pelikhan deleted the copilot/change-rendering-order-pr-body branch April 25, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants