fix: Fetch GitHub stats in process to allow timeout#256
Closed
ReenigneArcher wants to merge 5 commits into
Closed
Conversation
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.
21 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #256 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 862 943 +81
=========================================
+ Hits 862 943 +81
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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.
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.
|
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
Checklist
AI Usage