Skip to content

Grant pull-requests: write to branch freeze command workflow - #14495

Merged
AlesProkop merged 1 commit into
dotnet:mainfrom
AlesProkop:dev/alesprokop/branch-freeze-permissions-fix
Jul 23, 2026
Merged

AlesProkop merged 1 commit into
dotnet:mainfrom
AlesProkop:dev/alesprokop/branch-freeze-permissions-fix

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Context

Follow-up to #14470. The /freeze /unfreezecommand workflow only requestedissues: write, but it reacts to and replies on the *triggering comment*. When a command is issued from a **pull request** comment, GitHub requires pull-requests: writefor those operations, so the best-effort acknowledgement (👍 reaction + confirmation reply) failed withHTTP 403. The freeze/unfreeze state change itself always succeeded; only the acknowledgement on PR comments was affected. Confirmed live during rollout testing (a /freeze` from a PR comment applied the freeze and stamped the required status red, but posted no ack).

Changes Made

  • Added pull-requests: write to the command job permissions in branch-freeze-command.yml so reactions/replies succeed when the command originates from a PR comment. This also covers the deny-command step (same job).
  • Changed Add-Reaction in handle-command.ps1 to log a ::warning:: instead of silently swallowing a failed reaction, so any future permission gap is diagnosable.
  • Tightened the adjacent permissions comment (removed the now-inaccurate pull-requests: read note; statuses: write remains scoped to the refresh job).

Testing

  • Ran pwsh .github/branch-freeze/tests/run-tests.ps1: 73 passed, 0 failed.
  • Validated PowerShell parser over .github/branch-freeze/** (*.ps1/*.psm1): no errors.
  • Parsed branch-freeze-command.yml with powershell-yaml: valid; command-job permissions now {contents: read, issues: write, pull-requests: write}.

Notes

  • Behavior when commanded from a regular issue comment was already correct and is unchanged.
  • The deny-command path already logged reaction failures via Write-Warning and needs no change beyond the shared permission.

The /freeze and /unfreeze command workflow reacted to and replied on the triggering comment with only 'issues: write'. When a command is issued from a pull request comment, reacting/replying requires 'pull-requests: write', so those best-effort acknowledgements failed with HTTP 403 (the freeze/unfreeze itself still succeeded). Add 'pull-requests: write' to the command job, and log a warning instead of silently swallowing a failed reaction so future permission gaps are diagnosable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7eae7093-a91c-432d-9c5b-9720d1d5a2d4
Copilot AI review requested due to automatic review settings July 23, 2026 06:22
@AlesProkop
AlesProkop requested a review from a team as a code owner July 23, 2026 06:22
@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:22 — with GitHub Actions Inactive
@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:22 — with GitHub Actions Inactive
@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:23 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the branch-freeze slash-command workflow to ensure acknowledgements (reactions/replies) succeed when the triggering comment is on a pull request, and improves diagnosability when reactions fail.

Changes:

  • Granted pull-requests: write to the workflow’s default token permissions so the command job can react/reply on PR-originating comments without HTTP 403.
  • Updated Add-Reaction to emit a GitHub Actions ::warning:: when adding a reaction fails, instead of silently swallowing the failure.
  • Adjusted the permissions comment to reflect the new least-privilege breakdown (keeping statuses: write scoped to the refresh job).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/branch-freeze-command.yml Adds pull-requests: write to enable reactions/replies when /freeze is triggered from PR comments; clarifies permissions comment.
.github/branch-freeze/workflows/handle-command.ps1 Logs a workflow warning when reaction posting fails so permission gaps are visible in CI logs.

Comment thread .github/branch-freeze/workflows/handle-command.ps1
@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:26 — with GitHub Actions Inactive
@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:29 — with GitHub Actions Inactive

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

This is a straightforward GitHub Actions workflow fix. Both changes are correct and low-risk.

Permissions (pull-requests: write)

The issue_comment event fires for both issue and PR comments, but the issues: write permission only covers reactions/replies on issue comments. Adding pull-requests: write is the correct fix to allow the bot to react/reply when /freeze or /unfreeze is invoked from a PR comment. This follows least-privilege: the permission is scoped to this specific workflow with a concurrency guard.

Warning annotation

Replacing a silent return with Write-Host "::warning::..." is a good improvement—failures to add reactions are non-fatal but should be visible for debugging. The message is clear and includes the relevant context ($Content, $CommentId).

Minor observation

The catch block no longer contains return, so execution will continue after the warning. This is fine since Add-Reaction is a fire-and-forget helper and callers don't depend on its success, but worth confirming that no code after an Add-Reaction call assumes the reaction was actually posted.

No blocking issues found.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • awmgmcpg
  • patchdiff.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"
    - "patchdiff.githubusercontent.com"

See Network Configuration for more information.

Generated by Expert Code Review (on open) for #14495 · 36.7 AIC · ⌖ 5.05 AIC · ⊞ 5K

@AlesProkop
AlesProkop temporarily deployed to copilot-pat-pool July 23, 2026 06:29 — with GitHub Actions Inactive
@AlesProkop
AlesProkop merged commit 0567456 into dotnet:main Jul 23, 2026
20 checks passed
AlesProkop added a commit that referenced this pull request Aug 12, 2026
Reverts #14495 and #14470.

No other changes.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 42691a11-7401-40fe-b781-87654fed03fa

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 371caaf5 Deployed Jul 23, 2026 by AlesProkop via conclusion #532
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