Skip to content

fix: Fetch GitHub stats in process to allow timeout#256

Closed
ReenigneArcher wants to merge 5 commits into
masterfrom
fix/github-update-2
Closed

fix: Fetch GitHub stats in process to allow timeout#256
ReenigneArcher wants to merge 5 commits into
masterfrom
fix/github-update-2

Conversation

@ReenigneArcher
Copy link
Copy Markdown
Member

@ReenigneArcher ReenigneArcher commented May 17, 2026

Description

Run PyGithub commit-activity retrieval in a separate process so it can be terminated if the library keeps retrying 202 responses. Added a top-level _fetch_stats_commit_activity_with_pygithub helper that constructs a Github client and returns raw week data or None. Switched from ThreadPoolExecutor to ProcessPoolExecutor in _get_stats_with_timeout, submit the helper with repo full name and GITHUB_TOKEN, and call pool.terminate_workers() on timeout. Also stop remapping week.raw_data when writing commitActivity (write the returned raw-data list directly). Updated unit tests to cover the new helper, environment token usage, ProcessPoolExecutor behavior and termination, and added a raise_for_status helper on FakeResponse.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

Run PyGithub commit-activity retrieval in a separate process so it can be terminated if the library keeps retrying 202 responses. Added a top-level _fetch_stats_commit_activity_with_pygithub helper that constructs a Github client and returns raw week data or None. Switched from ThreadPoolExecutor to ProcessPoolExecutor in _get_stats_with_timeout, submit the helper with repo full name and GITHUB_TOKEN, and call pool.terminate_workers() on timeout. Also stop remapping week.raw_data when writing commitActivity (write the returned raw-data list directly). Updated unit tests to cover the new helper, environment token usage, ProcessPoolExecutor behavior and termination, and added a raise_for_status helper on FakeResponse.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c3162f2) to head (4205157).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #256   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          862       943   +81     
=========================================
+ Hits           862       943   +81     
Flag Coverage Δ
Linux 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/updater.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3162f2...4205157. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Convert PyGithub WeeklyStat objects to their raw_data before writing commit activity JSON so stored data is serializable and includes fields like 'days'. Also tweak the _get_stats_with_timeout docstring wording and update unit tests to expect the raw_data format for commit activity.
@ReenigneArcher ReenigneArcher marked this pull request as draft May 17, 2026 16:58
Replace the previous ProcessPoolExecutor + PyGithub timeout trick with a two-step approach: prime GitHub's async stats job via a lightweight requests GET to /stats/commit_activity, then fetch commit activity using repo.get_stats_commit_activity with proper GithubException handling. Add a dedicated _write_commit_activity helper to cache results and only process non-archived repos; update update_github to prime all active repos, process repos, then write commit activity. Remove concurrent.futures usage and related imports, simplify error handling and logging, and update unit tests to match the new priming/fetching flow and behaviors.
Switch commit-activity fetching to use direct HTTP requests and add polling/caching logic. _get_commit_activity now accepts headers and calls helpers.s.get, handling 202 (processing), 204 (empty), 200 (JSON), non-200 responses and JSON decode errors. _write_commit_activity signature changed to accept commit_activity and only write when data exists. Added _update_commit_activity to poll the GitHub stats endpoint with a timeout, progress reporting, and retries before warning on timeout. update_github now uses the new polling function. Corresponding unit tests were updated to reflect the new request/response flow and polling behavior.
Change _get_commit_activity to return (data, status) and handle more HTTP statuses and parse errors explicitly. Add _build_commit_activity_from_commits to synthesize 52-week commit activity from the commits API as a fallback when GitHub stats are not ready or time out. Update _update_commit_activity to collect status counts, show a status summary in the progress output, and use the commits-based fallback for repos that time out. Adjust imports to use timedelta and update unit tests to reflect the new return shapes and fallback behavior.
@sonarqubecloud
Copy link
Copy Markdown

@ReenigneArcher ReenigneArcher deleted the fix/github-update-2 branch May 19, 2026 21:43
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.

1 participant