Skip to content

fix: add HTTP retries, request timeout, and defensive API parsing in … - #21

Open
shellyco-code wants to merge 1 commit into
eclipse:mainfrom
shellyco-code:fix/api-resilience-and-parsing
Open

shellyco-code wants to merge 1 commit into
eclipse:mainfrom
shellyco-code:fix/api-resilience-and-parsing

Conversation

@shellyco-code

Copy link
Copy Markdown

Fixes #20

Summary of Changes

This PR hardens the data ingestion script in .github/workflows/generate.py against network hangs, transient API failures, and unhandled parsing crashes:

  1. HTTP Retries with Exponential Backoff: Configured requests.Session with urllib3.util.Retry(total=5, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504]) mounted for https:// and http://.
  2. Request Timeout: Added timeout=30 to all session.get() calls to prevent GitHub Actions runners from hanging indefinitely.
  3. Fail-Fast on API Errors: Replaced silent else: break with response.raise_for_status() and added a guard (if not projects: raise RuntimeError(...)) to prevent wiping docs/projects.csv with empty or truncated data on transient errors.
  4. Atomic File Replacement: Data is written to docs/projects.csv.tmp with explicit encoding="utf-8" and swapped atomically using os.replace(), guaranteeing that interruptions never leave a corrupt file.
  5. Defensive Dictionary & Key Parsing:
    • Safely retrieves project.get("github") and validates isinstance(..., dict) before accessing "org".
    • Safely parses project.get("github_repos").
    • Formats github_link cleanly to avoid writing [None](https://github.com/None).
    • Added guard if not s: return "" in escape() to avoid AttributeError on NoneType.
  6. Code Quality & PEP 8: Passed flake8 linting with zero errors and clean query parameters (params={"github_only": 1, ...}).

Verification & Testing

  • Unit Testing: Verified with mock responses that HTTP 500 errors properly raise exceptions without touching the existing CSV, and verified safe handling of null/missing dictionary keys.
  • Live PMI API Test: Executed generate.py against projects.eclipse.org — retrieved all 450 projects across 6 pages and generated 452 rows in docs/projects.csv.
  • MkDocs Build: Ran mkdocs build — static site built in _site/ in 2.17s with zero errors.

Signed-off-by

Signed-off-by: shellyco-code shellyco-code@users.noreply.github.com

…generate.py

Signed-off-by: shellyco-code <shellyco-code@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

fix: add HTTP retries, request timeout, and defensive API parsing in generate.py

1 participant