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

fix: refactor notify triager workflow #3403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sambhavgupta0705
Copy link
Member

@sambhavgupta0705 sambhavgupta0705 commented Nov 17, 2024

ref : #3214

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced the triager extraction process to ensure accurate identification of document and code triagers.
    • Added checks to prevent unnecessary review assignments when no triagers are found.
  • Improvements

    • Improved workflow efficiency by reducing unnecessary API calls related to reviewer assignments.

Copy link

coderabbitai bot commented Nov 17, 2024

Walkthrough

The pull request modifies the .github/workflows/notify-triager.yml workflow file to enhance the extraction and handling of triager information from the CODEOWNERS file. It refines the search for document and code triagers by specifically targeting lines marked with #docTriagers and #codeTriagers. The changes include checks to ensure that reviewers are only added if triagers are present, improving the workflow's robustness and preventing unnecessary API calls when no triagers are defined.

Changes

File Change Summary
.github/workflows/notify-triager.yml Refined extraction of triagers, added checks for existence before adding reviewers, and improved control flow.

Possibly related PRs

Suggested labels

autoapproved, autoupdate

Suggested reviewers

  • derberg
  • akshatnema
  • asyncapi-bot-eve

Poem

In the code where triagers dwell,
A rabbit hops, all is well.
With checks in place, no calls to waste,
The workflow's smooth, a joyful haste!
Let's cheer for changes, bright and clear,
For every triager, we hold dear! 🐇✨


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.

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.

Copy link

netlify bot commented Nov 17, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9758be5
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6739881b8d63cc00088649b7
😎 Deploy Preview https://deploy-preview-3403--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sambhavgupta0705
Copy link
Member Author

sambhavgupta0705 commented Nov 17, 2024

This is currently in draft state

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.77%. Comparing base (384da22) to head (9758be5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3403   +/-   ##
=======================================
  Coverage   67.77%   67.77%           
=======================================
  Files          21       21           
  Lines         664      664           
=======================================
  Hits          450      450           
  Misses        214      214           

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

@asyncapi-bot
Copy link
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 32
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3403--asyncapi-website.netlify.app/

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

🧹 Outside diff range and nitpick comments (1)
.github/workflows/notify-triager.yml (1)

73-86: Add error handling for GitHub API calls

The current implementation doesn't handle API failures or rate limits.

 if [ ${#codeTriagers[@]} -gt 0 ]; then
   reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
   reviewers="[${reviewers:2}]"
-  curl \
-    -X POST \
-    -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-    -H "Accept: application/vnd.github.v3+json" \
-    https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-    -d "{
-      \"reviewers\": $reviewers
-    }"
+  response=$(curl -s -w "%{http_code}" \
+    -X POST \
+    -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+    -H "Accept: application/vnd.github.v3+json" \
+    https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
+    -d "{\"reviewers\": $reviewers}")
+  status_code=${response: -3}
+  if [ $status_code -ge 400 ]; then
+    echo "::error::Failed to add reviewers. Status code: $status_code"
+    exit 1
+  fi
 fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 384da22 and 9758be5.

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

62-62: shellcheck reported issue in this script: SC2086:info:5:38: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint
.github/workflows/notify-triager.yml

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

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

🔇 Additional comments (1)
.github/workflows/notify-triager.yml (1)

54-57: Verify CODEOWNERS file format and current triager assignments

Let's ensure the changes align with the current CODEOWNERS file structure.

Also applies to: 63-66

✅ Verification successful

The CODEOWNERS file format and triager assignments are correctly handled

The verification confirms that:

  • The CODEOWNERS file exists and contains the expected triager definitions
  • The #docTriagers line is present with the correct format: #docTriagers: TRohit20 BhaswatiRoy VaishnaviNandakumar J0SAL
  • The code in the workflow correctly extracts triagers using grep '^#docTriagers' and sed 's/#docTriagers: //'
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify CODEOWNERS file format and current triager assignments

# Check if CODEOWNERS file exists and show its content
if [ -f "CODEOWNERS" ]; then
  echo "=== Current CODEOWNERS content ==="
  cat CODEOWNERS
else
  echo "CODEOWNERS file not found"
fi

# Check current triager line format
echo -e "\n=== Current triager definitions ==="
grep -E '^\s*#(doc|code)Triagers:' CODEOWNERS || echo "No triager definitions found"

Length of output: 1243

Comment on lines +54 to +57
docTriagers=$(grep '^#docTriagers' CODEOWNERS | sed 's/#docTriagers: //')
if [ -z "$docTriagers" ]; then
echo "No doc triagers found"
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve robustness of triager extraction

The current implementation could be made more robust to handle edge cases:

- docTriagers=$(grep '^#docTriagers' CODEOWNERS | sed 's/#docTriagers: //')
+ docTriagers=$(grep -E '^\s*#docTriagers:' CODEOWNERS | sed 's/^\s*#docTriagers:\s*//' | tr -d '\r')
- codeTriagers=$(grep '^#codeTriagers' CODEOWNERS | sed 's/#codeTriagers: //')
+ codeTriagers=$(grep -E '^\s*#codeTriagers:' CODEOWNERS | sed 's/^\s*#codeTriagers:\s*//' | tr -d '\r')

Changes:

  1. Added \s* to handle potential whitespace before/after the prefix
  2. Added tr -d '\r' to handle CRLF line endings
  3. Used -E for extended regex support

Also applies to: 63-66

Comment on lines +92 to +105
if [ ${#docTriagers[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers="[${reviewers:2}]"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"
else
echo "No doc triagers found, skipping review assignment"
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reduce code duplication and fix file format

  1. The reviewer assignment logic is duplicated between code and doc segments.
  2. File is missing a newline at the end.

Consider extracting the reviewer assignment logic into a reusable function:

+ add_reviewers() {
+   local reviewer_type=$1
+   local reviewers_array=("${@:2}")
+   
+   if [ ${#reviewers_array[@]} -gt 0 ]; then
+     reviewers=$(printf ', "%s"' "${reviewers_array[@]}")
+     reviewers="[${reviewers:2}]"
+     response=$(curl -s -w "%{http_code}" \
+       -X POST \
+       -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+       -H "Accept: application/vnd.github.v3+json" \
+       https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
+       -d "{\"reviewers\": $reviewers}")
+     status_code=${response: -3}
+     if [ $status_code -ge 400 ]; then
+       echo "::error::Failed to add $reviewer_type reviewers. Status code: $status_code"
+       exit 1
+     fi
+   else
+     echo "No $reviewer_type triagers found, skipping review assignment"
+   fi
+ }
+ 
  # Add code reviewers
  IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
- if [ ${#codeTriagers[@]} -gt 0 ]; then
-   # ... existing code ...
- fi
+ add_reviewers "code" "${codeTriagers[@]}"
  
  # Add doc reviewers
  IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
- if [ ${#docTriagers[@]} -gt 0 ]; then
-   # ... existing code ...
- fi
+ add_reviewers "doc" "${docTriagers[@]}"
+
📝 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
if [ ${#docTriagers[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers="[${reviewers:2}]"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"
else
echo "No doc triagers found, skipping review assignment"
fi
add_reviewers() {
local reviewer_type=$1
local reviewers_array=("${@:2}")
if [ ${#reviewers_array[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${reviewers_array[@]}")
reviewers="[${reviewers:2}]"
response=$(curl -s -w "%{http_code}" \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{\"reviewers\": $reviewers}")
status_code=${response: -3}
if [ $status_code -ge 400 ]; then
echo "::error::Failed to add $reviewer_type reviewers. Status code: $status_code"
exit 1
fi
else
echo "No $reviewer_type triagers found, skipping review assignment"
fi
}
# Add code reviewers
IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
add_reviewers "code" "${codeTriagers[@]}"
# Add doc reviewers
IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
add_reviewers "doc" "${docTriagers[@]}"
🧰 Tools
🪛 yamllint

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

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

@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty program related label label Nov 18, 2024
@aeworxet
Copy link
Contributor

@asyncapi/bounty_team

@anshgoyalevil
Copy link
Member

@sambhavgupta0705 Is it ready for review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty program related label
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants