Skip to content

About

Read-only GitHub API integration reporting public pull request outcomes as Markdown or JSON.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

GitHub Contribution Report

Tests

A small command-line GitHub API integration that reports a developer's public authored pull requests. It answers a recurring contribution-tracking question: which changes were merged, which remain open, and which were closed without merge? Reports are printed or saved as Markdown, JSON or CSV for use in local records or a manually maintained portfolio.

See a real public contribution report generated on September 23, 2026. This is a dated snapshot; run the command below to check current pull request states.

Requirements and setup

  • Python 3.10 or later; no Python packages to install.
  • GitHub CLI installed and authenticated to GitHub.com using gh auth login --hostname github.com.

Clone this repository, then run the script from its directory:

python3 contribution_report.py Doribelove
python3 contribution_report.py Doribelove --format json --output contributions.json
python3 contribution_report.py Doribelove --format csv --output contributions.csv
python3 contribution_report.py Doribelove --include-own --output contributions.md
python3 contribution_report.py Doribelove --state open
python3 contribution_report.py Doribelove --state merged
python3 contribution_report.py Doribelove --updated-since 2026-11-01
python3 contribution_report.py Doribelove --updated-since 2026-11-01 --state open
python3 contribution_report.py Doribelove --merged-since 2026-11-01 --merged-before 2026-12-01
python3 contribution_report.py Doribelove --repo pydata/sparse
python3 contribution_report.py Doribelove --repo Doribelove/github-contribution-report --include-own
python3 contribution_report.py Doribelove --gh /path/to/gh

The default report includes public PRs to repositories owned by other accounts or organizations. --include-own also includes the author's personal repositories and labels them own. Ownership comparison is case-insensitive. Organization membership and project independence are not inferred: a repository owned by an organization is categorized as external, even if the author belongs to it. Destination repositories that are forks retain an explicit isFork field.

Save reports safely

Use --output PATH to save a report without clearing the previous file if an API request or export fails. Both scripts first generate the complete result, write UTF-8 to a temporary file in the destination directory, then replace the output file. Successful file exports leave stdout empty. Omitting --output continues to print the report to stdout.

The parent directory must already exist. Symbolic-link destinations are rejected; the comparison script also rejects either input snapshot as its output. Saved files take the temporary file's permissions rather than preserving the old file's permissions. Replacement is atomic on filesystems that support atomic rename; this is not a guarantee against data loss during a power failure.

UTF-8 export

File exports and stdout use UTF-8, including systems with a legacy locale. Chinese characters and emoji are preserved without changing Python's encoding settings. For example, in Windows Command Prompt (cmd.exe):

python contribution_report.py Doribelove --format json --output contributions.json
python contribution_report.py Doribelove --output contributions.md

Open the exported files as UTF-8 in your editor. An interactive terminal also needs a font and encoding that can display the reported characters.

Spreadsheet export

--format csv writes one row per selected PR with stable column names, including repository, number, title, URL, state, draft/review status, ownership relationship, fork status and timestamps. All report filters apply. An empty selection writes the header only; API errors write no CSV. Import the file as UTF-8 in your spreadsheet application.

Commas, quotes and embedded newlines are quoted using standard CSV rules. Formula-like cells are prefixed with an apostrophe so spreadsheet applications treat titles as text. Use JSON when you need the exact original metadata and the report's scope, generation time and summary counts.

Compare saved snapshots

Export two JSON reports with the same author and filters, then compare their PR membership, review decisions, draft status and merge state offline:

python3 compare_reports.py before.json after.json
python3 compare_reports.py before.json after.json --format json --output changes.json

The result separates added, removed, changed and unchanged PRs and preserves before/after values. A removed row means it is absent from the later snapshot; use full-history reports to observe merge transitions directly. See the snapshot comparison guide for export commands, matching filters and output details. Comparison needs no GitHub authentication.

What the report means

  • MERGED counts as merged; CLOSED counts as closed without merge.
  • Draft PRs are counted within open PRs and also summarized separately.
  • --state open, --state merged, or --state closed filters the displayed rows and counts after fetching all public authored PRs. closed means closed without merge. The public_authored_total and own_repository_total fields still describe all fetched PRs, before either state or ownership filtering. A filter with no matches produces an empty report.
  • --repo OWNER/NAME limits the API search to one destination repository. public_authored_total and own_repository_total then describe that repository's search results, before state or ownership filtering. The normal external-only default still applies, so use --include-own for a repository owned by the author.
  • Each PR includes its URL, title, number, state, draft status, merge/update times, review decision, repository ownership, and fork status.
  • Public authored PR totals and own-repository totals describe all fetched PRs; the counts and pull_requests fields use the selected report scope.
  • An empty search produces an empty report. It does not verify that the username exists. GitHub search indexing may lag behind a recent change.

Recent activity

--updated-since YYYY-MM-DD searches for PRs whose last update is at or after 00:00:00 UTC on that date, including the boundary. It uses GitHub's updated search qualifier before pagination, and can be combined with --repo, --state and --include-own. Invalid calendar dates, timestamps and query fragments are rejected before any API request. Omitting the option preserves the full-history search.

The scope and all totals describe the date-limited search: they are not lifetime totals. This selects recently updated PRs, not individual activity events or only PRs merged during the period. For example, an older merged PR with a recent comment may appear with --state merged. The report shows the current state; it does not reconstruct the state at the selected date. Dates use UTC rather than your computer's local time zone.

Merges during a reporting period

Use --merged-since YYYY-MM-DD and --merged-before YYYY-MM-DD to report PRs by their merge date. The start includes midnight UTC; the end excludes midnight UTC. For example, the November command above selects merges from November 1 through November 30. Either boundary can be used on its own.

These options use GitHub's merged search qualifier before pagination, so totals describe the selected merge period. Older merges with recent comments stay outside that period. Repository, ownership and update filters can be combined with it; --state open and --state closed are rejected because they cannot match a merge period. The report is still a current snapshot and GitHub search indexing can lag behind a merge.

The tool uses the GitHub GraphQL search API through gh api graphql, requesting up to 100 PRs per page. It follows cursors and checks that all reported search results were fetched. GitHub search exposes at most 1,000 results for the selected query: larger result sets cause an explicit error, not a misleading partial report. Repository, update-date or merge-date filters can narrow that search. Changed counts, duplicate results, or stalled pagination also fail with a retry message. Pagination is not a transactional snapshot; PR metadata can change during a run.

Data handling

Only public PR metadata is requested, always from github.com, including when GH_HOST is set to a different host. GitHub CLI manages authentication; this script never reads or stores credentials. No shell commands are constructed from user input. No report is uploaded or published, and no scheduler is installed. Output is emitted only after all pages succeed. With --output, API and file-write failures leave an existing report intact; shell > redirection clears its target before the script starts. Errors go to stderr with exit status 1; invalid arguments use argparse's exit status 2. Raw CLI output is not echoed on API failures, so use gh auth status separately for diagnostics. Both scripts flush stdout before reporting success. A closed pipe or a failed redirected write produces a concise stderr error and exit status 1.

Development

Run the standard-library test suite without network access:

python3 -m unittest -v

The same suite runs automatically on every push and pull request. The workflow checks Python 3.10–3.15 on Linux and Python 3.10/3.15 on Windows, including actual subprocess tests for redirected Unicode output. It needs no GitHub CLI login, API credentials or third-party Python packages. A manual run is also available from the repository's Actions tab.

Tests mock GitHub CLI transport and cover pagination, the search cap, empty results, incomplete results, repository and ownership filtering, state counts, API failures, input validation, date-filter combinations, Unicode titles across system locales, CSV quoting and spreadsheet text protection, snapshot validation and comparison, Markdown escaping, file preservation during failed exports, and stdout write/flush failures with real subprocess pipes.

Support: [email protected]. Bug reports with a minimal reproduction are welcome; do not include credentials or private data.

AI assistance: the initial implementation, tests, and documentation were prepared with Codex. Test results should be checked before relying on a report.

Licensed under the MIT License. This is an independent integration and does not claim affiliation with GitHub or award GitHub profile achievements.

About

Read-only GitHub API integration reporting public pull request outcomes as Markdown or JSON.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages