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: fixed the notify triager workflow #3460

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sambhavgupta0705
Copy link
Member

@sambhavgupta0705 sambhavgupta0705 commented Dec 9, 2024

The current workflow has an error in which it calls the code reviewers also when the changes are only in the md files

Fixed that by adding a check

fixes : #3214

Summary by CodeRabbit

  • New Features

    • Enhanced workflow for pull requests with improved commit message processing.
    • Introduced a new step to retrieve all changed files, streamlining the review process.
  • Bug Fixes

    • Updated conditions for adding reviewers based on the count of changed files, ensuring accurate reviewer assignments.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces modifications to the workflow file .github/workflows/notify-triager.yml. Key changes include the addition of a step to extract and sanitize the last commit message, and the implementation of a new action to retrieve all changed files. This replaces the previous action version and simplifies the reviewer assignment process based on the count of changed files.

Changes

File Change Summary
.github/workflows/notify-triager.yml - Updated action version from tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 to tj-actions/changed-files@v45.
- Added a new step to get all changed files using the updated action.
- Modified conditions for adding reviewers based on the count of changed files.

Possibly related PRs

Suggested labels

ready-to-merge, autoapproved

Suggested reviewers

  • derberg
  • akshatnema
  • magicmatatjahu
  • anshgoyalevil
  • devilkiller-ag
  • asyncapi-bot-eve

🐰 In the garden, changes bloom,
A workflow spruced, dispelling gloom.
Commit messages now shine bright,
With cleaner steps, all feels right.
Reviewers gather, files in sight,
Hopping forward, all with delight! 🌼


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.

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit aadb343
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6757e740a7ce4d0008359a50
😎 Deploy Preview https://deploy-preview-3460--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

Tested the workflow here
sambhavgupta0705#5
cc: @akshatnema @anshgoyalevil @devilkiller-ag

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.22%. Comparing base (7f81142) to head (aadb343).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3460   +/-   ##
=======================================
  Coverage   77.22%   77.22%           
=======================================
  Files          21       21           
  Lines         663      663           
=======================================
  Hits          512      512           
  Misses        151      151           

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

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Dec 9, 2024

⚡️ Lighthouse report for the changes in this PR:

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

Lighthouse ran on https://deploy-preview-3460--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: 0

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

20-23: Consider making the commit message extraction more robust

The current implementation might:

  1. Remove legitimate characters from commit messages (e.g., brackets in conventional commit scopes)
  2. Lose important formatting due to aggressive sanitization

Consider this more selective sanitization:

- commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
+ # Only remove characters that could cause issues in GitHub API calls
+ commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | tr '\n' ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')

46-46: Remove outdated version comment

The inline comment references version 42.1.0 but the action is using v45.

- uses: tj-actions/changed-files@v45 # version 42.1.0 https://github.com/tj-actions/changed-files/releases/tag/v42.1.0
+ uses: tj-actions/changed-files@v45

50-50: Fix formatting issues

Remove the trailing whitespace and empty lines.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 50-50: trailing spaces

(trailing-spaces)


100-100: Fix file formatting

Add a newline at the end of the file and remove trailing whitespace.

🧰 Tools
🪛 yamllint (1.35.1)

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

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


[error] 100-100: 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 cd391cc and e230dde.

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

[error] 50-50: trailing spaces

(trailing-spaces)


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

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


[error] 100-100: trailing spaces

(trailing-spaces)

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

40-43: LGTM! Good practice using a pinned version.

The addition of this step with a specific version tag improves stability and reliability.


87-87: LGTM! Consistent with the workflow's purpose.

The condition correctly triggers doc reviewer notifications when markdown files are changed.


72-72: LGTM! This fixes the core issue.

The condition correctly prevents code reviewer notifications when only markdown files are changed by comparing the total changed files count with markdown files count.

Let's verify the logic works as expected:

✅ Verification successful

Logic verification confirms this is a correct implementation

The workflow implementation correctly handles the core requirement:

  • Uses changed-files action twice:
    1. First to get all changed files count (steps.changed-files.outputs.all_changed_files_count)
    2. Second to get markdown files count (steps.md-pr-changes.outputs.all_changed_files_count) with **.md filter
  • The condition steps.changed-files.outputs.all_changed_files_count != steps.md-pr-changes.outputs.all_changed_files_count will:
    • Be true when there are non-markdown changes (triggering code reviewer notification)
    • Be false when all changes are markdown files (skipping code reviewer notification)
  • The merge commit check (steps.check-merge-branch.outputs.isMergeCommit == 'false') properly prevents notifications for merge commits
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Test the condition with different file change scenarios

# Create test PR with only MD changes
cat << EOF > test_changes.json
{
  "md_only": {
    "changed_files": ["docs/a.md", "docs/b.md"],
    "expected": "should_not_notify_code_reviewers"
  },
  "mixed": {
    "changed_files": ["docs/a.md", "src/code.js"],
    "expected": "should_notify_code_reviewers"
  }
}
EOF

# Verify the workflow handles these cases
gh workflow run notify-triager.yml --json test_changes.json

Length of output: 244


Script:

#!/bin/bash
# Let's verify the workflow logic by examining the actual implementation

# First, check the workflow file content
cat .github/workflows/notify-triager.yml

# Then, let's examine the steps that provide the outputs used in the condition
rg -A 2 "id: changed-files" .github/workflows/notify-triager.yml
rg -A 2 "id: md-pr-changes" .github/workflows/notify-triager.yml

Length of output: 4347

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

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

20-23: Consider optimizing the commit message sanitization.

The current implementation works but could be more efficient. Consider combining the multiple sed commands into a single operation.

- commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
+ commit_message=$(echo "$commit_message" | sed 's/[<>|()[\]]//g' | xargs)

50-50: Remove unnecessary empty lines in the file pattern section.

The empty lines after the file pattern are unnecessary and flagged by the linter.

      files: |
        **.md
-
-
🧰 Tools
🪛 yamllint (1.35.1)

[error] 50-50: trailing spaces

(trailing-spaces)


100-100: Remove trailing whitespace.

Remove the trailing whitespace on line 100 to fix the linting error.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 100-100: 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 e230dde and 02b18ed.

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

[error] 50-50: trailing spaces

(trailing-spaces)


[error] 100-100: trailing spaces

(trailing-spaces)

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

72-72: The reviewer assignment logic looks good.

The conditions correctly handle:

  1. Code reviewers: Only notified when non-markdown files are changed
  2. Doc reviewers: Only notified when markdown files are changed

This aligns with the PR objective to fix incorrect notifications.

Let's verify the logic works as expected:

Also applies to: 87-87

✅ Verification successful

Let me try a different approach to verify the logic by examining the workflow file directly.


After examining the workflow file, I can now generate the final response:

The reviewer assignment logic is correctly implemented

The conditions for assigning reviewers are properly structured:

  • Code reviewers are notified when:

    • The commit is not a merge commit (isMergeCommit == 'false')
    • There are non-markdown files changed (all_changed_files_count != md-pr-changes.outputs.all_changed_files_count)
  • Doc reviewers are notified when:

    • The commit is not a merge commit (isMergeCommit == 'false')
    • Any markdown files are changed (any_changed == 'true')

The implementation uses the correct outputs from the changed-files action and properly handles both scenarios, ensuring reviewers are only notified for relevant changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Test the reviewer assignment logic with different file change scenarios

# Scenario 1: Only markdown files
echo "Testing scenario with only markdown files..."
gh pr create --draft --title "test: only md changes" --body "test" --base main
touch test.md
git add test.md
git commit -m "test: add markdown file"
git push

# Scenario 2: Mixed files
echo "Testing scenario with mixed files..."
gh pr create --draft --title "test: mixed changes" --body "test" --base main
touch test.md test.js
git add test.md test.js
git commit -m "test: add mixed files"
git push

# Check the workflow runs
gh run list --workflow=notify-triager.yml --limit 2

Length of output: 2339


Script:

#!/bin/bash
# Check the workflow file content
cat .github/workflows/notify-triager.yml

# Find all workflow runs that used this workflow
gh run list --workflow=notify-triager.yml --json conclusion,event,displayTitle --limit 10

Length of output: 5251

Comment on lines +40 to +43
- name: Get all changed files
id: changed-files
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use version tags instead of commit hashes for action versions.

Using a specific commit hash (aa08304bd477b800d468db44fe10f6c61f7f7b11) for the action version is risky as the commit could be force-pushed or deleted. The AI summary indicates that this should be using v45.

- uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11
+ uses: tj-actions/changed-files@v45
📝 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
- name: Get all changed files
id: changed-files
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11
- name: Get all changed files
id: changed-files
uses: tj-actions/changed-files@v45

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

@asyncapi/bounty_team

@@ -68,7 +69,7 @@ jobs:
echo "codeTriagers=$codeTriagers" >> $GITHUB_ENV

- name: Add Reviewers for code files
if: steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.non-md-pr-changes.outputs.any_changed == 'true'
if: ${{ steps.check-merge-branch.outputs.isMergeCommit == 'false' && steps.changed-files.outputs.all_changed_files_count != steps.md-pr-changes.outputs.all_changed_files_count }}
Copy link
Member

Choose a reason for hiding this comment

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

What if the changed-files.outputs.all_changed_files_count is equal to steps.md-pr-changes.outputs.all_changed_files_count?
Can you please explain exactly what that check means?

Copy link
Member Author

Choose a reason for hiding this comment

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

For this we are checking for non md files
If the count is not equal that means there are some non md files also which needs to be reviewed by code reviewers

Copy link
Member Author

Choose a reason for hiding this comment

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

tj-actions doesn't have any mechanism for non md files so that's why I implemented this or else we need to check for many file extensions

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Good catch

Copy link
Member

@anshgoyalevil anshgoyalevil Dec 10, 2024

Choose a reason for hiding this comment

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

Though I am still curious about the ambigious behavior of this workflow. For example, examine this PR

#3245 (comment)

See how MD triagers are getting assigned as PR reviewers even though there was no merge commit or a MD file change

Another instance of this issue:
#3075 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Perfect workflow for notifying triagers
4 participants