Skip to content

Enable add-comment for non-commentable events via PR resolution#2336

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/update-safe-outputs-add-comment
Closed

Enable add-comment for non-commentable events via PR resolution#2336
Copilot wants to merge 5 commits intomainfrom
copilot/update-safe-outputs-add-comment

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

The safe-outputs.add-comment feature only worked for workflows triggered by commentable events (issues, PRs, discussions). Workflows triggered by workflow_dispatch, push, or schedule would skip comment creation even when a relevant PR existed.

Changes

JavaScript Implementation (add_comment.cjs)

  • Added resolveCurrentBranch() to extract branch from GITHUB_REF/GITHUB_HEAD_REF
  • Added findOpenPullRequestForBranch() to search for open PRs via GitHub API
  • Updated main logic: when triggered by non-commentable events, resolves branch → finds matching PR → comments if found → exits gracefully if not
  • Supports target-repo slug for cross-repository scenarios

Go Compiler (add_comment.go)

  • Removed job condition requiring github.event.issue.number || github.event.pull_request.number || github.event.discussion.number
  • Job now runs whenever add_comment output exists; JavaScript handles target resolution

Behavior

Before:

on: workflow_dispatch
safe-outputs:
  add-comment:  # Would skip with "not in commentable context"

After:

on: workflow_dispatch
safe-outputs:
  add-comment:  # Finds PR for current branch and comments

For workflow_dispatch on branch feature-x with open PR #123:

  1. Resolves feature-x from GITHUB_REF
  2. Searches for PRs with head: "owner:feature-x"
  3. Comments on PR Network Permissions Testing Report - MCP Fetch Tool Analysis #123
  4. If no PR found, exits gracefully with log message (no error)

Existing behavior for issue/PR/discussion triggers unchanged.

Test Coverage

  • 8 new test cases covering PR resolution, branch resolution, graceful exits, error handling, and target-repo support
  • All 23 add_comment tests pass
  • All 591 JavaScript tests pass
Original prompt

Update the safe-outputs add-comment JavaScript to handle workflows triggered by non-commentable events (e.g., workflow-dispatch, workflow run). When the activation is not from an issue, discussion, or pull-request:

  • Resolve the current branch for the run (e.g., from GITHUB_REF/GITHUB_HEAD_REF or equivalent in the engine).
  • Find the first open pull-request whose head branch matches this branch (targeting the same target-repo if applicable).
  • If such a pull-request exists, use that pull-request as the comment target and proceed with add-comment.
  • If no matching open pull-request is found, do not fail; log a clear message in logs and exit gracefully without commenting.

Notes:

  • Preserve existing behavior for issue, discussion, pull-request, and pull-request-comment triggers.
  • Ensure safe-outputs handling remains intact and sanitized.
  • Respect permissions and github-token scopes.
  • Provide verbose logs when verbose is enabled.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits October 24, 2025 23:00
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update safe-outputs add-comment for non-commentable events Enable add-comment for non-commentable events via PR resolution Oct 24, 2025
Copilot AI requested a review from pelikhan October 24, 2025 23:16
@pelikhan
Copy link
Contributor

@copilot this mode must be enabled by a field on the configuration `

@pelikhan pelikhan closed this Oct 24, 2025
@pelikhan pelikhan deleted the copilot/update-safe-outputs-add-comment branch October 26, 2025 20:41
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.

2 participants