Skip to content

Z#25

Merged
zzzzzyc merged 5 commits into
devfrom
z
Jun 17, 2025
Merged

Z#25
zzzzzyc merged 5 commits into
devfrom
z

Conversation

@zzzzzyc

@zzzzzyc zzzzzyc commented Jun 17, 2025

Copy link
Copy Markdown
Collaborator

好的,这是将 pull request 总结翻译成中文的结果:

Sourcery 总结

增强插件初始化兼容性,调整默认配置和日志记录,更新依赖项,并添加用于获取贡献者头像和生成 Gource 可视化的实用程序

新功能:

  • 添加 git_get_icon.py 脚本,用于通过 GitHub API 获取和保存贡献者头像
  • 添加 gource_run.bat 脚本,用于使用贡献者头像生成 Gource 可视化视频
  • 在配置模板中引入新的 'enable_lichess' 选项

增强功能:

  • 自动在插件实例上设置 'plugin_dir' 属性,以实现向后兼容
  • 将默认日志级别更改为 INFO(当不在调试模式下运行时)

构建:

  • 将 customtkinter 添加到项目依赖项
Original summary in English

Summary by Sourcery

Enhance plugin initialization compatibility, adjust default configuration and logging, update dependencies, and add utilities for fetching contributor avatars and generating Gource visualizations

New Features:

  • Add git_get_icon.py script to fetch and save contributor avatars via GitHub API
  • Add gource_run.bat script to generate a Gource visualization video using contributor avatars
  • Introduce new 'enable_lichess' option in the configuration template

Enhancements:

  • Automatically set 'plugin_dir' attribute on plugin instances for backward compatibility
  • Change default log level to INFO when not running in debug mode

Build:

  • Add customtkinter to project dependencies

zzzzzyc added 5 commits June 18, 2025 02:24
- 将 `enable_subtitle` 和 `enable_minecraft` 设置为 `false`,以禁用字幕和Minecraft功能。
- 新增 `enable_lichess` 设置为 `true`,以启用国际象棋插件。
- 修改日志级别为 `INFO`,以优化日志输出。
- 更新插件管理器,手动设置插件目录路径以实现向后兼容。
- 在关键字动作插件中添加插件入口点定义。
- 新增 `git_get_icon.py` 脚本,自动从Git日志中提取贡献者信息并通过GitHub API下载头像。
- 创建头像保存目录以存储下载的头像。
- 新增 `gource_run.bat` 脚本,用于运行Gource并生成视频。
- 添加示例视频文件 `amaidesu_25_6_18.mp4`。
- 将 `enable_subtitle` 和 `enable_minecraft` 设置为 `false`,以禁用字幕和Minecraft功能。
- 新增 `enable_lichess` 设置为 `true`,以启用国际象棋插件。
- 修改日志级别为 `INFO`,以优化日志输出。
- 更新插件管理器,手动设置插件目录路径以实现向后兼容。
- 在关键字动作插件中添加插件入口点定义。
- 新增 `git_get_icon.py` 脚本,自动从Git日志中提取贡献者信息并通过GitHub API下载头像。
- 创建头像保存目录以存储下载的头像。
- 新增 `gource_run.bat` 脚本,用于运行Gource并生成视频。
- 添加示例视频文件 `amaidesu_25_6_18.mp4`。
@sourcery-ai

sourcery-ai Bot commented Jun 17, 2025

Copy link
Copy Markdown

好的,这是将审查指南翻译成中文的版本:

审查者指南

此 PR 增强了插件实例化的向后兼容性,更新了默认配置标志,优化了日志记录默认值,添加了一个新的依赖项,并引入了用于贡献者头像检索和 Gource 可视化的工具脚本。

插件实例化和 plugin_dir 属性的实体关系图

erDiagram
    PLUGIN_MANAGER ||--o{ PLUGIN : instantiates
    PLUGIN {
        string plugin_dir
    }
    %% plugin_dir 现在始终在插件实例上设置,以实现向后兼容性
Loading

PluginManager 中增强的插件实例化的类图

classDiagram
    class PluginManager {
        +load_plugins(plugin_dir: str)
        -logger
        -core
        -loaded_plugins
    }
    class Plugin {
        +setup()
        +plugin_dir
    }
    PluginManager --> Plugin : instantiates
    %% 重点:PluginManager 现在在 Plugin 实例上设置 plugin_dir 属性,以实现向后兼容性
Loading

git_get_icon.py 贡献者头像检索的流程图

flowchart TD
    A[开始] --> B[从 git log 获取贡献者]
    B --> C{找到贡献者?}
    C -- 否 --> Z[退出]
    C -- 是 --> D[对于每个贡献者]
    D --> E{头像存在?}
    E -- 是 --> F[跳过]
    E -- 否 --> G[从 GitHub API 获取头像]
    G --> H{找到头像?}
    H -- 是 --> I[将头像保存到 .git/avatars]
    H -- 否 --> J[记录未找到]
    F --> D
    I --> D
    J --> D
    D --> K[完成]
    K --> L[打印 Gource 用法]
    L --> M[结束]
Loading

文件级别变更

变更 详情 文件
在实例化的插件上持久化插件目录,以保持向后兼容性
  • 在插件实例化后,在插件实例上设置 'plugin_dir' 属性
  • 记录调试消息,确认 'plugin_dir' 赋值
src/core/plugin_manager.py
调整配置模板中的默认功能标志
  • 切换字幕和 Minecraft 支持的默认值
  • 引入新的 'enable_lichess' 标志,设置为 true
config-template.toml
优化主应用程序中的默认日志记录级别行为
  • 当不在调试模式下时,使用 INFO 级别,而不是始终使用 DEBUG
main.py
添加自定义 UI 依赖项
  • 在 requirements 中包含 'customtkinter' 包
requirements.txt
引入头像获取和可视化工具
  • 新脚本,用于通过 GitHub API 拉取贡献者头像
  • 批处理文件,用于使用用户图像运行 Gource
git_get_icon.py
gource_run.bat
确保 keyword_action 插件中正确的文件结尾和入口注释
  • 在文件末尾添加缺失的换行符
  • 追加插件入口点注释
src/plugins/keyword_action/plugin.py

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从评论中创建一个 issue。您也可以回复审查评论并使用 @sourcery-ai issue 来从中创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 pull request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 pull request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审查者指南: 在 pull request 上评论 @sourcery-ai guide 以随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。
  • 关闭所有 Sourcery 审查: 在 pull request 上评论 @sourcery-ai dismiss 以关闭所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

This PR enhances plugin instantiation for backward compatibility, updates default configuration flags, refines logging defaults, adds a new dependency, and introduces tooling scripts for contributor avatar retrieval and Gource visualization.

Entity relationship diagram for plugin instantiation and plugin_dir attribute

erDiagram
    PLUGIN_MANAGER ||--o{ PLUGIN : instantiates
    PLUGIN {
        string plugin_dir
    }
    %% plugin_dir is now always set on plugin instance for backward compatibility
Loading

Class diagram for enhanced plugin instantiation in PluginManager

classDiagram
    class PluginManager {
        +load_plugins(plugin_dir: str)
        -logger
        -core
        -loaded_plugins
    }
    class Plugin {
        +setup()
        +plugin_dir
    }
    PluginManager --> Plugin : instantiates
    %% Highlight: PluginManager now sets plugin_dir attribute on Plugin instance for backward compatibility
Loading

Flow diagram for git_get_icon.py contributor avatar retrieval

flowchart TD
    A[Start] --> B[Get contributors from git log]
    B --> C{Contributors found?}
    C -- No --> Z[Exit]
    C -- Yes --> D[For each contributor]
    D --> E{Avatar exists?}
    E -- Yes --> F[Skip]
    E -- No --> G[Fetch avatar from GitHub API]
    G --> H{Avatar found?}
    H -- Yes --> I[Save avatar to .git/avatars]
    H -- No --> J[Log not found]
    F --> D
    I --> D
    J --> D
    D --> K[Done]
    K --> L[Print Gource usage]
    L --> M[End]
Loading

File-Level Changes

Change Details Files
Persist plugin directory on instantiated plugins to maintain backward compatibility
  • Set 'plugin_dir' attribute on plugin instances after instantiation
  • Log debug message confirming 'plugin_dir' assignment
src/core/plugin_manager.py
Adjust default feature flags in the configuration template
  • Toggle default values for subtitles and Minecraft support
  • Introduce new 'enable_lichess' flag set to true
config-template.toml
Refine default logging level behavior in main application
  • Use INFO level when not in debug mode instead of always DEBUG
main.py
Add custom UI dependency
  • Include 'customtkinter' package in requirements
requirements.txt
Introduce avatar-fetching and visualization tooling
  • New script to pull contributor avatars via GitHub API
  • Batch file to run Gource with user images
git_get_icon.py
gource_run.bat
Ensure proper file ending and entry comment in keyword_action plugin
  • Add missing newline at end of file
  • Append plugin entry-point comment
src/plugins/keyword_action/plugin.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @zzzzzyc, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily introduces new utility scripts for generating visual representations of the repository's development history using Gource. It also updates the application's default configuration template, potentially enabling a new feature and adjusting existing defaults. A new UI library dependency is added, hinting at upcoming or concurrent UI development. Finally, several internal code quality improvements are made to the logging system and plugin management, enhancing the application's overall maintainability and user experience.

Highlights

  • New Gource Visualization Utilities: Introduced two new files, git_get_icon.py and gource_run.bat, which work together to automate the process of fetching GitHub contributor avatars and generating a Gource video visualization of the repository's commit history. This provides a new way to visualize project development.
  • Configuration Template Updates: Modified config-template.toml to change the default enablement of subtitle and minecraft features from true to false. Additionally, a new enable_lichess = true entry was added, suggesting the introduction or default activation of a new 'lichess' related feature.
  • New UI Dependency: Added customtkinter to requirements.txt, indicating that new graphical user interface components or features, likely with a modern look and feel, are being introduced or planned for the application.
  • Internal Plugin System Enhancements: Improved the plugin loading mechanism in src/core/plugin_manager.py by explicitly setting the plugin_dir attribute on plugin instances for better backward compatibility. Also, src/plugins/keyword_action/plugin.py was updated to explicitly define plugin_entrypoint, standardizing plugin discovery.
  • Logging Default Adjustment: Changed the default logging level in main.py from DEBUG to INFO when the debug flag is not explicitly set. This reduces log verbosity during standard operation while retaining detailed logs for debugging.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces new utility scripts, updates default configurations, enhances plugin initialization, and modifies the default logging level. The review focuses on improving the robustness of the Python script and correcting the path in the batch script. Other changes related to configuration and logging appear sound.

Comment thread git_get_icon.py
Comment on lines +35 to +37
if data.get('items'):
avatar_url = data['items'][0]['avatar_url']
print(f"Found GitHub user for {author_name} ({email})")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The code avatar_url = data['items'][0]['avatar_url'] can lead to an IndexError if data.get('items') returns an empty list. It's safer to check if the list is non-empty and that its first element is a dictionary containing the avatar_url.

Suggested change
if data.get('items'):
avatar_url = data['items'][0]['avatar_url']
print(f"Found GitHub user for {author_name} ({email})")
items = data.get('items')
if items and isinstance(items, list) and len(items) > 0 and isinstance(items[0], dict):
avatar_url = items[0].get('avatar_url')
if avatar_url:
print(f"Found GitHub user for {author_name} ({email})")

Comment thread git_get_icon.py
avatar_response.raise_for_status()

# 以 "作者名.jpg" 的格式保存图片,Gource会识别这个文件名
file_path = os.path.join(AVATAR_DIR, f"{author_name}.jpg")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Author names obtained from git log can contain characters that are invalid in file names on various operating systems. The author_name should be sanitized to remove or replace invalid characters before using it as part of a filename.

Comment thread gource_run.bat
@@ -0,0 +1 @@
gource --start-date "2025-03-01" --user-image-dir ....git/avatars/ -1920x1080 --title "Amaidesu History" -o - | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset veryfast -pix_fmt yuv420p -crf 18 -threads 0 -bf 0 amaidesu.mp4 No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The path ....git/avatars/ for --user-image-dir seems incorrect. If this script is intended to be run from the root of the Git repository, the path to the avatars directory should likely be .git/avatars/.

gource  --start-date "2025-03-01" --user-image-dir .git/avatars/ -1920x1080 --title "Amaidesu History" -o - | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset veryfast -pix_fmt yuv420p -crf 18 -threads 0 -bf 0 amaidesu.mp4

Comment thread git_get_icon.py
# 使用'|'作为分隔符,方便处理
log_output = subprocess.check_output(
['git', 'log', '--pretty=format:%an|%ae']
).decode('utf-8', errors='ignore')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using errors='ignore' when decoding the git log output can silently drop or corrupt characters. Consider using errors='replace' to replace problematic characters with a placeholder.

Suggested change
).decode('utf-8', errors='ignore')
).decode('utf-8', errors='replace')

Comment thread git_get_icon.py

contributors = set(log_output.strip().split('\n'))
return contributors
except Exception as e:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a generic Exception can hide specific errors. It's better to catch more specific exceptions that you anticipate, such as subprocess.CalledProcessError or FileNotFoundError.

Suggested change
except Exception as e:
except (subprocess.CalledProcessError, FileNotFoundError) as e:

Comment thread git_get_icon.py

except requests.exceptions.RequestException as e:
print(f"API request failed for {email}: {e}")
except Exception as e:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching Exception here is too broad. Consider catching more specific exceptions like requests.exceptions.RequestException.

@zzzzzyc zzzzzyc merged commit ba642fd into dev Jun 17, 2025
2 checks passed
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