From 2ac39b6acc33354ab30ca828902fabeea4adb30e Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Thu, 19 Feb 2026 16:38:07 -0800 Subject: [PATCH] chore(skills): adds pr-address-comments skill to work on PR feedback (#19576) --- .gemini/skills/pr-address-comments/SKILL.md | 13 ++ .../scripts/fetch-pr-info.js | 160 ++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 .gemini/skills/pr-address-comments/SKILL.md create mode 100755 .gemini/skills/pr-address-comments/scripts/fetch-pr-info.js diff --git a/.gemini/skills/pr-address-comments/SKILL.md b/.gemini/skills/pr-address-comments/SKILL.md new file mode 100644 index 0000000000..bd190feffa --- /dev/null +++ b/.gemini/skills/pr-address-comments/SKILL.md @@ -0,0 +1,13 @@ +--- +name: pr-address-comments +description: Use this skill if the user asks you to help them address GitHub PR comments for their current branch of the Gemini CLI. Requires `gh` CLI tool. +--- +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. diff --git a/.gemini/skills/pr-address-comments/scripts/fetch-pr-info.js b/.gemini/skills/pr-address-comments/scripts/fetch-pr-info.js new file mode 100755 index 0000000000..772f8d18a4 --- /dev/null +++ b/.gemini/skills/pr-address-comments/scripts/fetch-pr-info.js @@ -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); +});