hacs / integration

HACS gives you a powerful UI to handle downloads of all your custom needs.
https://hacs.xyz
MIT License
4.88k stars 1.23k forks source link

Use GraphQL to generate release content #3848

Closed ludeeus closed 3 days ago

ludeeus commented 3 days ago

Attempt 2...

3841 had to be reverted (in #3846) because of an issue with releases that were not latest, and not draft/pre.

That information was not in the REST API, so this had to be changed to using GraphQL...

coderabbitai[bot] commented 3 days ago
Walkthrough ## Walkthrough The changes primarily introduce a `prerelease` attribute to various components within the HACS module, enhancing the repository handling and validation processes. Exception handling and string formatting have been refactored for better readability and maintainability. Several test scripts and snapshot files have been updated to reflect these changes, with new test cases ensuring robustness and accuracy in data handling, especially focusing on handling pre-release information and improving data validation. ## Changes | Files/Modules | Change Summary | | --- | --- | | `custom_components/hacs/repositories/base.py` | Added `prerelease` attribute to `RepositoryData` class, improved exception handling, and string formatting. | | `custom_components/hacs/utils/data.py` | Introduced the `prerelease` attribute to the data structure and updated accordingly in `async_restore_repository` method. | | `custom_components/hacs/utils/validate.py` | Added optional `prerelease` field to the `validate_version` function. | | `scripts/data/generate_category_data.py` | Modified GraphQL query structure, repository data handling, and error validation, refactoring logic for better data retrieval. | | `tests/output/proxy_calls.json` | Added new GitHub API endpoint URLs for category data generation tests. | | `tests/scripts/data/test_generate_category_data.py` | Adjusted file handling and added new test function for generating category data with prior content. | | `tests/snapshots/diagnostics/base.json` | Introduced `prerelease` field with `null` value. | | `tests/snapshots/diagnostics/exception.json` | Added `prerelease` field with `null` value in the HACS software package JSON object. | | `tests/snapshots/.../integration/data.json` | Added new repository entries with various attributes. | | `tests/snapshots/.../integration/repositories.json` | Included two new repositories. | | `tests/snapshots/.../integration/summary.json` | Added fields related to rate limits for core and GraphQL APIs. |

[!TIP]

AI model upgrade ## `gpt-4o` model for reviews and chat is now live OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our [Discord Community](https://discord.com/invite/GsXnASn26c) to provide any feedback or to report any issues.

Recent review details **Configuration used: CodeRabbit UI** **Review profile: ASSERTIVE**
Commits Files that changed from the base of the PR and between 1d5e9a67964ae405e10185fb867c4d30f48ad782 and 4a9f3b98fc26e752d690a66fbba09bace7348d61.
Files selected for processing (11) * custom_components/hacs/repositories/base.py (10 hunks) * custom_components/hacs/utils/data.py (3 hunks) * custom_components/hacs/utils/validate.py (1 hunks) * scripts/data/generate_category_data.py (8 hunks) * tests/output/proxy_calls.json (1 hunks) * tests/scripts/data/test_generate_category_data.py (3 hunks) * tests/snapshots/diagnostics/base.json (1 hunks) * tests/snapshots/diagnostics/exception.json (1 hunks) * tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/data.json (1 hunks) * tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/repositories.json (1 hunks) * tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/summary.json (1 hunks)
Additional context used
Path-based instructions (6)
tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/repositories.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/summary.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
tests/snapshots/scripts/data/generate_category_data_with_prior_content/integration/data.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
tests/snapshots/diagnostics/exception.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
tests/snapshots/diagnostics/base.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
tests/output/proxy_calls.json (1) Pattern `tests/**/*.json`: Never suggest changes to the JSON files located under the tests directory
Additional comments not posted (19)
custom_components/hacs/utils/validate.py (1)
`121-121`: **Change Approved: Added `prerelease` field.** The addition of the `prerelease` field to the validation schema looks good.
tests/scripts/data/test_generate_category_data.py (3)
`60-60`: **Change Approved: Added snapshot validation for summary data.** The addition of snapshot validation for summary data looks good and ensures consistency. --- `99-105`: **Change Approved: Added snapshot validation for summary data.** The addition of snapshot validation for summary data looks good and ensures consistency. --- `107-185`: **Change Approved: Added test case for generating category data with prior content.** The new test case for handling prior content is comprehensive and covers various scenarios, including mocking GraphQL responses.
custom_components/hacs/utils/data.py (3)
`50-50`: **Change Approved: Added `prerelease` field to exported repository data.** The addition of the `prerelease` field to the exported repository data looks good. --- `293-293`: **Change Approved: Added `prerelease` field to restored repository data.** The addition of the `prerelease` field to the restored repository data looks good. --- `306-307`: **Change Approved: Added logic to handle `prerelease` field during repository restoration.** The logic to handle the `prerelease` field during the repository restoration process looks good.
scripts/data/generate_category_data.py (4)
`60-86`: **Change Approved: Added GraphQL query for fetching release information.** The addition of the GraphQL query for fetching release information looks good. --- `195-195`: **Change Approved: Added initialization for `HacsDataClient`.** The initialization of `HacsDataClient` looks good and is necessary for the new functionality. --- `238-292`: **Change Approved: Updated `concurrent_update_repository` to use GraphQL for fetching release data.** The update to use GraphQL for fetching release data looks good and improves the accuracy of the data retrieval process. --- Line range hint `456-513`: **Change Approved: Added logic to validate and store fetched data.** The added logic to validate and store the fetched data ensures data integrity and consistency.
custom_components/hacs/repositories/base.py (7)
`117-117`: **Change approved: Added `prerelease` to `REPOSITORY_KEYS_TO_EXPORT`.** The addition of the `prerelease` attribute is consistent with the PR objectives and appears necessary for the intended functionality. --- `169-169`: **Change approved: Added `prerelease` to `RepositoryData` class.** The addition of the `prerelease` attribute to the `RepositoryData` class aligns with the PR objectives and is necessary for the intended functionality. --- `574-578`: **Change approved: Improved exception handling in `download_zip_files` method.** The improved exception handling by catching `BaseException` and logging the error enhances robustness. --- `617-618`: **Change approved: Improved exception handling in `async_download_zip_file` method.** The improved exception handling by catching `BaseException` and logging the error enhances robustness. --- `727-728`: **Change approved: Improved exception handling in `async_get_hacs_json` method.** The improved exception handling by catching `BaseException` and logging the error enhances robustness. --- `829-830`: **Change approved: Improved exception handling in `remove_local_directory` method.** The improved exception handling by catching `BaseException` and logging the error enhances robustness. --- `1283-1284`: **Change approved: Improved exception handling in `dowload_repository_content` method.** The improved exception handling by catching `BaseException` and logging the error enhances robustness.
tests/output/proxy_calls.json (1)
`1255-1270`: **Verify the accuracy of the added API endpoints.** The new test case `test_generate_category_data_with_prior_content[category_test_data0]` and its associated API endpoints have been added. Ensure these endpoints are correct and relevant to the test case.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.