hacs / integration

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

fix: github action will miss ref and use default branch #3822

Open wuwentao opened 6 days ago

wuwentao commented 6 days ago

Issue:

we want to migrate a domain name, PR: https://github.com/wuwentao/midea_ac_lan/pull/159 PR submit from fork repo with different branch name.

github action uses hacs/action@main to verify PR it only return “Error: Not Found” no any ERROR log or step output in debug mode.

after fork it and add too many log info to print the step and args, found it caused by ref args miss:

  1. action.py run hacs.async_register_repository() with ref args
  2. async_register_repository defined in custom_components/hacs/base.py line 562, it call await repository.async_registration(ref), also include ref args
  3. and repository.async_registration(ref) defined in custom_components/hacs/repositories/base.py, in line 842, it call self.validate_repository() without refargs, but self.ref is available
  4. validate_repository() defined in custom_components/hacs/repositories/integration.py, in line 73, it call common_validate in custom_components/hacs/repositories/base.py, and it will run this line if manifest := await self.async_get_hacs_json():, it missed ref args, so add arg: ref=self.ref to fix it.
  5. but it will not return error during domain rename, as it using default branch hacs.json. it check pass, continue the remaining jobs, in custom_components/hacs/repositories/integration.py after line 73 in validate_repository().
  6. error found in line 94: if manifest := await self.async_get_integration_manifest(): , also missed ref args and use default branch value.
  7. in async_get_integration_manifest, as there is domain rename and dir rename, default branch don't have this dir and mainfest.json, it continue using default branch and call response = await self.hacs.async_github_api_method() in line 183
  8. async_github_api_method() definded in custom_components/hacs/base.py line 492, and try job can't pass with a exception: Not Found, so only print this error log.

checked with the same async_get_integration_manifest and async_get_hacs_json, add ref=self.ref to run it in normal branch and action.

issue fixed.

in addtion, also remove some minior error , like duplicate ## comments, remove from .utils.json import json_loads as import but not used.

please help to review and confirm whether it's the expect result.

github action error log: https://github.com/wuwentao/midea_ac_lan/actions/runs/9672246348/job/26686312538

after add the ref args fix, it can report the expect ERROR log as below: https://github.com/wuwentao/midea_ac_lan/actions/runs/9672246348/job/26687155544

Thanks

ludeeus commented 6 days ago

Protip: do NOT change the domain. This will cause you a lot of issues. This is not even being done inside of core because of it.

wuwentao commented 6 days ago

Protip: do NOT change the domain. This will cause you a lot of issues. This is not even being done inside of core because of it.

Thanks, it's really not a good choice, as the old domain owner not maintain it now, we want to work with a new domain, this domain migrate just want to save exist old user configs/entiries/devices.

if we drop it, old integration can't works in new HA, also no any bug fix, and they should start from zero with all the old configs and device history.

so we want to have a try, test it and confirm it what we can do, we have finished some config_entries/device_entries update in new domain, but still under test.

found this hacs/action failed and try to fix it.

ludeeus commented 6 days ago

@coderabbitai review

coderabbitai[bot] commented 6 days ago
Walkthrough ## Walkthrough The changes update comment formatting and adjust method parameters for better code readability and functionality in a variety of modules within the HACS (Home Assistant Custom Component Store) project. Additionally, some minor code tidying and bug fixes are made, such as correcting typos in error messages and enhancing exception handling. ## Changes | File(s) | Change Summary | |---------|----------------| | `action/action.py`, `custom_components/hacs/__init__.py` | Updated comments from double `##` to single `#` for readability. | | `custom_components/hacs/base.py` | Removed unused import of `json_loads`. | | `custom_components/hacs/repositories/base.py` | Modified method calls to `async_get_hacs_json()` to include `ref` parameter. | | `custom_components/hacs/repositories/integration.py` | Corrected typos, updated string formatting, path assignments, method calls with parameters, and enhanced exception handling. |

Recent review details **Configuration used: CodeRabbit UI** **Review profile: ASSERTIVE**
Commits Files that changed from the base of the PR and between 4e2c1d9d38c1e1d93b66ef68d5971cb0cd103eca and b9f63d09e0db59b725faa3b62bb7cce432b1a770.
Files selected for processing (5) * action/action.py (1 hunks) * custom_components/hacs/__init__.py (2 hunks) * custom_components/hacs/base.py (1 hunks) * custom_components/hacs/repositories/base.py (2 hunks) * custom_components/hacs/repositories/integration.py (5 hunks)
Additional comments not posted (7)
action/action.py (2)
`158-158`: **Update comment style for consistency.** The change from double to single hash marks for comments improves readability and consistency with common Python coding standards. --- `158-158`: **Proper exception handling in repository validation.** The use of `try-except` to handle possible exceptions during repository registration is appropriate and ensures that any issues are caught and handled gracefully.
custom_components/hacs/__init__.py (2)
`90-90`: **Updated GitHub client initialization to use new headers and client names.** The changes to the GitHub client initialization include setting custom headers and client names, which are important for correct API interaction and user-agent representation. This should help with better tracking and management of API requests. Also applies to: 100-100 --- `100-100`: **Ensure startup logic is robust and handles various scenarios effectively.** The startup logic includes checks for version compatibility, data restoration success, and proper handling of conditions where HACS cannot operate alongside `custom_updater`.
custom_components/hacs/repositories/integration.py (1)
`89-89`: **Refined error handling and manifest retrieval logic.** The updates include better error messages and the use of the `ref` parameter for fetching manifests, which aligns with the PR's objectives to handle different repository states more accurately. Also applies to: 94-94, 104-104
custom_components/hacs/repositories/base.py (2)
`479-479`: **Correct use of the `ref` parameter in `async_get_hacs_json` call.** This change ensures that the `async_get_hacs_json` function fetches data from the correct Git reference, aligning with the PR's goals to fix branch-related issues in GitHub Actions. --- `542-542`: **Proper propagation of the `ref` parameter in repository updates.** Ensuring that the `async_get_hacs_json` function is called with the correct `ref` parameter during repository updates is crucial for accurate data fetching, particularly when dealing with multiple branches or tags.
--- 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.