validate_actions.globals.web_fetcher

WebFetcher module for GitHub API interaction.

Classes

CachedWebFetcher([session, max_retries, ...])

Implementation of WebFetcher with caching and retry logic.

WebFetcher()

Abstract interface for web fetching.

class validate_actions.globals.web_fetcher.WebFetcher[source]

Bases: ABC

Abstract interface for web fetching.

This interface defines the contract for HTTP clients used throughout the validate-actions tool.

Examples

Basic usage pattern:

>>> fetcher = SomeWebFetcherImplementation()
>>> response = fetcher.fetch('https://example.com/api/data')
>>> if response and response.status_code == 200:
...     data = response.json()
abstractmethod fetch(url)[source]

Fetch a URL and return the HTTP response.

Parameters:

url (str) – The URL to fetch. Should be a valid HTTP/HTTPS URL.

Returns:

The HTTP response object if successful, None if the request failed after all retries or encountered an unrecoverable error.

Return type:

Response | None

class validate_actions.globals.web_fetcher.CachedWebFetcher(session=None, max_retries=3, request_timeout=1, retry_backoff_factor=0.01, github_token=None)[source]

Bases: WebFetcher

Implementation of WebFetcher with caching and retry logic.

This implementation provides robust HTTP fetching with the following features:

  • Response Caching: Successful responses are cached in memory to avoid redundant network requests during a single validation run.

  • Retry Logic: Failed requests are retried with exponential backoff to handle transient network issues.

  • Timeout Handling: Configurable request timeouts prevent hanging on slow or unresponsive servers.

  • Session Reuse: Reuses HTTP connections for better performance when making multiple requests.

This class is specifically designed for fetching GitHub Actions metadata and other external resources needed for workflow validation.

Parameters:
  • session (Session | None)

  • max_retries (int)

  • request_timeout (int)

  • retry_backoff_factor (float)

  • github_token (str | None)

fetch(url)[source]

Fetch a URL with caching and intelligent retry logic.

This method implements a robust HTTP fetching strategy:

  1. Cache Check: First checks if the URL has been fetched before and returns the cached response if available.

  2. HTTP Request: Makes an HTTP GET request with the configured timeout.

  3. Intelligent Retry Logic: Only retries on errors that might be transient: - Network errors (timeouts, connection failures) - Server errors (5xx status codes) - Rate limiting (429 status code)

  4. No Retry on Permanent Errors: Client errors (4xx except 429) indicate permanent issues and are not retried.

  5. Cache Storage: Both successful and permanently failed requests are cached.

Parameters:

url (str) – The URL to fetch. Must be a valid HTTP or HTTPS URL.

Returns:

The HTTP response object if the request succeeded (status 2xx), or None if the request failed permanently or after all retries.

Return type:

Response | None

clear_cache()[source]

Clear all cached HTTP responses.

Return type:

None