Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Masterain98
Copy link
Member

This pull request introduces a new issue reporting API and improves logging and error handling in the avatar strategy refresh logic. It also updates a submodule reference. The most important changes are grouped below:

New Issue Reporting API:

  • Added a new routers/issue.py module that provides /issue/bug endpoints for China, Global, and Fujian routers. These endpoints fetch open "Bug" issues from GitHub, cache results in Redis, and return summarized issue details and statistics.
  • Registered the new issue routers with the respective root routers in main.py, enabling access to the new endpoints.
  • Imported the new issue router module in main.py.

Avatar Strategy Logic Improvements:

  • Added info and error logging when processing avatar strategies in routers/strategy.py, making it easier to trace and debug avatar ID resolution. [1] [2] [3]
  • Improved cache miss handling for avatar strategies by dynamically importing and calling refresh_avatar_strategy from cloudflare_security_utils.mgnt when needed. [1] [2]

Submodule Update:

  • Updated the cloudflare_security_utils submodule to a newer commit, potentially bringing in upstream improvements or fixes.

@Masterain98 Masterain98 merged commit 2982d1d into main Sep 24, 2025
@dgp-bot
Copy link

dgp-bot bot commented Sep 24, 2025

## PR Summary

This PR, authored by Masterain, includes updates to the strategy router and introduces a new issue router to fetch and display GitHub issues.

## Changes by feature

<details>
  <summary>Strategy Router Updates (routers/strategy.py)</summary>

  - **Logging Improvements:** Added logging to track avatar processing and errors during strategy refresh from Miyoushe and Hoyolab.
  - **Error Handling:** Improved error logging for avatar ID retrieval failures.
  - **Redis Usage:** Modified the logic to refresh avatar strategies from Cloudflare when a TypeError occurs during Redis data loading.
</details>

<details>
  <summary>Issue Router (routers/issue.py, main.py)</summary>

  - **New Feature:** Implemented a new API endpoint to retrieve open bug issues from GitHub.
  - **Caching:** Integrated Redis caching to store and serve issue data, reducing GitHub API calls.
  - **Data Processing:** Added functions to prune unnecessary fields from the GitHub API response and calculate bug statistics based on labels.
  - **Bug Statistics:** The API now returns statistics on bug issues, including counts for "waiting_for_release", "untreated", and "hard_to_fix" issues.
  - **Filtering:** Enhanced issue filtering to focus on bug-related issues, exclude pull requests, and categorize issues based on labels.
</details>

## Key Change Highlights

- **Introduction of Issue Router:** A new router (`routers/issue.py`) is added to fetch and display open bug issues from the Snap.Hutao GitHub repository. This introduces a new dependency on the `httpx` library for making HTTP requests.
- **Strategy Refresh Logic:** The logic to refresh avatar strategies has been modified. Now, instead of calling `refresh_avatar_strategy` from `cloudflare_security_utils.mgnt` directly, it imports the function within the `try` block to resolve potential `TypeError` issues, possibly related to Redis data loading.
- **Data Structure and API Endpoint:** The `/issue/bug` endpoint now returns a structured response containing both issue details and statistics, which are calculated based on issue labels. This change affects how clients consume the API response.

## Suggested Test Methods

- **API Endpoint Tests for `/issue/bug`:**
  - Verify that the endpoint returns a `200 OK` status code.
  - Ensure that the response body contains both `details` (list of issues) and `stat` (bug statistics) keys.
  - Check that the issue details are correctly pruned to include only the required fields (`number`, `title`, `labels`, `author`, `created_at`).
  - Confirm that the bug statistics are calculated correctly based on the issue labels (e.g., "waiting_for_release", "untreated", "hard_to_fix").
  - Test the endpoint with different network conditions to ensure it handles `httpx.HTTPError` exceptions gracefully.
  - Mock the GitHub API to test different scenarios, such as empty responses or error responses.
- **Redis Caching Tests:**
  - Verify that the issue data is cached in Redis after the first request.
  - Ensure that subsequent requests are served from the cache until the cache expires.
  - Check that the cache is properly updated when new issues are added or existing issues are modified in the GitHub repository.
  - Test the cache invalidation logic when the `refresh_avatar_strategy` function is called.
- **Unit Tests for Helper Functions:**
  - Create unit tests for the `_prune_issue_fields` function to ensure it correctly filters and transforms the GitHub API response.
  - Write unit tests for the `_calc_bug_stats` function to verify that it accurately calculates bug statistics based on different label combinations.
- **Integration Tests:**
  - Test the integration between the issue router and the Redis cache to ensure that data is properly cached and retrieved.
  - Verify that the issue router correctly handles errors from the GitHub API and returns an appropriate error response to the client.

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