CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ghapi

A python client for the GitHub API

Pending
Overview
Eval results
Files

cli-tools.mddocs/

CLI Tools

Command-line interface tools providing direct GitHub API access from the command line, including endpoint calling, path-based access, and tab completion.

Capabilities

Command Functions

Core CLI functions for GitHub API access.

def ghapi():
    """
    Python backend for the 'ghapi' command.
    Calls GitHub API endpoints by operation name.
    
    Usage from command line:
    ghapi operation.name [arguments] [--option=value]
    """

def ghpath():
    """
    Python backend for the 'ghpath' command.
    Calls GitHub API endpoints by path and HTTP verb.
    
    Usage from command line:
    ghpath /api/path HTTP_VERB [arguments] [--option=value]
    """

def ghraw():
    """
    Python backend for the 'ghraw' command.
    Calls fully-specified GitHub API endpoints.
    
    Usage from command line:
    ghraw /full/api/path [arguments] [--option=value]
    """

def completion_ghapi():
    """
    Python backend for 'completion-ghapi' command.
    Provides tab completion support for ghapi CLI.
    
    Usage from command line:
    completion-ghapi [--install]
    """

Command Line Usage

ghapi Command

Call GitHub API endpoints using operation names in dot notation.

# Basic repository information
ghapi repos.get --owner=octocat --repo=Hello-World

# List issues for a repository
ghapi issues.list_for_repo --owner=octocat --repo=Hello-World --state=open

# Create a new issue
ghapi issues.create --owner=octocat --repo=Hello-World --title="Bug report" --body="Description"

# Get authenticated user information
ghapi users.get_authenticated

# List repositories for authenticated user
ghapi repos.list_for_authenticated_user

# Get repository contents
ghapi repos.get_content --owner=octocat --repo=Hello-World --path=README.md

# List pull requests
ghapi pulls.list --owner=octocat --repo=Hello-World --state=all

# Create a pull request
ghapi pulls.create --owner=octocat --repo=Hello-World --title="New feature" --head=feature-branch --base=main

# List workflow runs
ghapi actions.list_workflow_runs --owner=octocat --repo=Hello-World

# Get organization information
ghapi orgs.get --org=github

# List organization repositories
ghapi repos.list_for_org --org=github --type=public

ghpath Command

Call GitHub API endpoints using HTTP paths and verbs.

# GET requests (default verb)
ghpath /repos/octocat/Hello-World
ghpath /user
ghpath /orgs/github

# Explicit HTTP verbs
ghpath /repos/octocat/Hello-World/issues POST --title="New issue" --body="Issue description"
ghpath /repos/octocat/Hello-World/pulls/1 PATCH --state=closed
ghpath /repos/octocat/Hello-World/issues/1 DELETE

# With query parameters
ghpath "/repos/octocat/Hello-World/issues" --state=open --labels=bug
ghpath "/search/repositories" --q="language:python stars:>1000"

# Path parameters are automatically handled
ghpath /repos/octocat/Hello-World/contents/README.md
ghpath /repos/octocat/Hello-World/git/refs/heads/main

ghraw Command

Make raw HTTP calls to GitHub API endpoints.

# Simple GET requests
ghraw https://api.github.com/repos/octocat/Hello-World
ghraw https://api.github.com/user

# POST requests with data
ghraw https://api.github.com/repos/octocat/Hello-World/issues POST --title="Raw issue" --body="Created via ghraw"

# Custom headers
ghraw https://api.github.com/repos/octocat/Hello-World --headers='{"Accept": "application/vnd.github.v3.raw"}'

# Full URL specification
ghraw "https://api.github.com/search/repositories?q=language:python&sort=stars"

Authentication

All CLI tools use GitHub token authentication via environment variables or command-line options.

# Set token via environment variable
export GITHUB_TOKEN=ghp_your_personal_access_token

# Or pass token as argument
ghapi repos.get --token=ghp_your_token --owner=octocat --repo=Hello-World

# Use JWT token
export GITHUB_JWT_TOKEN=your_jwt_token
ghapi users.get_authenticated

# Debug mode
ghapi repos.get --debug --owner=octocat --repo=Hello-World

Tab Completion

Install and use tab completion for the ghapi command.

# Install tab completion
completion-ghapi --install >> ~/.bashrc
source ~/.bashrc

# Now you can use tab completion
ghapi repos.<TAB>          # Shows available repository operations
ghapi issues.<TAB>         # Shows available issue operations  
ghapi users.get_<TAB>      # Shows user-related get operations

# Completion works for nested operations
ghapi actions.list_<TAB>   # Shows Actions list operations
ghapi pulls.create_<TAB>   # Shows pull request creation operations

Usage Examples

Repository Management

# Get repository information
ghapi repos.get --owner=fastai --repo=ghapi

# List repository branches
ghapi repos.list_branches --owner=fastai --repo=ghapi

# Get repository topics
ghapi repos.get_all_topics --owner=fastai --repo=ghapi

# Create repository (requires auth)
ghapi repos.create_for_authenticated_user --name=new-repo --description="My new repository"

# Update repository
ghapi repos.update --owner=username --repo=repo-name --description="Updated description"

# Delete repository (careful!)
ghapi repos.delete --owner=username --repo=old-repo

Issue Management

# List all issues
ghapi issues.list_for_repo --owner=fastai --repo=ghapi --state=all --per_page=50

# Get specific issue
ghapi issues.get --owner=fastai --repo=ghapi --issue_number=123

# Create issue with labels
ghapi issues.create --owner=username --repo=repo --title="Bug report" --body="Description" --labels='["bug", "high-priority"]'

# Update issue
ghapi issues.update --owner=username --repo=repo --issue_number=123 --state=closed

# Add comment to issue
ghapi issues.create_comment --owner=username --repo=repo --issue_number=123 --body="This is fixed now"

# List issue comments
ghapi issues.list_comments --owner=fastai --repo=ghapi --issue_number=123

Pull Request Operations

# List pull requests
ghapi pulls.list --owner=fastai --repo=ghapi --state=open

# Get specific pull request
ghapi pulls.get --owner=fastai --repo=ghapi --pull_number=456

# Create pull request
ghapi pulls.create --owner=username --repo=repo --title="New feature" --body="Feature description" --head=feature-branch --base=main

# Update pull request
ghapi pulls.update --owner=username --repo=repo --pull_number=456 --title="Updated title"

# Merge pull request
ghapi pulls.merge --owner=username --repo=repo --pull_number=456 --commit_title="Merge feature"

# Request reviewers
ghapi pulls.request_reviewers --owner=username --repo=repo --pull_number=456 --reviewers='["reviewer1", "reviewer2"]'

User and Organization Operations

# Get authenticated user
ghapi users.get_authenticated

# Get user by username
ghapi users.get_by_username --username=octocat

# List user repositories
ghapi repos.list_for_user --username=octocat --type=public --sort=updated

# Get organization
ghapi orgs.get --org=github

# List organization members
ghapi orgs.list_members --org=github --per_page=50

# List organization repositories
ghapi repos.list_for_org --org=github --type=public --sort=stars

Search Operations

# Search repositories
ghapi search.repos --q="language:python stars:>1000"

# Search users
ghapi search.users --q="location:london language:python"

# Search issues
ghapi search.issues --q="repo:fastai/ghapi is:open label:bug"

# Search code
ghapi search.code --q="def main in:file language:python"

# Search commits
ghapi search.commits --q="author:octocat repo:octocat/Hello-World"

GitHub Actions

# List workflows
ghapi actions.list_repo_workflows --owner=fastai --repo=ghapi

# List workflow runs
ghapi actions.list_workflow_runs --owner=fastai --repo=ghapi --per_page=20

# Get workflow run
ghapi actions.get_workflow_run --owner=fastai --repo=ghapi --run_id=123456

# List jobs for workflow run
ghapi actions.list_jobs_for_workflow_run --owner=fastai --repo=ghapi --run_id=123456

# Download workflow run logs
ghapi actions.download_workflow_run_logs --owner=fastai --repo=ghapi --run_id=123456

# Trigger workflow dispatch
ghapi actions.create_workflow_dispatch --owner=username --repo=repo --workflow_id=workflow.yml --ref=main

Release Management

# List releases
ghapi repos.list_releases --owner=fastai --repo=ghapi

# Get latest release
ghapi repos.get_latest_release --owner=fastai --repo=ghapi

# Create release
ghapi repos.create_release --owner=username --repo=repo --tag_name=v1.0.0 --name="Version 1.0.0" --body="Release notes"

# Update release
ghapi repos.update_release --owner=username --repo=repo --release_id=123 --name="Updated release name"

# Delete release
ghapi repos.delete_release --owner=username --repo=repo --release_id=123

# Upload release asset
ghapi repos.upload_release_asset --owner=username --repo=repo --release_id=123 --name=asset.zip

Advanced Usage

# Output JSON for processing
ghapi repos.get --owner=fastai --repo=ghapi | jq '.stargazers_count'

# Pipe data between commands
ghapi repos.list_for_user --username=octocat | jq '.[].name' | head -10

# Use with environment variables
export REPO_OWNER=fastai
export REPO_NAME=ghapi
ghapi repos.get --owner=$REPO_OWNER --repo=$REPO_NAME

# Batch operations with shell scripting
for repo in $(ghapi repos.list_for_user --username=octocat | jq -r '.[].name'); do
    echo "Processing $repo..."
    ghapi repos.get --owner=octocat --repo=$repo
done

# Error handling
if ghapi repos.get --owner=nonexistent --repo=repo 2>/dev/null; then
    echo "Repository exists"
else
    echo "Repository not found"
fi

Install with Tessl CLI

npx tessl i tessl/pypi-ghapi

docs

authentication.md

cli-tools.md

core-api.md

events.md

github-actions.md

index.md

pagination.md

tile.json