SKILL.md
SKILL.mdBrowse 3 files
3,916 tokens
14,599 bytes
Token encoding: o200k_base
Snapshot 5b913e7
1---2name: check-pr3description: >4 Check a GitHub, GitLab, or Perforce PR/MR/CL for review comments, failing5 checks, and PR-body gaps. Use when asked to inspect, fix, or prepare a change6 for submission.7license: MIT8compatibility: Requires git and gh (GitHub CLI), glab (GitLab CLI), or p4 (Perforce CLI) installed and authenticated.9metadata:10 author: greptileai11 version: "1.3"12allowed-tools: Bash(gh:*) Bash(glab:*) Bash(git:*) Bash(p4:*)13---14 15# Check PR16 17Analyze a pull request (GitHub), merge request (GitLab), or shelved changelist (Perforce) for review comments, status checks, and description completeness, then help address any issues found.18 19## Inputs20 21- **PR/MR/CL number** (optional): If not provided, detect the PR/MR for the current branch, or the default pending changelist for p4.22 23## Instructions24 25### 0. Detect platform26 27First check if the user is working in a Perforce depot by looking for a `.p4config` file or `P4CLIENT`/`P4PORT` environment variables:28 29```bash30# Check for Perforce environment31if p4 info >/dev/null 2>&1; then32 VCS="perforce"33else34 # Fall back to git remote detection35 REMOTE_URL=$(git remote get-url origin)36 if echo "$REMOTE_URL" | grep -qi "gitlab"; then37 VCS="gitlab"38 else39 VCS="github"40 fi41fi42```43 44For self-hosted GitLab instances whose hostname doesn't contain "gitlab", the user can override by passing `--vcs gitlab` as an input. For Perforce, the user can override by passing `--vcs perforce`.45 46### 1. Identify the PR/MR/CL47 48If a number was provided, use it. Otherwise, detect it:49 50**GitHub:**51```bash52gh pr view --json number,headRefName,headRefOid -q '{number: .number, branch: .headRefName, head: .headRefOid}'53```54 55**GitLab:**56```bash57glab mr view --output json | jq '.iid'58```59 60**Perforce:**61```bash62# List pending changelists for the current user/client63p4 changes -s pending -u $P4USER -c $P4CLIENT64```65 66Key field differences between platforms:67- GitHub: `number`, `headRefName`, `headRefOid`68- GitLab: `iid`, `source_branch`, `sha`69- Perforce: changelist number (CL), `shelved` files for in-review CLs70 71### 2. Fetch PR/MR/CL details72 73**GitHub:**74```bash75gh pr view <PR_NUMBER> --json title,body,state,reviews,comments,headRefName,headRefOid,statusCheckRollup76OWNER_REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)77gh api "repos/$OWNER_REPO/pulls/<PR_NUMBER>/comments"78gh api --paginate "repos/$OWNER_REPO/issues/<PR_NUMBER>/comments?per_page=100"79```80 81GitHub PRs are also issues, so general PR comments live on the issue comments endpoint. Greptile may edit a single general PR comment on each review cycle instead of creating a new review or comment. Always inspect the latest Greptile-authored general comment by `updated_at`, including any "Prompt to fix all with AI" section, before concluding that the PR is clear.82 83**GitLab:**84```bash85glab mr view <MR_IID> --output json86# Fetch discussions (inline diff comments are type "DiffNote"; general comments have null type)87glab api "projects/:fullpath/merge_requests/<MR_IID>/discussions"88```89 90For GitLab, paginate discussions if needed (add `?per_page=100&page=N`).91 92**Perforce:**93```bash94# Get changelist description, files, and status95p4 describe -s <CL_NUMBER>96 97# Get shelved files (for in-review CLs)98p4 describe -S <CL_NUMBER>99 100# Get the diff of the shelved changelist101p4 diff2 //...@=<CL_NUMBER> //...@=<CL_NUMBER>102 103# List review comments (if using p4 review workflow)104p4 review -c <CL_NUMBER>105```106 107Key Perforce CL fields:108- `Change`: changelist number109- `Status`: `pending`, `submitted`, `shelved`110- `Description`: the CL description / commit message111- `Files`: list of files in the CL112 113### 3. Wait for pending checks114 115Before analyzing, ensure all status checks have completed. If any checks are `PENDING` or `IN_PROGRESS` (GitHub) / `running` or `pending` (GitLab), poll every 30 seconds until all checks reach a terminal state.116 117**GitHub:** poll `statusCheckRollup` from `gh pr view`.118 119**GitLab:**120```bash121glab api "projects/:fullpath/merge_requests/<MR_IID>/pipelines"122```123Pipeline statuses: `running`, `pending`, `success`, `failed`, `canceled`, `skipped`. Poll until no pipeline has `running` or `pending` status.124 125**Perforce:** Perforce doesn't have built-in CI checks natively. If the team uses a review tool (Swarm, etc.) or an external CI triggered by shelve events, check the relevant system. Otherwise, proceed to analysis immediately.126 127### 4. Require a fresh Greptile review for the current head128 129For GitHub PRs, do not treat an existing Greptile review, comment, or summary as current unless it is tied to the PR's exact current `headRefOid`. This is especially important after pushing a new commit to an existing PR: a Greptile review on an older commit is stale, even if the PR still has a Greptile comment or prior review.130 131Fetch the current head SHA immediately before the Greptile gate:132 133```bash134HEAD_SHA=$(gh pr view <PR_NUMBER> --json headRefOid -q .headRefOid)135```136 137Then inspect check-runs for that commit and require a completed Greptile run:138 139```bash140OWNER_REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)141GREPTILE_CHECKS=$(gh api "repos/$OWNER_REPO/commits/$HEAD_SHA/check-runs?per_page=100" \142 --jq '[.check_runs[] | select(.name | test("greptile"; "i"))]')143 144# A run only counts as a valid fresh pass when it has completed AND concluded cleanly.145# GitHub check-run conclusions: success, neutral, skipped, failure, timed_out,146# cancelled, action_required, stale. Treat success/neutral as clean;147# everything else (especially failure and action_required) must block.148FRESH_GREPTILE_COMPLETED=$(echo "$GREPTILE_CHECKS" \149 | jq '[.[] | select(.status == "completed")] | length')150FRESH_GREPTILE_CLEAN=$(echo "$GREPTILE_CHECKS" \151 | jq '[.[] | select(.status == "completed" and (.conclusion | IN("success","neutral")))] | length')152FRESH_GREPTILE_BLOCKING=$(echo "$GREPTILE_CHECKS" \153 | jq '[.[] | select(.status == "completed" and ((.conclusion | IN("success","neutral")) | not))] | length')154 155if [ "$FRESH_GREPTILE_COMPLETED" = "0" ]; then156 echo "Blocked: no completed Greptile review/check is tied to current PR head $HEAD_SHA."157 echo "Request a fresh Greptile review against this head before marking the PR check done."158 echo "Suggested trigger: gh pr comment <PR_NUMBER> --body \"@greptile review\""159 exit 1160fi161 162if [ "$FRESH_GREPTILE_BLOCKING" != "0" ] || [ "$FRESH_GREPTILE_CLEAN" = "0" ]; then163 echo "Blocked: Greptile completed on head $HEAD_SHA but did not conclude clean"164 echo "(conclusion was failure/action_required/timed_out/cancelled/stale, or no clean run exists)."165 echo "Address the findings, push, and re-run Greptile until it concludes success/clean on the new head."166 exit 1167fi168```169 170If a Greptile check exists for the current head but is still pending or in progress, wait for it with the same polling pattern used by `greploop` rather than proceeding from older review material. If no Greptile check appears for the current head after a reasonable wait, report the PR as blocked on a fresh Greptile review for `HEAD_SHA` and stop. Do not mark the check complete from PR comments, PR reviews, or Greptile summaries that cannot be associated with the current head SHA.171 172For GitLab installations with Greptile integration, apply the same freshness rule against the MR's current head SHA:173 174```bash175# 1. Get the MR's current head SHA176MR_SHA=$(glab mr view <MR_IID> --output json | jq -r '.sha // .diff_refs.head_sha')177 178# 2. Find the latest pipeline for that EXACT sha, then the Greptile job within it.179LATEST_PIPELINE_ID=$(glab api "projects/:fullpath/merge_requests/<MR_IID>/pipelines" \180 | jq -r --arg sha "$MR_SHA" '[.[] | select(.sha == $sha)] | sort_by(.id) | last | .id // empty')181 182if [ -n "$LATEST_PIPELINE_ID" ]; then183 GREPTILE_JOBS=$(glab api "projects/:fullpath/pipelines/$LATEST_PIPELINE_ID/jobs" \184 | jq --arg sha "$MR_SHA" '[.[] | select(.name | test("greptile"; "i"))185 | {name, status, pipeline_sha: $sha}]')186else187 GREPTILE_JOBS='[]'188fi189 190GREPTILE_JOB_SUCCESS=$(echo "$GREPTILE_JOBS" \191 | jq '[.[] | select(.status == "success")] | length')192GREPTILE_JOB_BLOCKING=$(echo "$GREPTILE_JOBS" \193 | jq '[.[] | select(.status != "success")] | length')194 195# 3. If Greptile integrates via MR notes instead of a CI job, require the newest196# Greptile note to reference the current head sha and report a clean review.197GREPTILE_NOTES=$(glab api "projects/:fullpath/merge_requests/<MR_IID>/discussions?per_page=100" \198 | jq --arg sha "$MR_SHA" '[.[].notes[]199 | select(.author.username | test("greptile"; "i"))]200 | sort_by(.updated_at // .created_at)')201GREPTILE_NOTE_CLEAN=$(echo "$GREPTILE_NOTES" \202 | jq --arg sha "$MR_SHA" 'if length == 0 then 0203 elif ((last.body // "") | contains($sha) and test("Confidence Score:[[:space:]]*5/5|Confidence:[[:space:]]*5/5|\\b5/5\\b"; "i") and (test("Prompt To Fix|blocking issue|failed|action required"; "i") | not)) then 1204 else 0 end')205 206if [ "$GREPTILE_JOB_SUCCESS" = "0" ] && [ "$GREPTILE_NOTE_CLEAN" = "0" ]; then207 echo "Blocked: no successful Greptile job or completed-clean current-head Greptile note is tied to MR head $MR_SHA."208 exit 1209fi210 211if [ "$GREPTILE_JOB_BLOCKING" != "0" ]; then212 echo "Blocked: at least one Greptile job for MR head $MR_SHA did not succeed."213 exit 1214fi215```216 217Block completion if, for `MR_SHA`, there is (a) no Greptile job or note at all (missing), (b) the newest Greptile job/note is tied to a different sha (stale), or (c) the Greptile job status is not `success`. A completed Greptile result for a different SHA is stale and must block completion.218 219For Perforce installations with Greptile integration, apply the same rule using the CL's current shelved-revision identity and the Greptile webhook/review artifact tied to it; a Greptile result for an earlier shelf is stale and must block completion.220 221### 5. Analyze the PR/MR222 223Once all checks are complete, evaluate these areas:224 225#### A. Status Checks226 227- Are all CI checks passing?228- If any are failing, identify which ones and the failure reason.229 230#### B. PR/MR Description231 232- Is the description complete and follows team conventions?233- Are all required sections filled in?234- Are there TODOs or placeholders that need updating?235 236#### C. Review Comments237 238- Inline code review comments that need addressing239- Look for bot review comments (e.g. from `greptile-apps[bot]` on GitHub, or the Greptile bot user on GitLab, linters, etc.)240- Human reviewer comments241- **Perforce:** review comments from `p4 review` or external review tools242 243#### D. General Comments244 245- Discussion comments on the PR/MR246- For GitHub, check the issue comments endpoint and use `updated_at` to catch bot comments edited in place. Greptile's latest edited summary can contain actionable items even when there are no new inline comments.247- Bot comments (deploy previews, etc.) - usually informational248- **Perforce:** CL description should include a clear summary, affected files rationale, and testing notes249 250### 6. Categorize issues251 252For each issue found, categorize as:253 254| Category | Meaning |255|---|---|256| **Actionable** | Code changes, test improvements, or fixes needed |257| **Informational** | Verification notes, questions, or FYIs that don't require changes |258| **Already addressed** | Issues that appear to be resolved by subsequent commits |259 260### 7. Report findings261 262Present a summary table:263 264| Area | Issue | Status | Action Needed |265|------|-------|--------|---------------|266| Status Checks | CI build failing | Failing | Fix type error in `src/api.ts` |267| Review | "Add null check" - @reviewer | Actionable | Add guard clause |268| Description | TODO placeholder in test plan | Actionable | Fill in test plan |269| Review | "Looks good" - @teammate | Informational | None |270 271### 8. Fix issues (if requested)272 273If there are actionable items:274 2751. Switch to the PR/MR's branch (git) or ensure files are open in the correct CL (Perforce) if not already.2762. Ask the user if they want to fix the issues.2773. If yes, make the fixes, then:278 279**GitHub/GitLab:** commit and push:280```bash281git add <files>282git commit -m "address review feedback"283git push284```285 286**Perforce:** open files for edit, make changes, and re-shelve:287```bash288p4 edit <file>289# make changes290p4 shelve -f -c <CL_NUMBER>291```292 293### 9. Resolve review threads294 295After addressing comments, resolve the corresponding review threads.296 297**Perforce** - Perforce does not have a native "resolve thread" concept. Instead, mark comments as addressed by updating the CL description or by responding in the review tool being used (Swarm, etc.). If using `p4 review`:298 299```bash300# Mark files as reviewed after addressing feedback301p4 review -c <CL_NUMBER>302```303 304**GitHub** - fetch unresolved thread IDs (paginate if needed - see [the GraphQL reference](references/graphql-queries.md)):305 306```bash307gh api graphql -f query='308query($cursor: String) {309 repository(owner: "OWNER", name: "REPO") {310 pullRequest(number: PR_NUMBER) {311 reviewThreads(first: 100, after: $cursor) {312 pageInfo { hasNextPage endCursor }313 nodes {314 id315 isResolved316 comments(first: 1) {317 nodes { body path }318 }319 }320 }321 }322 }323}'324```325 326If `hasNextPage` is true, repeat with `-f cursor=ENDCURSOR` to get remaining threads.327 328Then resolve threads that have been addressed or are informational:329 330```bash331gh api graphql -f query='332mutation {333 resolveReviewThread(input: {threadId: "THREAD_ID"}) {334 thread { isResolved }335 }336}'337```338 339Batch multiple resolutions into a single mutation using aliases (`t1`, `t2`, etc.).340 341**GitLab** - fetch unresolved discussions (see [the GitLab API reference](references/gitlab-api.md)):342 343```bash344glab api "projects/:fullpath/merge_requests/<MR_IID>/discussions?per_page=100"345```346 347Filter for discussions where `"resolved": false`. Collect each discussion's `id`.348 349Resolve each discussion individually (GitLab has no batch resolution):350 351```bash352glab api --method PUT \353 "projects/:fullpath/merge_requests/<MR_IID>/discussions/<DISCUSSION_ID>" \354 --field resolved=true355```356 357Repeat for each unresolved discussion ID.358 359### 10. Multiple PRs/MRs/CLs360 361If checking a chain of PRs/MRs/CLs, process them sequentially.362 363**Perforce** - to check multiple changelists at once:364```bash365p4 changes -s pending -u $P4USER -c $P4CLIENT -l366```367 368## Output format369 370Summarize:371- PR/MR/CL title or description and current state372- Platform detected (GitHub / GitLab / Perforce)373- Status checks summary (passing/failing/pending) - or N/A for Perforce374- Total issues found375- Actionable items with descriptions376- Items that can be ignored with reasons377- Recommended next steps378 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.