Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add PR review labels automation #2972

Open
wants to merge 6 commits into
base: feat_v3.x
Choose a base branch
from

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented Feb 7, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能
    • 添加了自动化工作流程,可根据拉取请求的审核数量智能更新标签:当获得两次及以上审批时,将自动标记为可合并;若审批不足,则保持待审核状态,从而提升整体审核和合并效率。

Copy link

coderabbitai bot commented Feb 7, 2025

Warning

Rate limit exceeded

@Alex-huxiyang has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fbede29 and 6c3e4fc.

📒 Files selected for processing (1)
  • .github/workflows/pr-labels.yml (1 hunks)

Walkthrough

本次提交新增了一个 GitHub Actions 工作流文件 (.github/workflows/pr-labels.yml),用于根据拉取请求(PR)中的评论状态自动管理标签。该工作流在 PR 评论相关事件触发时运行,通过脚本统计批准评论的数量,并根据审批数目删除旧标签后添加新的标签(当批准数达到两个或以上时添加 "action:merge",否则添加 "action:review")。

Changes

文件路径 更改概述
.github/workflows/pr-labels.yml 新增工作流用于根据 PR 审查状态统计评论,并自动管理(添加/删除)相关标签

Sequence Diagram(s)

sequenceDiagram
    participant PR as 拉取请求
    participant GA as GitHub Actions
    participant Script as 脚本
    participant API as GitHub API

    PR->>GA: 触发 PR 评论事件(提交/编辑/撤销审核)
    GA->>Script: 执行 update-labels 任务
    Script->>API: 获取 PR 审查数据
    API-->>Script: 返回审核统计结果
    Script->>API: 移除旧标签(action:merge 和 action:review)
    alt 审核数 ≥ 2
        Script->>API: 添加 "action:merge" 标签
    else
        Script->>API: 添加 "action:review" 标签
    end
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud

Poem

我是小兔跳跃忙,
PR 标签如同行囊。
数着审查得分好,
标记新意永不老。
代码路上欢声笑 😊
啾啾祝愿快成功!


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the 3.x Target branch 3.x label Feb 7, 2025
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.74%. Comparing base (95c21a7) to head (6c3e4fc).
Report is 3 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2972   +/-   ##
==========================================
  Coverage      85.74%   85.74%           
==========================================
  Files            277      277           
  Lines          18110    18105    -5     
  Branches        2745     2745           
==========================================
- Hits           15528    15524    -4     
+ Misses          2577     2576    -1     
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.github/workflows/pr-labels.yml (4)

13-14: 建议更新 Checkout Action 版本
当前使用的 actions/checkout@v3 可能存在已知问题或安全隐患,建议检查最新稳定版本并升级。例如:

- uses: actions/checkout@v3
+ uses: actions/[email protected]  # 请根据最新版本做相应更新
🧰 Tools
🪛 actionlint (1.7.4)

14-14: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


16-18: 建议更新 GitHub Script Action 版本
actions/github-script@v6 可能也略显过时,建议更新至最新版本以确保良好的兼容性和安全性。例如:

- uses: actions/github-script@v6
+ uses: actions/[email protected]  # 请核对最新稳定版后更新
🧰 Tools
🪛 actionlint (1.7.4)

17-17: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


19-63: 脚本逻辑清晰,但可考虑添加错误处理
脚本能够正确获取 PR 评论、计算批准数量并更新标签。为了提高稳定性,建议在关键 API 调用处增加异常捕获或错误日志记录,以便在请求失败时能及时反映问题。

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 63-63: no new line character at the end of file

(new-line-at-end-of-file)


63-63: 遵循 YAMLlint 规范
文件末尾缺少换行符,请在末尾添加一个新行以符合 YAMLlint 要求。

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 63-63: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61955b9 and 2f5e01a.

📒 Files selected for processing (1)
  • .github/workflows/pr-labels.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pr-labels.yml

14-14: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


17-17: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 YAMLlint (1.35.1)
.github/workflows/pr-labels.yml

[error] 63-63: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
.github/workflows/pr-labels.yml (2)

1-2: 工作流程名称设置正确
名称 "PR Review Labels" 清晰表明了此工作流程的用途。


3-8: 触发器配置合理
本部分配置了 pull_request_review 以及 pull_request 的 review 相关触发类型,能够满足自动管理 PR 标签的需求。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.github/workflows/pr-labels.yml (4)

15-17: 更新 actions/checkout 版本建议
静态分析工具提示 actions/checkout@v3 版本可能较旧,建议参考 GitHub 官方文档升级到最新稳定版本以提高兼容性和安全性。

🧰 Tools
🪛 actionlint (1.7.4)

16-16: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


18-20: 更新 actions/github-script 版本建议
静态分析工具提示 actions/github-script@v6 可能已不再是最新版本,建议检查最新的发布情况并升级到最新版本以利用新功能和改进。

🧰 Tools
🪛 actionlint (1.7.4)

19-19: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


49-56: 删除旧 Action 标签的实现
使用 for-of 循环逐个调用 API 删除对应标签是可行的方案。若未来标签数目增加,考虑并行执行可能会进一步提高效率,但目前规模下这种实现是合理的。


58-65: 添加新标签及文件结尾换行问题
根据 approved 数量选择新标签(approvedCount >= 2 时为 "action:merge",否则为 "action:review")的逻辑符合预期。另外,静态分析工具指出文件末尾缺少换行符,请在文件末尾添加换行符以符合 YAML 格式要求。

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 65-65: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5e01a and fbede29.

📒 Files selected for processing (1)
  • .github/workflows/pr-labels.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pr-labels.yml

16-16: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


19-19: the runner of "actions/github-script@v6" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 YAMLlint (1.35.1)
.github/workflows/pr-labels.yml

[error] 65-65: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (5)
.github/workflows/pr-labels.yml (5)

1-10: 工作流名称与触发条件设置
该部分代码定义了工作流名称 “PR Review Labels” 以及监听的多个 pull_request 及 pull_request_review 事件,满足自动化标签管理的基本需求。


21-30: 提取仓库信息与获取 PR 评论
代码正确地从 context 中提取 owner、repo 和 pull request 编号,并利用 GitHub API 调用了 listReviews 方法获取了所有 PR 评论,逻辑清晰且实现合理。


32-36: 统计“APPROVED”评论数量
通过过滤 reviews.data 中 state 为 "APPROVED" 的评论来计算数量,这种方式简洁有效,如有需要可增加更严格的状态验证。


37-42: 获取当前 PR 标签
使用 listLabelsOnIssue 方法获取当前 PR 标签的实现正确,逻辑清楚,有助于后续对标签进行管理。


44-48: 准备删除旧的 Action 标签
代码通过过滤当前标签集合中的 “action:merge” 和 “action:review” 来确定需要移除的标签,逻辑清晰,无冗余。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant