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
60 changes: 59 additions & 1 deletion .github/workflows/copilot-review-tests.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions .github/workflows/copilot-review-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
pull_request_review_comment: [contributor, first_time_contributor, first_timer, mannequin, none]
reaction: none
status-comment: false
# Grant the pre-activation job (the on.steps below) issues:write so it can hide (minimize
# as resolved) the triggering `/review tests` comment once the command is recognized and
# authorized. Minimizing requires the same issues:write scope that deletion did.
permissions:
issues: write
steps:
- name: Confirm exact /review tests command
id: exact_command
Expand All @@ -31,6 +36,54 @@ on:
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
fi
- name: Hide the /review tests command comment as resolved when authorized
if: github.event_name == 'issue_comment' && steps.exact_command.outputs.should_run == 'true'
Comment thread
kubaflo marked this conversation as resolved.
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ github.token }}
script: |
// Only hide when the command is exactly `/review tests` (should_run) AND the
// commenter is an authorized collaborator (write/maintain/admin). This mirrors
// the workflow's own role gate but is self-contained, so an unauthorized user's
// comment is always left visible. A failed hide must not block activation.
// Only act on newly-created comments. The gh-aw slash_command trigger also fires
// on `edited`, so without this guard, editing any existing comment to say
// `/review tests` would minimize that comment (and collapse its entire history).
if (context.payload.action !== 'created') {
core.info('Skipping hide: comment was edited, not created.');
return;
}
const { owner, repo } = context.repo;
const actor = context.actor;
let permission = 'none';
try {
const res = await github.rest.repos.getCollaboratorPermissionLevel({ owner, repo, username: actor });
permission = res.data.permission;
} catch (e) {
core.info(`Permission lookup for ${actor} failed: ${e.message}`);
}
// Must mirror the workflow `roles:` frontmatter (admin/maintain/write) — keep in sync.
if (!['admin', 'maintain', 'write'].includes(permission)) {
Comment thread
kubaflo marked this conversation as resolved.
core.info(`Actor ${actor} is not an authorized collaborator (${permission}); leaving the /review tests comment.`);
return;
}
// Minimize (hide as resolved) rather than delete: the rerun scanner replays the PR's
// REST comment history, and minimized comments are still returned by the REST list
// endpoint — only collapsed in the web UI. node_id is the comment's GraphQL global id.
const subjectId = context.payload.comment.node_id;
try {
await github.graphql(
`mutation($id: ID!) {
minimizeComment(input: { subjectId: $id, classifier: RESOLVED }) {
minimizedComment { isMinimized }
}
}`,
{ id: subjectId }
);
core.info(`Hid /review tests command comment ${subjectId} as resolved.`);
} catch (e) {
core.warning(`Could not hide /review tests command comment ${subjectId}: ${e.message}`);
}
workflow_dispatch:
inputs:
pr_number:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/review-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ jobs:
"Reason: ${{ steps.rerun.outputs.reason }}" >> $env:GITHUB_STEP_SUMMARY
"Label: ${{ steps.rerun.outputs.label }}" >> $env:GITHUB_STEP_SUMMARY

- name: Hide the /review rerun command comment as resolved
if: github.event_name == 'issue_comment' && steps.rerun.outputs.eligible == 'true'
Comment thread
kubaflo marked this conversation as resolved.
env:
GH_TOKEN: ${{ github.token }}
COMMENT_NODE_ID: ${{ github.event.comment.node_id }}
run: |
# Only collapse once a rerun was actually triggered (eligible == 'true'). Ineligible
# reruns (no-ai-summary / review-in-progress / no-new-activity) keep the comment fully
# visible as the implicit "seen, nothing changed" signal.
#
# We MINIMIZE (hide as resolved) rather than delete: the rerun scanner replays the
# PR's REST comment history to reconstruct rerun state (Resolve-RerunEligibility.ps1 /
# Query-RerunReadyPRs.ps1 / Get-LatestRerunCommentBefore), and minimized comments are
# still returned by the REST list endpoint — only collapsed in the web UI. Deleting
# would erase that durable checkpoint and re-qualify unchanged commits. A failed hide
# must never fail the job.
if gh api graphql -f query='mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:RESOLVED}){minimizedComment{isMinimized}}}' -f id="$COMMENT_NODE_ID" --silent; then
echo "Hid /review rerun command comment ${COMMENT_NODE_ID} as resolved"
else
echo "::warning::Could not hide /review rerun command comment ${COMMENT_NODE_ID}"
fi

trigger-review:
needs: match
if: needs.match.outputs.matched == 'true' && needs.match.outputs.command == 'review'
Expand Down Expand Up @@ -454,3 +476,23 @@ jobs:
run: |
. .github/scripts/shared/Update-AgentLabels.ps1
Clear-AgentReviewInProgress -PRNumber $env:PR_NUMBER -Owner '${{ github.repository_owner }}' -Repo '${{ github.event.repository.name }}' | Out-Null

- name: Hide the /review command comment as resolved
if: github.event_name == 'issue_comment' && steps.trigger_azdo.outcome == 'success'
env:
GH_TOKEN: ${{ github.token }}
COMMENT_NODE_ID: ${{ github.event.comment.node_id }}
run: |
# Collapse only after the pipeline was actually triggered, so a lock-skip
# (locked == 'true') or a failed AzDO trigger leaves the /review comment visible
# for the user to retry.
#
# We MINIMIZE (hide as resolved) rather than delete so the command — and its
# --branch/--platform options — survives in the REST comment history that the rerun
# scanner replays. Minimized comments are still returned by the REST list endpoint;
# only collapsed in the web UI. A failed hide must never fail the review trigger.
if gh api graphql -f query='mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:RESOLVED}){minimizedComment{isMinimized}}}' -f id="$COMMENT_NODE_ID" --silent; then
echo "Hid /review command comment ${COMMENT_NODE_ID} as resolved"
else
echo "::warning::Could not hide /review command comment ${COMMENT_NODE_ID}"
fi
Loading