-
Notifications
You must be signed in to change notification settings - Fork 13k
chore(skills): adds pr-address-comments skill to work on PR feedback #19576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| name: pr-address-comments | ||
| description: Use this skill if the user asks you to help them address PR comments for their current work/branch. | ||
mbleigh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --- | ||
| You are helping the user address comments on their Pull Request. These comments may have come from an automated review agent or a team member. | ||
|
|
||
| OBJECTIVE: Help the user review and address comments on their PR. | ||
|
|
||
| # Comment Review Procedure | ||
|
|
||
| 1. Run the `scripts/fetch-pr-info.js` script to get PR info and state. MAKE SURE you read the entire output of the command, even if it gets truncated. | ||
| 2. Summarize the review status by analyzing the diff, commit log, and comments to see which still need to be addressed. Pay attention to the current user's comments. For resolved threads, summarize as a single line with a ✅. For open threads, provide a reference number e.g. [1] and the comment content. | ||
| 3. Present your summary of the feedback and current state and allow the user to guide you as to what to fix/address/skip. DO NOT begin fixing issues automatically. | ||
160 changes: 160 additions & 0 deletions
160
.gemini/skills/pr-address-comments/scripts/fetch-pr-info.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* eslint-env node */ | ||
| /* global console, process */ | ||
|
|
||
| import { exec } from 'node:child_process'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execAsync = promisify(exec); | ||
|
|
||
| async function run(cmd) { | ||
| try { | ||
| const { stdout } = await execAsync(cmd, { | ||
| encoding: 'utf8', | ||
| stdio: ['pipe', 'pipe', 'ignore'], | ||
| }); | ||
| return stdout.trim(); | ||
| } catch (_e) { // eslint-disable-line @typescript-eslint/no-unused-vars | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| const IGNORE_MESSAGES = [ | ||
| 'thank you so much for your contribution to Gemini CLI!', | ||
| "I'm currently reviewing this pull request and will post my feedback shortly.", | ||
| 'This pull request is being closed because it is not currently linked to an issue.', | ||
| ]; | ||
|
|
||
| const shouldIgnore = (body) => { | ||
| if (!body) return false; | ||
| return IGNORE_MESSAGES.some((msg) => body.includes(msg)); | ||
| }; | ||
|
|
||
| async function main() { | ||
| const branch = await run('git branch --show-current'); | ||
| if (!branch) { | ||
| console.error('❌ Could not determine current git branch.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const gqlQuery = `query($branch:String!){repository(name:"gemini-cli",owner:"google-gemini"){pullRequests(headRefName:$branch,first:100){nodes{id,number,state,comments(first:100){nodes{createdAt,isMinimized,minimizedReason,author{login},body,url,authorAssociation}},reviews(first:100){nodes{id,author{login},createdAt,isMinimized,minimizedReason,body,state,comments(first:30){nodes{id,replyTo{id},author{login},createdAt,body,isMinimized,minimizedReason,path,line,startLine,originalLine,originalStartLine}}}}}}}}`; | ||
|
|
||
| const [authInfo, diff, commits, rawJson] = await Promise.all([ | ||
| run('gh auth status -a'), | ||
| run('gh pr diff'), | ||
| run( | ||
| 'git fetch && git log origin/main..origin/$(git branch --show-current)', | ||
| ), | ||
| run(`gh api graphql -F branch="${branch}" -f query='${gqlQuery}'`), | ||
| ]); | ||
|
|
||
| if (!diff) { | ||
| console.error(`⚠️ No active PR found for branch: ${branch}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`\n# Current GitHub user info:\n\n${authInfo}\n`); | ||
| console.log(`\n# PR diff for current branch: ${branch}\n\n\`\`\``); | ||
| console.log(diff); | ||
| console.log('```'); | ||
| console.log( | ||
| `\n# Commit history (origin/main..origin/${branch})\n\n${commits}`, | ||
| ); | ||
|
|
||
| const data = JSON.parse(rawJson || '{}'); | ||
| const prs = data?.data?.repository?.pullRequests?.nodes || []; | ||
|
|
||
| // Sort PRs by number descending so we check the newest one first | ||
| prs.sort((a, b) => b.number - a.number); | ||
|
|
||
| const pr = prs.find((p) => p.state === 'OPEN') || prs[0]; | ||
|
|
||
| if (!pr) { | ||
| console.error('❌ No PR data found.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log('\n# PR Feedback\n'); | ||
|
|
||
| // 1. General PR Comments | ||
| const general = pr.comments.nodes.filter((c) => !shouldIgnore(c.body)); | ||
| if (general.length > 0) { | ||
| console.log('\n💬 GENERAL COMMENTS:'); | ||
| general.forEach((c) => { | ||
| const minimized = c.isMinimized | ||
| ? ` (Minimized: ${c.minimizedReason})` | ||
| : ''; | ||
| console.log( | ||
| `[${c.createdAt}] [${c.author.login}]${minimized}: ${c.body}\n`, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| // 2. Process ALL Review Comments into a single Thread Map | ||
| const allInlineComments = pr.reviews.nodes.flatMap((r) => r.comments.nodes); | ||
| const filteredInlines = allInlineComments.filter( | ||
| (c) => !shouldIgnore(c.body), | ||
| ); | ||
|
|
||
| console.log('🔍 CODE REVIEWS & INLINE THREADS:'); | ||
|
|
||
| // Print Review Summaries First | ||
| pr.reviews.nodes.forEach((review) => { | ||
| if (review.body && !shouldIgnore(review.body)) { | ||
| const icon = review.state === 'APPROVED' ? '✅' : '💬'; | ||
| const minimized = review.isMinimized | ||
| ? ` (Minimized: ${review.minimizedReason})` | ||
| : ''; | ||
| console.log( | ||
| `\n${icon} ${review.state} by ${review.author.login} at ${review.createdAt}${minimized}: "${review.body}"`, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| // Build and Print Threads | ||
| const topLevelThreads = filteredInlines.filter((c) => !c.replyTo); | ||
|
|
||
| const printThread = (parentId, depth = 1) => { | ||
| const indent = ' '.repeat(depth); | ||
| filteredInlines | ||
| .filter((c) => c.replyTo?.id === parentId) | ||
| .forEach((reply) => { | ||
| const minimized = reply.isMinimized | ||
| ? ` (Minimized: ${reply.minimizedReason})` | ||
| : ''; | ||
| console.log( | ||
| `${indent}↳ [${reply.createdAt}] ${reply.author.login}${minimized}: ${reply.body}`, | ||
| ); | ||
| printThread(reply.id, depth + 1); | ||
| }); | ||
| }; | ||
|
|
||
| topLevelThreads.forEach((c) => { | ||
| const start = c.startLine || c.originalStartLine; | ||
| const end = c.line || c.originalLine; | ||
| const range = start && end && start !== end ? `${start}-${end}` : end || ''; | ||
| const fileInfo = c.path | ||
| ? `(${c.path}${range ? `:${range}` : ''}) ` | ||
| : range | ||
| ? `(Line ${range}) ` | ||
| : ''; | ||
| const minimized = c.isMinimized ? ` (Minimized: ${c.minimizedReason})` : ''; | ||
| console.log( | ||
| `\n💬 ${minimized}${c.author.login} | ${c.createdAt} ${fileInfo}\n${c.body}`, | ||
| ); | ||
| printThread(c.id); | ||
| }); | ||
|
|
||
| console.log('\n'); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error('❌ Unexpected error:', err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.