Skip to content

Add script: merged PR count per author aggregated by week over the past year#97

Merged
sdpython merged 15 commits intomainfrom
copilot/add-merged-prs-weekly-report
Apr 24, 2026
Merged

Add script: merged PR count per author aggregated by week over the past year#97
sdpython merged 15 commits intomainfrom
copilot/add-merged-prs-weekly-report

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

Creates a standalone Python script that queries the GitHub REST API for merged PRs on one or more repositories, aggregates the results by author and ISO week over the trailing 365 days, and saves the visualisations as PNG images. Fetched data is cached locally to minimise repeated API calls.

New: _doc/practice/years/2026/github_stat_pr.py

  • Fetch with cache — on each run, loads a per-repo CSV cache (prs_cache_{owner}_{repo}.csv); only fetches PRs merged after the latest cached date from the API (full fetch on first run); merges new rows with the cache, deduplicates, prunes entries older than 365 days, and saves the updated cache. A CACHE_DIR parameter (default ".") controls where the files are stored.
  • Author whitelist — an AUTHOR_WHITELIST parameter (default []) lets you restrict the analysis to a specific set of GitHub usernames; leave it empty to include all authors. The whitelist applies only to the per-author bar and heatmap charts; the cross-repo line chart always reflects all authors.
  • Aggregate — pandas groupby on (repo, author, week) where week is the Monday of each ISO week; produces a combined pivot table (all repos summed, authors ranked by total PR count) as well as per-repo pivot tables when multiple repos are listed.
  • Visualise (combined) — stacked bar chart (week on x-axis, colour per author) + imshow heatmap (author × week) aggregated across all repos; saved as github_stat_pr_bar.png and github_stat_pr_heatmap.png.
  • Visualise (cross-repo line chart) — when multiple repos are listed, a line chart with one line per repo is produced; authors are fully aggregated (all contributors, unaffected by the whitelist) so each line shows the true total weekly merged PR count for that repo, making activity differences between repos immediately visible; saved as github_stat_pr_lines.png.
  • Visualise (per repo) — when multiple repos are listed, an additional stacked bar chart and heatmap are saved for each individual repo (github_stat_pr_bar_{owner}_{repo}.png, github_stat_pr_heatmap_{owner}_{repo}.png), with the repo name included in the chart title.
  • Error handling — raises descriptive RuntimeError for HTTP 401 (bad token), 403 (rate-limited), and 404 (repo not found).
# Customise the list of repos and cache directory at the top of the script
REPOS = [
    ("sdpython", "teachpyx"),
    # ("sdpython", "onnx-extended"),  # add as many as needed
]
CACHE_DIR = pathlib.Path(".")  # directory where prs_cache_*.csv files are stored
AUTHOR_WHITELIST: list[str] = []  # e.g. ["xadupre", "sdpython-bot"] — empty = all authors
# Optional: export GITHUB_TOKEN=ghp_xxxx

Run with:

export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx  # optional but recommended
python github_stat_pr.py

New: _doc/practice/years/2026/github_stat_pr.rst

Documentation page with a literalinclude of the script, keeping the toctree entry in index.rst functional.

Updated: _doc/practice/years/2026/index.rst

Added github_stat_pr to the toctree.

Copilot AI changed the title [WIP] Add notebook to report merged PRs per person weekly Add notebook: merged PR count per author aggregated by week over the past year Apr 24, 2026
Copilot AI requested a review from xadupre April 24, 2026 07:47
Comment thread _doc/practice/years/2026/github_stat_pr.ipynb Outdated
Copilot AI requested a review from xadupre April 24, 2026 07:55
Comment thread _doc/practice/years/2026/github_stat_pr.ipynb Outdated
Comment thread _doc/practice/years/2026/github_stat_pr.ipynb Outdated
Comment thread _doc/practice/years/2026/github_stat_pr.ipynb Outdated
Comment thread _doc/practice/years/2026/github_stat_pr.ipynb Outdated
@xadupre
Copy link
Copy Markdown
Collaborator

xadupre commented Apr 24, 2026

@copilot can you replace this by a script outputting images (not a notebook)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 24, 2026

@copilot can you replace this by a script outputting images (not a notebook)

Done in f0e2806. The notebook has been replaced by github_stat_pr.py — a standalone Python script that uses plt.savefig() to write PNG images to disk instead of displaying them interactively. A companion github_stat_pr.rst page (with a literalinclude of the script) keeps the toctree entry working.

Output files produced when running python github_stat_pr.py:

  • github_stat_pr_bar.png — stacked bar chart (all repos combined)
  • github_stat_pr_heatmap.png — heatmap (all repos combined)
  • github_stat_pr_bar_{owner}_{repo}.png — per-repo bar chart (when len(REPOS) > 1)
  • github_stat_pr_heatmap_{owner}_{repo}.png — per-repo heatmap (when len(REPOS) > 1)

Copilot AI changed the title Add notebook: merged PR count per author aggregated by week over the past year Add script: merged PR count per author aggregated by week over the past year Apr 24, 2026
Comment thread _doc/practice/years/2026/github_stat_pr.py
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 24, 2026

@copilot can you replace this by a script outputting images (not a notebook)

Already done in f0e2806 — the notebook was replaced by github_stat_pr.py, a standalone Python script that saves all charts as PNG files via plt.savefig().

@xadupre xadupre marked this pull request as ready for review April 24, 2026 10:43
@sdpython sdpython merged commit 6b54d4c into main Apr 24, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

créer un notebook qui récupèrer le nombre de PR fusionnés par une personne agrégrées par semaine sur l'année écoulée

3 participants