0PricingLogin
AI Agents · Lesson

Listing and Managing Issues

Fetching, creating, labeling, and closing issues programmatically.

Getting Issues from a Repository

Use repo.get_issues() to list issues. By default it returns open issues; pass state='closed' or state='all' for other states. The result is a PaginatedList — iterate over it to process each issue.

from github import Github
import os

g = Github(token=os.environ['GITHUB_TOKEN'])
repo = g.get_repo('myorg/myrepo')

# Open issues (default)
open_issues = repo.get_issues(state='open')
print(f'Open issues: {open_issues.totalCount}')

# Process first 20
for issue in open_issues[:20]:
    print(f'#{issue.number}: {issue.title}')
    print(f'  Labels: {[l.name for l in issue.labels]}')
    print(f'  Assignee: {issue.assignee.login if issue.assignee else None}')
    print(f'  Created: {issue.created_at.date()}')

Filtering Issues

get_issues() supports several filter parameters: state, labels, assignee, milestone, since, and sort. Combine them to get exactly the issues your agent needs to process.

import datetime
from github import Github
import os

g = Github(token=os.environ['GITHUB_TOKEN'])
repo = g.get_repo('myorg/myrepo')

# Issues with the 'bug' label, sorted by newest
bug_issues = repo.get_issues(
    state='open',
    labels=['bug'],
    sort='created',
    direction='desc'
)

# Issues updated in the last 7 days
cutoff = datetime.datetime.now() - datetime.timedelta(days=7)
recent_issues = repo.get_issues(
    state='open',
    since=cutoff
)

# Issues assigned to a specific user
my_issues = repo.get_issues(
    state='open',
    assignee='username'
)

print(f'Bug issues: {bug_issues.totalCount}')
print(f'Recent issues: {recent_issues.totalCount}')

All lessons in this course

  1. GitHub REST API Overview
  2. Listing and Managing Issues
  3. Automated PR Review Comments
  4. Commit History and Diff Analysis
← Back to AI Agents