Skip to content

fix: adjust pr-label strategy #2984

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

Merged
merged 4 commits into from
Feb 13, 2025
Merged

fix: adjust pr-label strategy #2984

merged 4 commits into from
Feb 13, 2025

Conversation

Miles-hxy
Copy link
Collaborator

@Miles-hxy Miles-hxy commented Feb 11, 2025

Summary by CodeRabbit

  • Chores

    • 更新调度任务频率为每3小时运行,确保PR标签的及时更新。
  • Refactor

    • 优化标签更新逻辑,确保仅参考每位评审的最新意见,提高反馈的准确性。
    • 简化任务描述并增强错误处理,提升整体流程的稳定性。

Copy link

coderabbitai bot commented Feb 11, 2025

Walkthrough

该改动在 GitHub Actions 工作流文件中更新了管理拉取请求标签的定时触发器(每 3 小时执行),调整了 pull_request_target 事件的格式,修改了工作流权限(去除了 checks: writecontents: read)。在 update-labels 任务中,步骤名称被简化,原先针对单个 PR 的评论获取逻辑被替换为遍历所有开放 PR,并使用 Map 来确保只取每个用户的最新评论以统计批准数。更新后的逻辑先过滤掉已有的操作标签,然后用 setLabels 替换所有标签,整个流程增加了错误处理。

Changes

文件路径 变更摘要
.github/workflows/pr-labels.yml 更新定时触发器(每 3 小时),调整 pull_request_target 事件格式和权限设置(移除 checks: writecontents: read),简化 "Update PR labels" 步骤名称;更新 update-labels 任务逻辑,通过遍历所有开放 PR 使用 Map 统计每个用户最新评论,过滤原有操作标签后用 setLabels 更新标签,并添加错误处理。

Sequence Diagram(s)

sequenceDiagram
    participant Cron as 定时触发器 (Cron)
    participant Runner as GitHub Actions Runner
    participant PR as 开放的 PR 列表
    participant Review as 评论获取器
    participant Label as 标签管理器

    Cron->>Runner: 每3小时触发工作流
    Runner->>PR: 获取所有开放的 PR
    loop 针对每个 PR
        PR->>Review: 获取该 PR 的所有评论
        Review-->>Runner: 传回评论数据
        Runner->>Label: 计算各用户最新评论及批准数
        Label-->>Runner: 返回标签更新信息
        Runner->>PR: 用setLabels更新标签,保留非操作标签
    end
    Runner->>Runner: 记录并处理错误
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud

Poem

我是一只快乐的小兔子,
在代码森林里蹦跳着心意。
定时触发飞快如风,
更新标签逻辑新颖齐整。
错误处理也不遗漏,
祝大家代码路上畅通无阻!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 687e25b and 43f6df5.

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

22-22: 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)

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

4-5: 定时任务频率调整符合预期

已根据用户反馈将执行频率调整为每 3 小时一次,这个调整很好地平衡了 API 调用频率。


44-52: 使用 Map 追踪最新评审的实现很棒

使用 Map 来确保只统计每个用户的最新评审状态是一个很好的实现。这样可以避免重复计算同一用户的多个评审。


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 action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Feb 11, 2025
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.75%. Comparing base (565fc8d) to head (43f6df5).
Report is 5 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #2984      +/-   ##
=============================================
+ Coverage      85.74%   85.75%   +0.01%     
=============================================
  Files            277      277              
  Lines          18105    18110       +5     
  Branches        2745     2735      -10     
=============================================
+ Hits           15524    15531       +7     
+ Misses          2576     2574       -2     
  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: 2

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

4-5: 建议降低定时任务的执行频率

每15分钟执行一次定时任务可能过于频繁,建议根据团队的 PR review 节奏调整为更合理的间隔(如每小时或每2小时)。这样可以减少 GitHub Actions 的资源消耗。

   schedule:
-    - cron: '*/15 * * * *'
+    - cron: '0 */2 * * *'
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 565fc8d and e6211e5.

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

21-21: 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)

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

21-21: 更新 github-script action 版本

当前使用的 actions/github-script@v6 版本过旧,建议更新到最新版本以确保兼容性和安全性。

✅ Verification successful

🌐 Web query:

What is the latest version of actions/github-script?

💡 Result:

The latest version of actions/github-script is v7, as shown in multiple examples and recent workflow updates[1][7]. This is confirmed by GitHub Actions documentation references and pull request updates explicitly using actions/github-script@v7 for API interactions[1][4][7].

For context:

  • The action provides pre-authenticated Octokit client access to GitHub's API
  • It supports JavaScript/TypeScript scripting within workflows
  • Recent updates (as of February 2025) show active maintenance with dependency bumps and security patches[8]

Citations:


更新 github-script action 版本

  • 当前工作流文件 .github/workflows/pr-labels.yml 中使用的 actions/github-script@v6 版本已过时。
  • 根据最新查询结果,最新版本为 v7,建议升级以确保工作流兼容性和安全性。
  • 请将对应行更新为 uses: actions/github-script@v7
🧰 Tools
🪛 actionlint (1.7.4)

21-21: 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)

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 12, 2025
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: 3

♻️ Duplicate comments (1)
.github/workflows/pr-labels.yml (1)

29-33: ⚠️ Potential issue

添加分页处理逻辑

当前获取 PR 列表的实现没有处理分页,可能会遗漏部分 PR。建议添加分页处理逻辑以确保获取所有开放的 PR。

              const { data: prs } = await github.rest.pulls.list({
                owner,
                repo,
-               state: 'open'
+               state: 'open',
+               per_page: 100,
+               page: 1
              });
+             
+             let allPRs = prs;
+             while (prs.length === 100) {
+               const { data: morePRs } = await github.rest.pulls.list({
+                 owner,
+                 repo,
+                 state: 'open',
+                 per_page: 100,
+                 page: page + 1
+               });
+               allPRs = allPRs.concat(morePRs);
+             }
🧹 Nitpick comments (1)
.github/workflows/pr-labels.yml (1)

76-79: 优化错误处理机制

建议增加更详细的错误信息和重试机制:

  1. 区分不同类型的错误(API 限流、网络问题等)
  2. 添加重试逻辑
  3. 记录更多调试信息
            } catch (error) {
-             console.error('Error:', error);
+             const errorMessage = error.response?.data?.message || error.message;
+             console.error('Error type:', error.name);
+             console.error('Error message:', errorMessage);
+             console.error('Status code:', error.response?.status);
+             if (error.response?.status === 403 && error.response?.data?.message.includes('API rate limit exceeded')) {
+               console.log('等待 API 限流重置...');
+               await new Promise(resolve => setTimeout(resolve, 60000));
+               // 重试逻辑
+             }
              throw error;
            }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e6211e5 and c3e5625.

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

21-21: 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)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: build

@xiaoyatong
Copy link
Collaborator

关注api权限,20分钟有些频繁,可修订2-5小时。

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c3e5625 and 687e25b.

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

21-21: 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)

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

12-14: 添加 rate-limit 权限配置

需要添加 rate-limit 权限以支持 API 限流检查。


21-21: 更新 GitHub Script Action 版本

当前版本过旧,建议更新到最新版本。

🧰 Tools
🪛 actionlint (1.7.4)

21-21: 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)


29-33: 添加分页处理逻辑

当前获取 PR 列表的实现可能会遗漏部分 PR。

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
@xiaoyatong xiaoyatong merged commit ec4c186 into jdf2e:feat_v3.x Feb 13, 2025
8 checks passed
oasis-cloud pushed a commit to oasis-cloud/nutui-react that referenced this pull request Feb 20, 2025
* fix: adjust pr-label strategy

* fix: adjust time interval

* fix: adjust interval time

* fix: adjust interval time
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 action:review This PR needs more reviews (less than 2 approvals) size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants