-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
修改插件商店下载逻辑 #1851
修改插件商店下载逻辑 #1851
Conversation
🐛 修复使用道具后未减去道具数量
RepoInfo 的更新类图classDiagram
class RepoInfo {
-owner: str
-repo: str
-branch: str
+__init__(owner: str, repo: str, branch: str)
+to_dict(**kwargs)
+get_latest_commit() str
+is_commit_hash() bool
}
note for RepoInfo "Added get_latest_commit() and is_commit_hash() methods"
文件级别变更
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获得帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request modifies the plugin store download logic to fetch the latest commit hash from the GitHub repository before installing a plugin. This ensures that the latest version of the plugin is always installed, even if the plugin's version is not explicitly specified. It also adds utility functions to determine if a branch is a commit hash. Sequence diagram for plugin installation with latest commitsequenceDiagram
participant PluginStore
participant GithubUtils
participant GithubAPI
participant Github
PluginStore->GithubUtils: parse_github_url(github_url)
activate GithubUtils
GithubUtils-->PluginStore: repo_info
deactivate GithubUtils
PluginStore->repo_info: is_commit_hash()
alt not repo_info.is_commit_hash()
PluginStore->repo_info: get_latest_commit()
activate repo_info
repo_info->Github: GET /repos/{owner}/{repo}/branches/{branch}
activate Github
Github-->repo_info: commit SHA
deactivate Github
repo_info-->PluginStore: latest_commit
deactivate repo_info
PluginStore->repo_info: branch = latest_commit
end
PluginStore->GithubUtils: iter_api_strategies()
loop For each repo_api in strategies
PluginStore->repo_api: parse_repo_info(repo_info)
activate repo_api
repo_api->GithubAPI: Fetch repo information
activate GithubAPI
GithubAPI-->repo_api: Repo information
deactivate GithubAPI
repo_api-->PluginStore: Success or Failure
deactivate repo_api
end
Updated class diagram for RepoInfoclassDiagram
class RepoInfo {
-owner: str
-repo: str
-branch: str
+__init__(owner: str, repo: str, branch: str)
+to_dict(**kwargs)
+get_latest_commit() str
+is_commit_hash() bool
}
note for RepoInfo "Added get_latest_commit() and is_commit_hash() methods"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嘿 @Copaan - 我已经查看了你的更改 - 这里有一些反馈:
总体评论:
- 考虑向
get_latest_commit
添加缓存,以避免不必要的 API 调用。 install_plugin_with_repo
中的 try-except 块会重新引发异常,请考虑这是否是所需的行为。
以下是我在审查期间查看的内容
- 🟡 一般问题:发现 1 个问题
- 🟢 安全性:一切看起来都不错
- 🟢 测试:一切看起来都不错
- 🟢 复杂性:一切看起来都不错
- 🟢 文档:一切看起来都不错
帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey @Copaan - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a cache to
get_latest_commit
to avoid unnecessary API calls. - The try-except block in
install_plugin_with_repo
re-raises the exception, consider if this is the desired behavior.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
if response.status_code == 200: | ||
data = response.json() | ||
return data["commit"]["sha"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): 保护措施,防止出现意外的 API 响应结构。
虽然 API 调用会检查响应状态,但它假设 JSON 数据包含预期的“commit”和“sha”键。添加显式键检查或处理潜在的 KeyError 异常可以使该方法对 API 响应结构的变化更具鲁棒性。
if response.status_code == 200: | |
data = response.json() | |
return data["commit"]["sha"] | |
if response.status_code == 200: | |
data = response.json() | |
if "commit" in data and "sha" in data["commit"]: | |
return data["commit"]["sha"] | |
raise ValueError(f"Unexpected API response structure: {data}") |
Original comment in English
suggestion (bug_risk): Safeguard against unexpected API response structures.
While the API call is checked for response status, it assumes the JSON data contains the expected 'commit' and 'sha' keys. Adding explicit key checks or handling potential KeyError exceptions could make the method more robust against changes in the API's response structure.
if response.status_code == 200: | |
data = response.json() | |
return data["commit"]["sha"] | |
if response.status_code == 200: | |
data = response.json() | |
if "commit" in data and "sha" in data["commit"]: | |
return data["commit"]["sha"] | |
raise ValueError(f"Unexpected API response structure: {data}") |
No description provided.