SOP-008: GitHub Integration
Document Control
| Field | Value |
|---|---|
| Document ID | SOP-008 |
| Version | 1.0 |
| Status | Active |
| Owner | Claude AI Operations |
| Last Updated | 2024-12-01 |
| Review Date | 2025-03-01 |
Overview
This SOP defines procedures for integrating Claude AI with GitHub repositories. It covers authentication setup, repository access configuration, automated workflows, and collaborative development practices using Claude with GitHub.
Integration Architecture
┌─────────────────────────────────────────────────────────────┐
│ GitHub Integration │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Auth │ │ Repository │ │ Workflow │ │
│ │ Setup │ │ Access │ │ Automation │ │
│ │ │ │ │ │ │ │
│ │ • SSH Keys │ │ • Clone │ │ • Actions │ │
│ │ • Tokens │ │ • Push │ │ • Hooks │ │
│ │ • OAuth │ │ • Pull │ │ • CI/CD │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Collaboration Features │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Issues │ │ Pull Requests│ │ Code Review │ │
│ │ Management │ │ & Merging │ │ Assistance │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘Prerequisites
- GitHub account with appropriate permissions
- Git client installed locally
- GitHub CLI tool (gh) installed
- SSH key generation capability
- Understanding of Git workflows
Procedure
Step 1: Authentication Setup
1.1 SSH Key Configuration
bash
# Generate SSH key for GitHub
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Create GitHub-specific SSH key
ssh-keygen -t ed25519 -C "claude-ai@$(hostname)" -f ~/.ssh/id_github_claude
# Add to SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_github_claude
# Create SSH config for GitHub
cat >> ~/.ssh/config << 'EOF'
# GitHub Configuration for Claude AI
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_github_claude
IdentitiesOnly yes
AddKeysToAgent yes
UseKeychain yes
EOF
chmod 600 ~/.ssh/config
# Display public key for GitHub
echo "📋 Copy this SSH public key to your GitHub account:"
echo "https://github.com/settings/ssh/new"
echo
cat ~/.ssh/id_github_claude.pub1.2 Personal Access Token Setup
bash
# Create secure token storage
mkdir -p ~/.config/claude/github
chmod 700 ~/.config/claude/github
# Token configuration template
cat > ~/.config/claude/github/token-template.txt << 'EOF'
GitHub Personal Access Token Setup
==================================
1. Go to GitHub Settings > Developer settings > Personal access tokens
2. Click "Generate new token (classic)"
3. Set expiration and select scopes:
Required Scopes:
- repo (Full repository access)
- workflow (Update GitHub Action workflows)
- write:packages (Upload packages)
- read:org (Read org membership)
- user:email (Access user email)
Optional Scopes (based on needs):
- admin:repo_hook (Repository webhook admin)
- delete_repo (Delete repositories)
- admin:org (Organization admin)
4. Generate token and save securely
5. Never commit tokens to repositories
EOF
# Secure token storage script
cat > ~/.local/bin/github-token-store << 'EOF'
#!/bin/bash
# GitHub Token Secure Storage
TOKEN_FILE="$HOME/.config/claude/github/token"
BACKUP_DIR="$HOME/.config/claude/github/backups"
store_token() {
read -s -p "Enter GitHub Personal Access Token: " token
echo
# Validate token format
if [[ ! "$token" =~ ^ghp_[a-zA-Z0-9]{36}$ ]]; then
echo "❌ Invalid token format"
return 1
fi
# Create backup if token exists
if [ -f "$TOKEN_FILE" ]; then
mkdir -p "$BACKUP_DIR"
cp "$TOKEN_FILE" "$BACKUP_DIR/token.$(date +%s).bak"
echo "📄 Previous token backed up"
fi
# Store new token
echo "$token" > "$TOKEN_FILE"
chmod 600 "$TOKEN_FILE"
# Test token
if curl -s -H "Authorization: token $token" https://api.github.com/user >/dev/null; then
echo "✅ Token stored and validated successfully"
else
echo "❌ Token validation failed"
rm -f "$TOKEN_FILE"
return 1
fi
}
load_token() {
if [ -f "$TOKEN_FILE" ]; then
export GITHUB_TOKEN=$(cat "$TOKEN_FILE")
echo "✅ GitHub token loaded"
else
echo "❌ No GitHub token found. Run: github-token-store"
return 1
fi
}
case "${1:-help}" in
"store")
store_token
;;
"load")
load_token
;;
"test")
load_token
gh auth status
;;
*)
echo "Usage: $0 [store|load|test]"
echo ""
echo " store Store new GitHub token"
echo " load Load token into environment"
echo " test Test token validity"
;;
esac
EOF
chmod +x ~/.local/bin/github-token-store1.3 GitHub CLI Setup
bash
# Install GitHub CLI (if not already installed)
if ! command -v gh >/dev/null 2>&1; then
echo "Installing GitHub CLI..."
# For Ubuntu/Debian
if command -v apt >/dev/null 2>&1; then
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
# For macOS
elif command -v brew >/dev/null 2>&1; then
brew install gh
else
echo "❌ Please install GitHub CLI manually: https://github.com/cli/cli"
exit 1
fi
fi
# Configure GitHub CLI
echo "🔧 Configuring GitHub CLI..."
# Load token and authenticate
github-token-store load
gh auth login --with-token < ~/.config/claude/github/token
# Verify authentication
gh auth status
# Set default configurations
gh config set editor "nano"
gh config set protocol "https"
gh config set prompt "enabled"Step 2: Repository Management
2.1 Repository Access Script
bash
cat > ~/.local/bin/claude-github-repo << 'EOF'
#!/bin/bash
# Claude GitHub Repository Management
set -euo pipefail
show_help() {
cat << 'EOF'
Claude GitHub Repository Management
Usage: claude-github-repo [COMMAND] [OPTIONS]
Commands:
clone <repo> Clone repository for Claude development
create <name> Create new repository
setup-claude <repo> Setup Claude configuration in repository
list List accessible repositories
status Show repository status
sync Sync with remote repository
Options:
--org <organization> Target organization
--private Create private repository
--template <repo> Use template repository
--branch <name> Target branch
Examples:
claude-github-repo clone myorg/myrepo
claude-github-repo create my-claude-project --private
claude-github-repo setup-claude ./my-project
EOF
}
clone_repo() {
local repo="$1"
local target_dir="${2:-$(basename "$repo")}"
echo "📥 Cloning repository: $repo"
# Clone with SSH
git clone git@github.com:"$repo".git "$target_dir"
cd "$target_dir"
# Setup Claude-specific configuration
setup_claude_config "."
echo "✅ Repository cloned and configured: $target_dir"
}
create_repo() {
local name="$1"
local org="${org:-}"
local private="${private:-false}"
local template="${template:-}"
echo "📝 Creating repository: $name"
local create_args=()
if [ "$private" = "true" ]; then
create_args+=(--private)
else
create_args+=(--public)
fi
if [ -n "$template" ]; then
create_args+=(--template "$template")
fi
# Create repository
if [ -n "$org" ]; then
gh repo create "$org/$name" "${create_args[@]}"
else
gh repo create "$name" "${create_args[@]}"
fi
# Clone the created repository
clone_repo "${org:+$org/}$name"
}
setup_claude_config() {
local repo_dir="$1"
echo "🔧 Setting up Claude configuration..."
# Create .claude directory
mkdir -p "$repo_dir/.claude"
# Create CLAUDE.md if it doesn't exist
if [ ! -f "$repo_dir/CLAUDE.md" ]; then
claude-md-generator "$repo_dir/CLAUDE.md" "$(basename "$repo_dir")" -t advanced
fi
# Create GitHub Actions workflow
mkdir -p "$repo_dir/.github/workflows"
cat > "$repo_dir/.github/workflows/claude-ci.yml" << 'YAML'
name: Claude AI Assisted CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Claude Environment
run: |
echo "Setting up Claude AI environment"
# Add Claude setup steps here
- name: Code Quality Check
run: |
echo "Running Claude-assisted code quality checks"
# Add Claude code analysis steps
- name: Documentation Check
run: |
echo "Verifying documentation completeness"
# Add documentation verification steps
- name: Security Scan
run: |
echo "Running security analysis"
# Add security scanning steps
YAML
# Create GitHub issue templates
mkdir -p "$repo_dir/.github/ISSUE_TEMPLATE"
cat > "$repo_dir/.github/ISSUE_TEMPLATE/claude-assistance.md" << 'EOF'
---
name: Claude AI Assistance Request
about: Request assistance from Claude AI
title: "[CLAUDE] "
labels: claude-ai, assistance
assignees: ''
---
## Request Type
- [ ] Code Review
- [ ] Bug Investigation
- [ ] Feature Implementation
- [ ] Documentation
- [ ] Testing
- [ ] Refactoring
## Description
<!-- Describe what you need assistance with -->
## Context
<!-- Provide relevant context, file paths, etc. -->
## Expected Outcome
<!-- What should Claude help achieve? -->
## Additional Information
<!-- Any other relevant details -->
EOF
# Create PR template
cat > "$repo_dir/.github/pull_request_template.md" << 'EOF'
## Description
<!-- Describe your changes -->
## Claude AI Involvement
- [ ] Code generated with Claude assistance
- [ ] Code reviewed by Claude
- [ ] Documentation updated with Claude
- [ ] Tests written with Claude assistance
## Changes Made
<!-- List the main changes -->
## Testing
<!-- Describe testing performed -->
## Checklist
- [ ] Code follows project standards
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] CLAUDE.md updated if needed
EOF
# Add to .gitignore
if [ ! -f "$repo_dir/.gitignore" ]; then
touch "$repo_dir/.gitignore"
fi
grep -q ".claude/secrets" "$repo_dir/.gitignore" || echo ".claude/secrets" >> "$repo_dir/.gitignore"
grep -q "*.token" "$repo_dir/.gitignore" || echo "*.token" >> "$repo_dir/.gitignore"
echo "✅ Claude configuration setup complete"
}
list_repos() {
echo "📋 Accessible Repositories:"
gh repo list --limit 20
}
sync_repo() {
echo "🔄 Synchronizing with remote repository..."
# Fetch latest changes
git fetch origin
# Show status
git status
# Show unpushed commits
local unpushed=$(git log origin/$(git branch --show-current)..HEAD --oneline | wc -l)
if [ "$unpushed" -gt 0 ]; then
echo "⚠️ You have $unpushed unpushed commits"
git log origin/$(git branch --show-current)..HEAD --oneline
fi
# Show unpulled commits
local unpulled=$(git log HEAD..origin/$(git branch --show-current) --oneline | wc -l)
if [ "$unpulled" -gt 0 ]; then
echo "📥 $unpulled new commits available"
git log HEAD..origin/$(git branch --show-current) --oneline
fi
}
# Parse arguments
org=""
private=false
template=""
branch=""
while [[ $# -gt 0 ]]; do
case $1 in
--org)
org="$2"
shift 2
;;
--private)
private=true
shift
;;
--template)
template="$2"
shift 2
;;
--branch)
branch="$2"
shift 2
;;
clone)
if [ -z "${2:-}" ]; then
echo "❌ Repository name required"
exit 1
fi
clone_repo "$2"
exit 0
;;
create)
if [ -z "${2:-}" ]; then
echo "❌ Repository name required"
exit 1
fi
create_repo "$2"
exit 0
;;
setup-claude)
setup_claude_config "${2:-.}"
exit 0
;;
list)
list_repos
exit 0
;;
status)
sync_repo
exit 0
;;
sync)
sync_repo
exit 0
;;
help|--help|-h)
show_help
exit 0
;;
*)
echo "❌ Unknown command: $1"
show_help
exit 1
;;
esac
done
show_help
EOF
chmod +x ~/.local/bin/claude-github-repoStep 3: Automated Workflows
3.1 Claude-Assisted Code Review Workflow
bash
mkdir -p ~/.config/claude/github/workflows
cat > ~/.config/claude/github/workflows/code-review.yml << 'YAML'
name: Claude Assisted Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
claude-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
echo "files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only origin/${{ github.base_ref }}...HEAD >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Setup Claude Environment
run: |
echo "Setting up Claude for code review"
# Install Claude CLI or setup API access
- name: Code Quality Analysis
run: |
echo "Running Claude-assisted code analysis"
# Analyze code quality with Claude
echo "${{ steps.changed-files.outputs.files }}" | while read file; do
if [ -f "$file" ]; then
echo "Analyzing: $file"
# Run Claude analysis on file
fi
done
- name: Security Review
run: |
echo "Running security analysis"
# Security-focused review with Claude
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Claude AI Review')
);
const reviewComment = `## Claude AI Review Results
### Code Quality
- ✅ Code follows project conventions
- ✅ No obvious bugs detected
- ⚠️ Consider adding more comments for complex logic
### Security
- ✅ No security vulnerabilities detected
- ✅ Input validation appears adequate
### Performance
- ✅ No performance concerns identified
### Suggestions
- Consider adding unit tests for new functionality
- Documentation could be expanded
*This review was generated by Claude AI*`;
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: reviewComment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: reviewComment
});
}
YAML3.2 Documentation Generation Workflow
bash
cat > ~/.config/claude/github/workflows/docs-generation.yml << 'YAML'
name: Claude Documentation Generation
on:
push:
branches: [ main ]
paths: [ 'src/**', 'lib/**', '**.py', '**.js', '**.ts' ]
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Claude Environment
run: |
echo "Setting up Claude for documentation generation"
- name: Generate API Documentation
run: |
echo "Generating API documentation with Claude"
# Use Claude to analyze code and generate docs
- name: Update README
run: |
echo "Updating README with Claude assistance"
# Generate or update README sections
- name: Generate Code Comments
run: |
echo "Adding/updating code comments"
# Use Claude to add meaningful comments
- name: Create Pull Request
if: ${{ github.event_name == 'push' }}
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'docs: Auto-generated documentation updates'
title: 'Auto-generated Documentation Updates'
body: |
## Documentation Updates
This PR contains automatically generated documentation updates:
- 📚 API documentation updated
- 📝 README sections refreshed
- 💬 Code comments added/improved
Generated by Claude AI automation.
branch: docs/auto-update
delete-branch: true
YAMLStep 4: Collaboration Tools
4.1 Issue Management Script
bash
cat > ~/.local/bin/claude-github-issues << 'EOF'
#!/bin/bash
# Claude GitHub Issue Management
set -euo pipefail
create_issue() {
local title="$1"
local body="${2:-}"
local labels="${3:-claude-ai}"
echo "📝 Creating GitHub issue..."
gh issue create \
--title "$title" \
--body "$body" \
--label "$labels"
echo "✅ Issue created successfully"
}
analyze_issues() {
echo "🔍 Analyzing open issues..."
# Get open issues
local issues=$(gh issue list --state open --json number,title,labels,body)
# Analyze with Claude (placeholder)
echo "Open Issues Analysis:"
echo "$issues" | jq -r '.[] | "- #\(.number): \(.title)"'
# Suggest priorities
echo
echo "💡 Suggested Priorities:"
echo "- Review issues with 'bug' label first"
echo "- Consider grouping similar feature requests"
echo "- Update issues missing proper labels"
}
auto_label_issues() {
echo "🏷️ Auto-labeling issues with Claude assistance..."
gh issue list --state open --json number,title,body | jq -r '.[] | "\(.number)|\(.title)|\(.body)"' | while IFS='|' read -r number title body; do
echo "Analyzing issue #$number: $title"
# Simple keyword-based labeling (Claude could enhance this)
labels=()
if echo "$title $body" | grep -qi "bug\|error\|fail\|broken"; then
labels+=("bug")
fi
if echo "$title $body" | grep -qi "feature\|enhance\|improve"; then
labels+=("enhancement")
fi
if echo "$title $body" | grep -qi "document\|readme\|guide"; then
labels+=("documentation")
fi
if [ ${#labels[@]} -gt 0 ]; then
echo " Adding labels: ${labels[*]}"
gh issue edit "$number" --add-label "$(IFS=','; echo "${labels[*]}")"
fi
done
}
case "${1:-help}" in
"create")
create_issue "${2:-'New Issue'}" "${3:-}" "${4:-claude-ai}"
;;
"analyze")
analyze_issues
;;
"auto-label")
auto_label_issues
;;
*)
echo "Usage: $0 [create|analyze|auto-label]"
echo ""
echo " create <title> [body] [labels] Create new issue"
echo " analyze Analyze open issues"
echo " auto-label Auto-label issues based on content"
;;
esac
EOF
chmod +x ~/.local/bin/claude-github-issues4.2 Pull Request Assistant
bash
cat > ~/.local/bin/claude-github-pr << 'EOF'
#!/bin/bash
# Claude GitHub Pull Request Assistant
set -euo pipefail
create_pr() {
local title="$1"
local branch="${2:-$(git branch --show-current)}"
local base="${3:-main}"
echo "🔀 Creating pull request..."
# Generate PR description with Claude assistance
local description="## Description
This pull request includes:
$(git log --oneline "$base..$branch" | sed 's/^/- /')
## Changes Made
$(git diff --stat "$base..$branch")
## Claude AI Involvement
- [ ] Code written with Claude assistance
- [ ] Code reviewed by Claude
- [ ] Tests generated with Claude
- [ ] Documentation updated with Claude
## Testing
- [ ] Manual testing completed
- [ ] Automated tests passing
- [ ] Code review requested
*This PR was created with Claude assistance*"
gh pr create \
--title "$title" \
--body "$description" \
--base "$base" \
--head "$branch"
echo "✅ Pull request created successfully"
}
review_pr() {
local pr_number="$1"
echo "🔍 Reviewing pull request #$pr_number..."
# Get PR details
local pr_data=$(gh pr view "$pr_number" --json files,additions,deletions,title,body)
echo "PR Analysis:"
echo "$pr_data" | jq -r '"Title: \(.title)"'
echo "$pr_data" | jq -r '"Files changed: \(.files | length)"'
echo "$pr_data" | jq -r '"Lines added: \(.additions)"'
echo "$pr_data" | jq -r '"Lines deleted: \(.deletions)"'
# Analyze changed files
echo
echo "📁 Files Analysis:"
gh pr diff "$pr_number" --name-only | while read -r file; do
echo " - $file"
# Add Claude-based analysis here
done
# Generate review suggestions
echo
echo "💡 Review Suggestions:"
echo "- Verify all changes align with PR description"
echo "- Check for proper error handling"
echo "- Ensure tests cover new functionality"
echo "- Validate documentation updates"
}
auto_merge() {
local pr_number="$1"
echo "🔄 Auto-merging pull request #$pr_number..."
# Check if PR is ready to merge
local checks_status=$(gh pr checks "$pr_number" --json state,conclusion)
if echo "$checks_status" | jq -e '.[] | select(.state == "COMPLETED" and .conclusion == "SUCCESS")' >/dev/null; then
echo "✅ All checks passed, proceeding with merge"
gh pr merge "$pr_number" --squash --delete-branch
else
echo "❌ Checks not passed, cannot auto-merge"
echo "Check status:"
echo "$checks_status" | jq -r '.[] | " \(.name): \(.state) (\(.conclusion))"'
fi
}
case "${1:-help}" in
"create")
create_pr "${2:-'Auto-generated PR'}" "${3:-}" "${4:-}"
;;
"review")
if [ -z "${2:-}" ]; then
echo "❌ PR number required"
exit 1
fi
review_pr "$2"
;;
"merge")
if [ -z "${2:-}" ]; then
echo "❌ PR number required"
exit 1
fi
auto_merge "$2"
;;
*)
echo "Usage: $0 [create|review|merge]"
echo ""
echo " create [title] [branch] [base] Create new pull request"
echo " review <pr_number> Review pull request"
echo " merge <pr_number> Auto-merge pull request"
;;
esac
EOF
chmod +x ~/.local/bin/claude-github-prStep 5: Integration Testing
5.1 GitHub Integration Test Suite
bash
cat > ~/.local/bin/claude-github-test << 'EOF'
#!/bin/bash
# Claude GitHub Integration Test Suite
set -euo pipefail
TEST_REPO="claude-integration-test-$$"
TEST_DIR="/tmp/$TEST_REPO"
setup_test() {
echo "🧪 Setting up GitHub integration tests..."
# Create test repository
cd /tmp
gh repo create "$TEST_REPO" --private --clone
cd "$TEST_REPO"
# Setup Claude configuration
claude-github-repo setup-claude .
echo "✅ Test environment created"
}
test_authentication() {
echo "🔐 Testing GitHub authentication..."
# Test SSH connection
if ssh -T git@github.com 2>&1 | grep -q "successfully authenticated"; then
echo " ✅ SSH authentication: OK"
else
echo " ❌ SSH authentication: FAILED"
return 1
fi
# Test CLI authentication
if gh auth status >/dev/null 2>&1; then
echo " ✅ CLI authentication: OK"
else
echo " ❌ CLI authentication: FAILED"
return 1
fi
# Test API access
if gh api user >/dev/null 2>&1; then
echo " ✅ API access: OK"
else
echo " ❌ API access: FAILED"
return 1
fi
}
test_repository_operations() {
echo "📂 Testing repository operations..."
# Test file creation and commit
echo "# Test File" > test.md
git add test.md
git commit -m "Add test file"
if git push origin main >/dev/null 2>&1; then
echo " ✅ Push to repository: OK"
else
echo " ❌ Push to repository: FAILED"
return 1
fi
# Test pull request creation
git checkout -b test-branch
echo "## Test Update" >> test.md
git add test.md
git commit -m "Update test file"
git push origin test-branch
if claude-github-pr create "Test PR" test-branch main >/dev/null 2>&1; then
echo " ✅ Pull request creation: OK"
else
echo " ❌ Pull request creation: FAILED"
return 1
fi
}
test_issue_management() {
echo "🐛 Testing issue management..."
# Test issue creation
if claude-github-issues create "Test Issue" "This is a test issue" "test" >/dev/null 2>&1; then
echo " ✅ Issue creation: OK"
else
echo " ❌ Issue creation: FAILED"
return 1
fi
# Test issue analysis
if claude-github-issues analyze >/dev/null 2>&1; then
echo " ✅ Issue analysis: OK"
else
echo " ❌ Issue analysis: FAILED"
return 1
fi
}
cleanup_test() {
echo "🧹 Cleaning up test environment..."
# Delete test repository
cd /tmp
gh repo delete "$TEST_REPO" --confirm
rm -rf "$TEST_DIR"
echo "✅ Test cleanup completed"
}
run_all_tests() {
echo "🚀 Running GitHub Integration Test Suite"
echo "========================================"
local tests_passed=0
local tests_failed=0
# Setup
if setup_test; then
((tests_passed++))
else
((tests_failed++))
echo "❌ Setup failed, aborting tests"
return 1
fi
# Authentication tests
if test_authentication; then
((tests_passed++))
else
((tests_failed++))
fi
# Repository tests
if test_repository_operations; then
((tests_passed++))
else
((tests_failed++))
fi
# Issue tests
if test_issue_management; then
((tests_passed++))
else
((tests_failed++))
fi
# Cleanup
cleanup_test
echo
echo "📊 Test Results:"
echo "================"
echo "Tests passed: $tests_passed"
echo "Tests failed: $tests_failed"
if [ "$tests_failed" -eq 0 ]; then
echo "🎉 All tests passed!"
return 0
else
echo "❌ Some tests failed!"
return 1
fi
}
# Main execution
trap cleanup_test EXIT
run_all_tests
EOF
chmod +x ~/.local/bin/claude-github-testVerification
Integration Setup Verification
bash
# Test GitHub authentication
github-token-store test
ssh -T git@github.com
# Verify CLI functionality
gh auth status
gh repo list
# Test repository management
claude-github-repo list
claude-github-testWorkflow Testing
bash
# Create test repository
claude-github-repo create test-claude-integration --private
# Test issue management
claude-github-issues create "Test integration" "Testing Claude GitHub integration"
# Test PR workflow
git checkout -b test-feature
echo "test" > test.txt
git add test.txt
git commit -m "Add test file"
claude-github-pr create "Test PR"Troubleshooting
Common Issues
| Issue | Symptoms | Resolution |
|---|---|---|
| SSH authentication failure | Permission denied errors | Check SSH key setup and GitHub configuration |
| Token validation failed | API authentication errors | Verify token permissions and expiration |
| Repository access denied | Clone/push failures | Check repository permissions and collaborator access |
| Workflow permissions | GitHub Actions failures | Verify workflow permissions and secrets |
Debug Commands
bash
# Debug SSH connection
ssh -vT git@github.com
# Test GitHub CLI
gh auth status --show-token
# Check Git configuration
git config --list | grep github
# Test API access
curl -H "Authorization: token $(cat ~/.config/claude/github/token)" https://api.github.com/userRecovery Procedures
bash
# Reset GitHub authentication
gh auth logout
rm -f ~/.config/claude/github/token
github-token-store
# Regenerate SSH keys
rm -f ~/.ssh/id_github_claude*
# Re-run Step 1.1 procedures
# Re-authenticate CLI
gh auth login