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

[ISSUE #1247]🔨Add Sync Issue Labels to PR Github action CI #1248

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

mxsm
Copy link
Owner

@mxsm mxsm commented Nov 20, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #1247

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • New Features
    • Introduced an automated workflow to synchronize labels from linked issues to pull requests, enhancing organization and tracking of related work.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

A new GitHub Actions workflow named sync-issue-labels.yml has been added to automate the synchronization of labels from linked issues to pull requests. This workflow is triggered when a pull request is opened, synchronized, or edited. It checks out the repository and executes a script to extract issue numbers from the PR description, fetches the corresponding issue labels via the GitHub REST API, and applies these labels to the PR if available.

Changes

File Change Summary
.github/workflows/sync-issue-labels.yml New workflow added to sync issue labels to PRs.

Assessment against linked issues

Objective Addressed Explanation
Add Sync Issue Labels to PR Github action CI

Possibly related PRs

Suggested labels

approved, auto merge

Suggested reviewers

  • SpaceXCN
  • TeslaRustor

Poem

In the garden of code, a new bloom does rise,
Syncing labels with ease, a delightful surprise.
Pull requests now dressed, in colors so bright,
Thanks to our workflow, they shine with delight! 🌼✨

Warning

Rate limit exceeded

@mxsm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 5 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 e3ff08b and faa0c37.


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 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.

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.

@rocketmq-rust-bot rocketmq-rust-bot added this to the v0.4.0 milestone Nov 20, 2024
@rocketmq-rust-bot rocketmq-rust-bot added the feature🚀 Suggest an idea for this project. label Nov 20, 2024
@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥

@rocketmq-rust-bot rocketmq-rust-bot added AI review first Ai review pr first ready to review waiting-review waiting review this PR labels Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 18.26%. Comparing base (102f54b) to head (faa0c37).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1248   +/-   ##
=======================================
  Coverage   18.26%   18.26%           
=======================================
  Files         428      428           
  Lines       53595    53595           
=======================================
  Hits         9789     9789           
  Misses      43806    43806           

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


🚨 Try these New Features:

Copy link
Contributor

@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: 5

🧹 Outside diff range and nitpick comments (2)
.github/workflows/sync-issue-labels.yml (2)

32-60: Implement rate limiting and batch processing

The current implementation processes issues sequentially without considering API rate limits. For PRs with many linked issues, this could hit rate limits.

Consider:

  1. Implementing exponential backoff for API calls
  2. Processing issues in batches
  3. Using GraphQL API instead of REST for better performance

Would you like me to provide an implementation example?

🧰 Tools
🪛 yamllint

[error] 34-34: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 43-43: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 50-50: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)


1-60: Fix formatting issues

The file has several formatting issues:

  1. Incorrect newline characters
  2. Trailing spaces on multiple lines

Consider using a pre-commit hook with a YAML formatter to maintain consistent formatting.

🧰 Tools
🪛 yamllint

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 43-43: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 50-50: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 102f54b and e3ff08b.

📒 Files selected for processing (1)
  • .github/workflows/sync-issue-labels.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/sync-issue-labels.yml

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 43-43: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 50-50: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)

.github/workflows/sync-issue-labels.yml Outdated Show resolved Hide resolved
- name: Sync Labels from Linked Issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Define minimum required permissions for BOT_TOKEN

Using secrets.BOT_TOKEN without explicit permissions could potentially grant more access than needed. Consider defining minimum required permissions in the workflow.

jobs:
  sync-labels:
    runs-on: ubuntu-latest
+   permissions:
+     issues: write
+     pull-requests: write

Committable suggestion skipped: line range outside the PR's diff.

issue_number: issueNumber,
});

const issueLabels = issueResponse.data.labels.map(label => label.name);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle duplicate and invalid labels

The current implementation doesn't handle duplicate labels or validate if the labels exist in the repository.

- const issueLabels = issueResponse.data.labels.map(label => label.name);
+ // Remove duplicates and ensure labels exist
+ const issueLabels = [...new Set(issueResponse.data.labels.map(label => label.name))];
+ 
+ // Verify labels exist in the repository
+ const repoLabels = await github.rest.issues.listLabelsForRepo({
+   owner: context.repo.owner,
+   repo: context.repo.repo
+ });
+ 
+ const validLabels = issueLabels.filter(label => 
+   repoLabels.data.some(repoLabel => repoLabel.name === label)
+ );
+ 
+ if (validLabels.length !== issueLabels.length) {
+   console.log('Some labels were invalid or not found in the repository');
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const issueLabels = issueResponse.data.labels.map(label => label.name);
// Remove duplicates and ensure labels exist
const issueLabels = [...new Set(issueResponse.data.labels.map(label => label.name))];
// Verify labels exist in the repository
const repoLabels = await github.rest.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo
});
const validLabels = issueLabels.filter(label =>
repoLabels.data.some(repoLabel => repoLabel.name === label)
);
if (validLabels.length !== issueLabels.length) {
console.log('Some labels were invalid or not found in the repository');
}

.github/workflows/sync-issue-labels.yml Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rocketmq-rust-bot
Copy link
Collaborator

🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (3)
.github/workflows/sync-issue-labels.yml (3)

14-14: Consider using SHA pinning for third-party actions

While using version tags like @v3 and @v7 is good, using the full SHA commit hash provides better security against supply chain attacks.

-        uses: actions/checkout@v3
+        uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
-        uses: actions/github-script@v7
+        uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v7.0.1

Also applies to: 18-18


52-57: Optimize label updates with batch processing

Instead of adding labels one by one for each issue, consider collecting all unique labels first and then adding them in a single API call.

-              await github.rest.issues.addLabels({
-                owner: context.repo.owner,
-                repo: context.repo.repo,
-                issue_number: context.payload.pull_request.number,
-                labels: issueLabels,
-              });
+              // Collect all labels from all linked issues first
+              const allLabels = new Set();
+              for (const label of issueLabels) {
+                allLabels.add(label);
+              }
+              
+              // Add all unique labels in a single API call at the end
+              if (allLabels.size > 0) {
+                await github.rest.issues.addLabels({
+                  owner: context.repo.owner,
+                  repo: context.repo.repo,
+                  issue_number: context.payload.pull_request.number,
+                  labels: Array.from(allLabels),
+                });
+              }

1-60: Fix minor formatting issues

The YAML file has some formatting inconsistencies:

  • Trailing spaces on multiple lines
  • Inconsistent line endings

Consider using an editor with YAML formatting support or adding a .editorconfig file to maintain consistent formatting.

🧰 Tools
🪛 yamllint

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 43-43: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 50-50: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e3ff08b and faa0c37.

📒 Files selected for processing (1)
  • .github/workflows/sync-issue-labels.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/sync-issue-labels.yml

[error] 1-1: wrong new line character: expected \n

(new-lines)


[error] 26-26: trailing spaces

(trailing-spaces)


[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 43-43: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 50-50: trailing spaces

(trailing-spaces)


[error] 58-58: trailing spaces

(trailing-spaces)

Comment on lines +36 to +40
const issueResponse = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add rate limit handling for GitHub API calls

The GitHub API has rate limits that could affect the workflow. Consider adding rate limit detection and handling.

+             try {
+               const rateLimit = await github.rest.rateLimit.get();
+               if (rateLimit.data.rate.remaining < 10) {
+                 console.log(`Rate limit critical: ${rateLimit.data.rate.remaining} calls remaining`);
+                 await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
+               }
+
                const issueResponse = await github.rest.issues.get({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  issue_number: issueNumber,
                });
+               console.log(`Successfully fetched issue #${issueNumber}`);
+             } catch (error) {
+               if (error.status === 403 && error.message.includes('API rate limit exceeded')) {
+                 console.log('Rate limit exceeded. Waiting before retry...');
+                 await new Promise(resolve => setTimeout(resolve, 60000));
+                 continue;
+               }
+               console.error(`Failed to fetch issue #${issueNumber}: ${error.message}`);
+               continue;
+             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const issueResponse = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
try {
const rateLimit = await github.rest.rateLimit.get();
if (rateLimit.data.rate.remaining < 10) {
console.log(`Rate limit critical: ${rateLimit.data.rate.remaining} calls remaining`);
await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
}
const issueResponse = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
console.log(`Successfully fetched issue #${issueNumber}`);
} catch (error) {
if (error.status === 403 && error.message.includes('API rate limit exceeded')) {
console.log('Rate limit exceeded. Waiting before retry...');
await new Promise(resolve => setTimeout(resolve, 60000));
continue;
}
console.error(`Failed to fetch issue #${issueNumber}: ${error.message}`);
continue;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI review first Ai review pr first approved PR has approved auto merge feature🚀 Suggest an idea for this project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature🚀] Add Sync Issue Labels to PR Github action CI
3 participants