AgentSkillsCN

eia-github-pr-context

在进行代码评审规划时,可选用此技能来获取PR上下文,包括元数据、差异对比,以及变更文件。可通过/review-pr [PR_NUMBER]触发。

SKILL.md
--- frontmatter
name: eia-github-pr-context
description: Use when retrieving PR context including metadata, diff, and changed files for code review planning. Trigger with /review-pr [PR_NUMBER].
license: Apache-2.0
compatibility: Requires AI Maestro installed.
metadata:
  version: 1.0.0
  author: integrator-agent
  category: github
  tags: "pull-request, code-review, diff-analysis, github-api"
agent: api-coordinator
context: fork

GitHub PR Context Skill

Overview

This skill provides tools to retrieve comprehensive context about GitHub Pull Requests. Use this skill when you need to:

  • Understand a PR before reviewing: Get the full picture of what changed, why, and how
  • Plan task delegation: Know which files changed to assign subagents appropriately
  • Analyze merge readiness: Check mergeable status, conflicts, and CI state
  • Extract specific metadata: Get author, branch names, labels, reviewers

Output

Each script produces structured output for different PR analysis needs:

ScriptOutput FormatKey FieldsUse Case
eia_get_pr_context.pyJSONnumber, title, state, author, mergeable, files[], labels[], reviewers[]Complete PR overview for review planning
eia_get_pr_files.pyJSON arrayfilename, status, additions, deletions, patch (optional)File-level change tracking
eia_get_pr_diff.pyUnified diff text or JSON statsDiff hunks or files_changed, insertions, deletionsCode change inspection

All JSON outputs are pretty-printed and can be piped to jq for filtering.

Instructions

Follow these numbered steps to retrieve and analyze GitHub PR context:

  1. Verify prerequisites are met

    • Run gh auth status to confirm GitHub CLI authentication
    • Run python3 --version to confirm Python 3.8+ is available
    • Ensure you have read access to the target repository
  2. Identify which information you need

    • Need full PR overview? → Use eia_get_pr_context.py
    • Need only changed files list? → Use eia_get_pr_files.py
    • Need actual code diff? → Use eia_get_pr_diff.py
  3. Run the appropriate script with required parameters

    • Always provide --pr NUMBER (the PR number)
    • Optionally provide --repo OWNER/REPO (defaults to current directory's repo)
    • For diffs, optionally add --stat for summary or --files for specific files
  4. Parse the output based on your task

    • For JSON outputs: pipe to jq or parse in your code
    • For diff outputs: analyze unified diff format or statistics
    • Check exit codes (0 = success, 1-4 = various errors)
  5. Handle errors appropriately

    • Exit code 1: Fix invalid parameters
    • Exit code 2: Verify PR number and repository
    • Exit code 3: Check network, retry if rate limited
    • Exit code 4: Re-authenticate with gh auth login
  6. Extract specific information as needed

Checklist

Copy this checklist and track your progress:

  • Verify GitHub CLI is authenticated (gh auth status)
  • Verify Python 3.8+ is available
  • Confirm read access to the target repository
  • Identify which information is needed (context/files/diff)
  • Run the appropriate script with --pr NUMBER parameter
  • Parse the JSON or diff output
  • Check exit codes and handle any errors
  • Extract specific metadata or diff information as needed

When to Use This Skill

ScenarioUse This Skill
Starting a code reviewYes - get full PR context first
Need to know which files changedYes - use file listing script
Want to see actual code changesYes - use diff retrieval script
Need PR metadata (author, labels)Yes - use context script
Creating a new PRNo - use git workflow skill instead
Commenting on a PRPartially - get context first, then use gh CLI directly

Decision Tree: Which Script to Use

code
Need PR information?
├── Need full context (metadata + files + status)?
│   └── Use: eia_get_pr_context.py
│
├── Need only the list of changed files?
│   └── Use: eia_get_pr_files.py
│
├── Need to see the actual code diff?
│   ├── Want summary statistics only?
│   │   └── Use: eia_get_pr_diff.py --stat
│   ├── Want diff for specific files?
│   │   └── Use: eia_get_pr_diff.py --files file1.py file2.py
│   └── Want full diff?
│       └── Use: eia_get_pr_diff.py

Prerequisites

  1. GitHub CLI (gh) must be installed and authenticated
  2. Python 3.8+ available in PATH
  3. Repository access - you must have read access to the repository

Verify prerequisites:

bash
# Check gh is authenticated
gh auth status

# Check Python version
python3 --version

Script Reference Table

ScriptPurposeKey ArgumentsOutput
eia_get_pr_context.pyFull PR metadata and status--pr NUMBER, --repo OWNER/REPOJSON with metadata, files, mergeable status
eia_get_pr_files.pyList changed files--pr NUMBER, --repo OWNER/REPO, --include-patchJSON array of files with status
eia_get_pr_diff.pyGet code diff--pr NUMBER, --repo OWNER/REPO, --stat, --filesDiff text or JSON stats

Exit Codes (Standardized)

All scripts use standardized exit codes for consistent error handling:

CodeMeaningDescription
0SuccessOutput is valid JSON/text
1Invalid parametersBad PR number, missing required args
2Resource not foundPR does not exist
3API errorNetwork, rate limit, timeout
4Not authenticatedgh CLI not logged in
5Idempotency skipN/A for these scripts
6Not mergeableN/A for these scripts

Examples

Get Full PR Context

bash
# Get context for PR #123 in current repo
python3 eia_get_pr_context.py --pr 123

# Get context for PR in specific repo
python3 eia_get_pr_context.py --pr 456 --repo owner/repo-name

List Changed Files

bash
# List files changed in PR #123
python3 eia_get_pr_files.py --pr 123

# Include patch/diff for each file
python3 eia_get_pr_files.py --pr 123 --include-patch

Get Diff

bash
# Get full diff
python3 eia_get_pr_diff.py --pr 123

# Get statistics summary only
python3 eia_get_pr_diff.py --pr 123 --stat

# Get diff for specific files only
python3 eia_get_pr_diff.py --pr 123 --files src/main.py tests/test_main.py

Reference Documents

PR Metadata Reference

For detailed information about PR metadata fields and how to extract specific information, see:

references/pr-metadata.md

Contents:

    1. PR Metadata JSON Structure
    • 1.1 Core identification fields (number, title, state)
    • 1.2 Author and assignee information
    • 1.3 Branch and merge information
    • 1.4 Labels, milestones, and projects
    • 1.5 Review and approval status
    1. Extracting Specific Fields
    • 2.1 Getting PR title and description
    • 2.2 Finding the source and target branches
    • 2.3 Checking mergeable status and conflicts
    • 2.4 Listing reviewers and their decisions
    1. Common Metadata Queries
    • 3.1 Is this PR ready to merge?
    • 3.2 Who needs to approve this PR?
    • 3.3 What labels are applied?

Diff Analysis Reference

For detailed information about interpreting PR diffs and analyzing changes, see:

references/diff-analysis.md

Contents:

    1. Understanding Diff Output
    • 1.1 Unified diff format explanation
    • 1.2 File headers and hunks
    • 1.3 Addition, deletion, and context lines
    1. File-Level Analysis
    • 2.1 Identifying file types by extension
    • 2.2 Detecting rename and copy operations
    • 2.3 Binary file changes
    1. Change Statistics
    • 3.1 Lines added vs deleted
    • 3.2 Files by change type (added, modified, deleted)
    • 3.3 Estimating review complexity
    1. Filtering and Focusing
    • 4.1 Filtering by file path patterns
    • 4.2 Ignoring generated files
    • 4.3 Focusing on specific directories

Integration with Integrator Agent

When delegating PR review tasks, use this skill to gather context first:

code
1. Get PR context with eia_get_pr_context.py
2. Analyze which files changed with eia_get_pr_files.py
3. Delegate file-specific reviews to subagents based on file types
4. Aggregate results and post review summary

Error Handling

ProblemCauseSolution
"gh: command not found"GitHub CLI not installedInstall with brew install gh or see gh docs
"not logged into any GitHub hosts"gh not authenticatedRun gh auth login
"Could not resolve to a PullRequest"Wrong PR number or repoVerify PR exists with gh pr view NUMBER
Rate limit errorsToo many API callsWait for rate limit reset or use --retry
Permission deniedNo repo accessVerify you have read access to the repository

For additional troubleshooting, run scripts with --verbose flag for detailed logging.

Resources