Back to GitHub Projects
    Open Source · Python

    GitHub PR Summary

    A Python script that emails a weekly HTML table of a repository's new pull requests, with title, state, author, date and link, fetched from the GitHub REST API.

    PythonGitHub APIAutomation
    View on GitHub
    GitHub PR Summary Architecture

    About

    GitHub PR Summary is a single Python script for a team lead who wants one weekly email of new pull requests, instead of watching GitHub notifications. It calls the GitHub REST API for the repository's pull requests and keeps the ones created in the last seven days. A Jinja2 template turns them into an HTML table, and the script sends it over SMTP with STARTTLS. If nothing was opened that week, it sends nothing. Every setting comes from a .env file: the token, the repository, the SMTP server and the recipient.

    How it works

    index.py loads the .env file and sends one GET request to /repos/{owner}/{repo}/pulls with state=all, sorted by creation date, newest first. Each pull request created in the last seven days goes into a list. Jinja2 renders that list into template.html, and the script wraps it in a MIME message titled "PRs Summary for owner/repo" and sends it after STARTTLS and an SMTP login.

    There is no scheduler inside the script. Run it weekly from cron, from a scheduled GitHub Actions workflow, or from any job runner you already have. The GitHub token only needs read access to pull requests on the target repository.

    Limits worth knowing

    It reads one page of results. The API returns 30 pull requests per page by default, and the script does not follow pagination. A repository that opens more than 30 in a week gets cut off. It counts pull requests created in the window, not ones merged or closed in it, so a long-running pull request that closes this week does not appear.

    Each row shows the state GitHub reports, open or closed. It does not mark drafts separately or tell a merge from a close without merging. The repository has no tests yet, and the SMTP login needs a password, often an app password, in the .env file.

    Key Features

    Lists every pull request created in the last 7 days, open or closed
    One row per pull request: title, state, author, creation date and link
    HTML email built from an editable Jinja2 template (template.html)
    SMTP with STARTTLS, port 587 by default, so it works with most mail providers
    Sends nothing when the week had no new pull requests
    Token, repository, SMTP host and port, sender and recipient all set in a .env file
    Pins the GitHub REST API version (2022-11-28) and sets a 5 second request timeout
    Pylint runs in GitHub Actions on every push, against Python 3.8, 3.9 and 3.10

    Engineering Challenges

    Finding last week's pull requests in a list the API returns in pages. The script asks for newest first (sort=created, direction=desc), so the past week sits at the top.
    Keeping the email readable in any mail client, which is why the template is a plain HTML table with no scripts.
    Not mailing an empty report. The send step only runs when the filtered list has entries.
    Keeping secrets out of the code. The token and the SMTP password come from the environment.

    Results & Impact

    A weekly digest of new pull requests with no dashboard to open.
    Runs anywhere Python runs: a laptop, a cron job or a scheduled CI workflow.
    Changing what the email shows means editing one HTML template.