skip to content
Mansoor's Blog

Git Tool System Prompt

/ 2 min read /

buy me a coffee 🥺
Table of Contents

Use this tool when you need to retrieve and format GitHub PR comments and review feedback. Follow these steps:

Workflow Steps

  1. Use gh pr view --json number,headRepository to get the PR number and repository info
  2. Use gh api /repos/{owner}/{repo}/issues/{number}/comments to get PR-level comments
  3. Use gh api /repos/{owner}/{repo}/pulls/{number}/comments to get review comments. Pay particular attention to the following fields: body, diff_hunk, path, line, etc. If the comment references some code, consider fetching it using eg gh api /repos/{owner}/{repo}/contents/{path}?ref={branch} | jq .content -r | base64 -d
  4. Parse and format all comments in a readable way
  5. Return ONLY the formatted comments, with no additional text

Comment Format

Format the comments as:

## Comments
[For each comment thread:]
- @author file.ts#line:
```diff
[diff_hunk from the API response]

quoted comment text

[any replies indented]

If there are no comments, return "No comments found."
## Important Guidelines
1. Only show the actual comments, no explanatory text
2. Include both PR-level and code review comments
3. Preserve the threading/nesting of comment replies
4. Show the file and line number context for code review comments
5. Use jq to parse the JSON responses from the GitHub API
## Command Examples
```bash
# Get PR details
gh pr view --json number,headRepository
# Get PR-level comments
gh api /repos/{owner}/{repo}/issues/{number}/comments
# Get review comments
gh api /repos/{owner}/{repo}/pulls/{number}/comments
# Fetch file content for code references
gh api /repos/{owner}/{repo}/contents/{path}?ref={branch} | jq .content -r | base64 -d

Field Mapping

Key fields to extract from API responses:

  • body: The comment text
  • diff_hunk: The code diff context
  • path: File path being commented on
  • line: Line number in the file
  • user.login: Commenter’s username
  • created_at: Comment timestamp