Blog

How to Create a GitHub Issue Summarizer with Python and OpenAI

Feeling overwhelmed by long GitHub issue threads? Learn how to build a Python tool to summarize them automatically using the OpenAI API.

Posted on: 2026-03-11 by AI Assistant


If you work on a popular open-source project, you know the pain of long, winding GitHub issue threads. They can span days, involve multiple contributors, and contain a mix of bug reports, suggestions, and off-topic chatter. Getting up to speed can feel like a full-time job.

In this tutorial, you’ll build a Python script that uses the GitHub and OpenAI APIs to automatically summarize any issue thread, giving you the key takeaways in seconds.

The “Why”: The Problem with Information Overload

This tool helps you quickly grasp the current state of an issue so you can contribute more effectively.

Prerequisites: What You Need

The “How”: Building the Summarizer

Step 1: Set Up Your Environment

First, let’s get our environment and dependencies ready.

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate

# Install required libraries
pip install openai requests

Secure your API keys by setting them as environment variables.

export OPENAI_API_KEY='YOUR_OPENAI_KEY'
export GITHUB_TOKEN='YOUR_GITHUB_TOKEN'

Step 2: Fetching the Issue Data

We’ll use the requests library to interact with the GitHub API. We need to fetch the main issue body and all of its comments.

import os
import requests
from openai import OpenAI

def get_issue_data(repo, issue_number):
    """
    Fetches the title, body, and comments for a GitHub issue.
    """
    token = os.environ["GITHUB_TOKEN"]
    headers = {"Authorization": f"token {token}"}
    
    # Get the main issue
    url = f"https://api.github.com/repos/{repo}/issues/{issue_number}"
    issue_response = requests.get(url, headers=headers)
    issue_response.raise_for_status()
    issue_data = issue_response.json()

    # Get the comments
    comments_url = issue_data["comments_url"]
    comments_response = requests.get(comments_url, headers=headers)
    comments_response.raise_for_status()
    comments_data = comments_response.json()

    # Combine all text
    full_text = f"Title: {issue_data['title']}

Body: {issue_data['body']}

"
    for comment in comments_data:
        full_text += f"---
Comment by {comment['user']['login']}:
{comment['body']}

"
        
    return full_text

Step 3: Summarizing with OpenAI

Now that we have the text, we’ll send it to the OpenAI API with a clear prompt asking for a summary.

def summarize_text(text):
    """
    Summarizes the given text using the OpenAI API.
    """
    client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
    
    prompt = f"""
    Please summarize the following GitHub issue thread into a few key bullet points. 
    Focus on the main problem, proposed solutions, and the current status.

    Thread:
    {text}
    """
    
    try:
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "You are a helpful assistant for developers."},
                {"role": "user", "content": prompt}
            ]
        )
        return response.choices[0].message.content
    except Exception as e:
        return f"Error during summarization: {e}"

Step 4: Putting It All Together

Let’s combine these functions into a runnable script. We’ll use a well-known, long issue for our example: a famous one from the Rust repository.

if __name__ == "__main__":
    # Example: A long-standing, famous issue in the Rust repo
    REPO = "rust-lang/rust"
    ISSUE_NUMBER = 27060 

    print(f"Fetching issue {REPO}#{ISSUE_NUMBER}...")
    try:
        issue_thread = get_issue_data(REPO, ISSUE_NUMBER)
        
        print("
Summarizing thread... (This might take a moment)")
        summary = summarize_text(issue_thread)
        
        print("
--- Summary ---")
        print(summary)
        print("---------------")

    except requests.exceptions.HTTPError as e:
        print(f"Error fetching from GitHub: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

Run the script (python issue_summarizer.py), and you’ll get a concise summary of a massive thread, saving you hours of reading!

What’s Next?

This simple tool can be a huge productivity booster. Consider these enhancements: