Unverified Commit 6d572c27 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

scripts/pr-status: add reply-and-resolve-thread command (#92450)

### What?

Adds a `reply-and-resolve-thread` subcommand to `scripts/pr-status.js`
that combines replying and resolving a review thread in a single
command. Also updates the generated `thread-N.md` files to show this
command alongside the existing separate `reply-thread` and
`resolve-thread` options, and documents the command in the agent skill
files.

### Why?

When addressing PR review comments, the typical workflow is to reply
with a description of what was done and then immediately resolve the
thread. This previously required two separate commands:

```bash
node scripts/pr-status.js reply-thread <id> "Done -- ..."
node scripts/pr-status.js resolve-thread <id>
```

Having a single command reduces friction for agents (and humans) closing
out review threads after addressing feedback.

### How?

- Added `reply-and-resolve-thread` subcommand in `main()` that calls the
existing `replyToThread()` and `resolveThread()` functions in sequence.
- Updated `generateThreadMd()` to include a "Reply and resolve in one
step" code block in the Commands section of each unresolved thread file
(alongside the existing separate commands, not replacing them).
- Updated `.agents/skills/pr-status-triage/SKILL.md` to mention the
combined command in workflow step 6 and added a "Thread interaction"
quick-command reference section.
- Updated `.agents/skills/pr-status-triage/workflow.md` to show the
one-step alternative in the "Resolving Review Threads" section.

<!-- NEXT_JS_LLM_PR -->

---------
Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: 's avatarClaude <noreply@anthropic.com>
parent fea75474
...@@ -19,7 +19,7 @@ Use this skill when the user asks about PR status, CI failures, or review commen ...@@ -19,7 +19,7 @@ Use this skill when the user asks about PR status, CI failures, or review commen
3. Prioritize blocking jobs first: build, lint, types, then test jobs. 3. Prioritize blocking jobs first: build, lint, types, then test jobs.
4. Treat failures as real until disproven; check the "Known Flaky Tests" section before calling anything flaky. 4. Treat failures as real until disproven; check the "Known Flaky Tests" section before calling anything flaky.
5. Reproduce locally with the same mode and env vars as CI. 5. Reproduce locally with the same mode and env vars as CI.
6. After addressing review comments, reply to the thread describing what was done, then resolve it. See `thread-N.md` files for ready-to-use commands. 6. After addressing review comments, reply to the thread describing what was done, then resolve it. Use `reply-and-resolve-thread` to do both in one step, or use `reply-thread` + `resolve-thread` separately. See `thread-N.md` files for ready-to-use commands.
7. When the only remaining failures are known flaky tests and no code changes are needed, retrigger the failing CI jobs with `gh run rerun <run-id> --failed`. Then wait 5 minutes and go back to step 1. Repeat this loop up to 5 times. 7. When the only remaining failures are known flaky tests and no code changes are needed, retrigger the failing CI jobs with `gh run rerun <run-id> --failed`. Then wait 5 minutes and go back to step 1. Repeat this loop up to 5 times.
## Quick Commands ## Quick Commands
...@@ -31,6 +31,14 @@ node scripts/pr-status.js [PR] --wait # background mode, waits for CI to fi ...@@ -31,6 +31,14 @@ node scripts/pr-status.js [PR] --wait # background mode, waits for CI to fi
node scripts/pr-status.js --skip-flaky-check # skip flaky test detection node scripts/pr-status.js --skip-flaky-check # skip flaky test detection
``` ```
Thread interaction:
```bash
node scripts/pr-status.js reply-thread <threadNodeId> "<body>" # reply to a review thread
node scripts/pr-status.js resolve-thread <threadNodeId> # resolve a review thread
node scripts/pr-status.js reply-and-resolve-thread <threadNodeId> "<body>" # reply and resolve in one step
```
## References ## References
- [workflow.md](./workflow.md) — prioritization, common failure patterns, resolving review threads - [workflow.md](./workflow.md) — prioritization, common failure patterns, resolving review threads
......
...@@ -39,6 +39,12 @@ After addressing a review comment (e.g., making the requested code change), or w ...@@ -39,6 +39,12 @@ After addressing a review comment (e.g., making the requested code change), or w
node scripts/pr-status.js resolve-thread <threadNodeId> node scripts/pr-status.js resolve-thread <threadNodeId>
``` ```
Or do both in one step:
```bash
node scripts/pr-status.js reply-and-resolve-thread <threadNodeId> "Done -- <description of changes>"
```
The ready-to-use commands with the correct thread IDs are at the bottom of each `thread-N.md` file in `scripts/pr-status/`. The ready-to-use commands with the correct thread IDs are at the bottom of each `thread-N.md` file in `scripts/pr-status/`.
**Important:** Always reply with a description of the actions taken before resolving. This gives the reviewer context about what changed. **Important:** Always reply with a description of the actions taken before resolving. This gives the reviewer context about what changed.
...@@ -382,37 +382,66 @@ function getPRComments(prNumber) { ...@@ -382,37 +382,66 @@ function getPRComments(prNumber) {
function replyToThread(threadId, body) { function replyToThread(threadId, body) {
body = ':robot: ' + body body = ':robot: ' + body
const mutation = `
mutation($threadId: ID!, $body: String!) { // Step 1: Look up the PR number and first comment's databaseId from the
addPullRequestReviewThreadReply(input: { // thread's GraphQL node ID. The REST reply endpoint requires both.
pullRequestReviewThreadId: $threadId, const lookupQuery = `
body: $body query($id: ID!) {
}) { node(id: $id) {
comment { ... on PullRequestReviewThread {
id pullRequest {
url number
}
comments(first: 1) {
nodes {
databaseId
}
}
} }
} }
} }
` `
let prNumber, commentDatabaseId
try {
const lookupOutput = execFileSync(
'gh',
['api', 'graphql', '-f', `query=${lookupQuery}`, '-f', `id=${threadId}`],
{ encoding: 'utf8' }
).trim()
const lookupData = JSON.parse(lookupOutput)
const thread = lookupData.data.node
if (!thread || !thread.pullRequest || !thread.comments?.nodes?.[0]) {
console.error(`Could not resolve thread node ID: ${threadId}`)
process.exit(1)
}
prNumber = thread.pullRequest.number
commentDatabaseId = thread.comments.nodes[0].databaseId
} catch (error) {
console.error(
'Failed to look up thread info:',
error.stderr || error.message
)
process.exit(1)
}
// Step 2: Post the reply via REST. Unlike the GraphQL mutation
// addPullRequestReviewThreadReply, this endpoint always publishes the reply
// immediately — it is never attached to a pending/draft review.
try { try {
const output = execFileSync( const output = execFileSync(
'gh', 'gh',
[ [
'api', 'api',
'graphql', '--method',
'-f', 'POST',
`query=${mutation}`, `/repos/vercel/next.js/pulls/${prNumber}/comments/${commentDatabaseId}/replies`,
'-f',
`threadId=${threadId}`,
'-f', '-f',
`body=${body}`, `body=${body}`,
], ],
{ encoding: 'utf8' } { encoding: 'utf8' }
).trim() ).trim()
const data = JSON.parse(output) const data = JSON.parse(output)
const comment = data.data.addPullRequestReviewThreadReply.comment console.log(`Reply posted: ${data.html_url}`)
console.log(`Reply posted: ${comment.url}`)
} catch (error) { } catch (error) {
console.error('Failed to reply to thread:', error.stderr || error.message) console.error('Failed to reply to thread:', error.stderr || error.message)
process.exit(1) process.exit(1)
...@@ -1066,6 +1095,11 @@ function generateThreadMd(thread, index) { ...@@ -1066,6 +1095,11 @@ function generateThreadMd(thread, index) {
'```', '```',
`node scripts/pr-status.js resolve-thread ${thread.id}`, `node scripts/pr-status.js resolve-thread ${thread.id}`,
'```', '```',
'',
'Reply and resolve in one step:',
'```',
`node scripts/pr-status.js reply-and-resolve-thread ${thread.id} "Your reply here"`,
'```',
'' ''
) )
} }
...@@ -1526,6 +1560,20 @@ async function main() { ...@@ -1526,6 +1560,20 @@ async function main() {
return return
} }
if (subcommand === 'reply-and-resolve-thread') {
const threadId = process.argv[3]
const body = process.argv[4]
if (!threadId || !body) {
console.error(
'Usage: node scripts/pr-status.js reply-and-resolve-thread <threadNodeId> <body>'
)
process.exit(1)
}
replyToThread(threadId, body)
resolveThread(threadId)
return
}
// Parse CLI arguments // Parse CLI arguments
const args = process.argv.slice(2) const args = process.argv.slice(2)
const waitFlag = args.includes('--wait') const waitFlag = args.includes('--wait')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment