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

Fixes PR thank you msg. from potentially tagging the PR author twice #9228

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

Conversation

JavidSumra
Copy link
Contributor

@JavidSumra JavidSumra commented Nov 28, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update [product documentation](https://docs.ohc.network).
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews

Summary by CodeRabbit

  • Chores
    • Improved the workflow for tagging contributors in thank-you notes, ensuring a consistent and streamlined approach.

@JavidSumra JavidSumra requested a review from a team as a code owner November 28, 2024 07:21
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The pull request modifies the workflow file .github/workflows/thank-you.yml to improve the process of tagging users in thank-you notes for contributors. It consolidates the logic for creating comment bodies by using a single variable, taggedUsers, which is determined by the presence of assignees. This change simplifies the comment creation step and eliminates conditional logic, resulting in a more streamlined and consistent approach to generating thank-you messages.

Changes

File Change Summary
.github/workflows/thank-you.yml Consolidated logic for tagging users in thank-you messages; introduced taggedUsers variable to simplify comment creation.

Assessment against linked issues

Objective Addressed Explanation
Should only mention once (#[9224])

Possibly related PRs

  • added non-core-qn workflow #8889: The changes in the main PR regarding the workflow file .github/workflows/thank-you.yml and the introduction of streamlined logic for handling contributors are related to the workflow automation theme present in the notify-non-core-qn.yml file, which also focuses on enhancing contributor interactions through automated notifications.

Suggested labels

changes required, Deploy-Failed

Poem

🐰 In the meadow where bunnies play,
Thank-you notes now brighten the day.
With tags that are neat, and logic so clear,
We hop with joy, spreading good cheer!
No more double pings, just one little shout,
For every kind deed, we’re thankful, no doubt! 🌼


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 28, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit e179fc2
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67483358f20e3a0008a8a56e
😎 Deploy Preview https://deploy-preview-9228--care-ohc.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.

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 (1)
.github/workflows/thank-you.yml (1)

40-43: Remove trailing spaces

There are trailing spaces at the end of these lines that should be removed.

Apply this diff to fix the formatting:

-            await github.rest.issues.createComment({ 
-              ...options, 
-              body: `${taggedUsers} ${thankyouNote}` 
-            });
+            await github.rest.issues.createComment({
+              ...options,
+              body: `${taggedUsers} ${thankyouNote}`
+            });
🧰 Tools
🪛 yamllint (1.35.1)

[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 42-42: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6bea49a and a0b0114.

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

[error] 36-36: trailing spaces

(trailing-spaces)


[error] 37-37: trailing spaces

(trailing-spaces)


[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 42-42: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/thank-you.yml (1)

36-43: Verify thank-you message handling across the codebase

Let's ensure there are no other locations handling thank-you messages that might need similar updates.

✅ Verification successful

Changes to thank-you message handling are isolated

The changes to user mention handling in the thank-you workflow are isolated to this single file. The workflow is self-contained and there are no other instances of similar thank-you message handling or user mention patterns that would need to be updated.

  • The only implementation of thank-you message handling is in .github/workflows/thank-you.yml
  • The user mention logic (@login) is specific to this workflow and doesn't affect other parts of the codebase
  • No test files need to be updated as this is a standalone GitHub workflow
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other files that might handle thank-you messages or user mentions
rg -l "thank.*you|createComment|@.*login" --type yaml

Length of output: 55


Script:

#!/bin/bash
# Let's try a broader search across all file types for thank-you message handling
rg -i "thank.*you|createcomment|@.*login" .

# Also search for workflow files specifically
fd -e yml -e yaml . .github/workflows/

Length of output: 985


Script:

#!/bin/bash
# Let's check the content of other workflow files for similar patterns
cat .github/workflows/thank-you.yml

# Also search for any other files that might be creating comments or handling user mentions
rg "github.*createComment|@.*login|taggedUsers" -A 3 -B 3

Length of output: 1486

🧰 Tools
🪛 yamllint (1.35.1)

[error] 36-36: trailing spaces

(trailing-spaces)


[error] 37-37: trailing spaces

(trailing-spaces)


[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 42-42: trailing spaces

(trailing-spaces)

.github/workflows/thank-you.yml Outdated Show resolved Hide resolved
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/thank-you.yml (3)

21-21: Consider externalizing the thank you message

The thank you message is currently hardcoded and contains domain-specific content. Consider moving it to a configuration file for better maintainability and reusability.


36-38: Add validation for user login values

Consider adding validation to ensure user login values are valid before creating mentions.

             const taggedUsers = Array.from(uniqueUsers)
+              .filter(login => login && login.trim())
               .map(login => '@' + login)
               .join(' ');

40-43: Remove trailing spaces

There are trailing spaces in the comment creation block that should be removed.

-            await github.rest.issues.createComment({ 
-              ...options, 
-              body: `${taggedUsers} ${thankyouNote}` 
+            await github.rest.issues.createComment({
+              ...options,
+              body: `${taggedUsers} ${thankyouNote}`
             });
🧰 Tools
🪛 yamllint (1.35.1)

[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 42-42: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a0b0114 and 69824d9.

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

[error] 40-40: trailing spaces

(trailing-spaces)


[error] 41-41: trailing spaces

(trailing-spaces)


[error] 42-42: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/thank-you.yml (1)

30-34: LGTM! Effective solution for preventing duplicate mentions

The use of Set for deduplication is an elegant solution that directly addresses the issue of duplicate pings mentioned in #9224.

.github/workflows/thank-you.yml Outdated Show resolved Hide resolved
.github/workflows/thank-you.yml Outdated Show resolved Hide resolved
.github/workflows/thank-you.yml Outdated Show resolved Hide resolved
.github/workflows/thank-you.yml Outdated Show resolved Hide resolved
@rithviknishad rithviknishad changed the title Fix Duplicate ping author Fixes PR thank you msg. from potentially tagging the PR author twice Nov 28, 2024
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 (1)
.github/workflows/thank-you.yml (1)

30-32: LGTM! Effective deduplication implementation

The use of Set effectively prevents duplicate mentions, addressing the core issue. However, there are some trailing whitespace issues to clean up.

-            const taggedUsers = [...new Set(
-              assignees.map(u => "@"+u.login).concat("@"+user.login)  
-            )].join(" ")
+            const taggedUsers = [...new Set(
+              assignees.map(u => "@"+u.login).concat("@"+user.login)
+            )].join(" ");
🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 69824d9 and e179fc2.

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

[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 35-35: trailing spaces

(trailing-spaces)


[error] 36-36: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
.github/workflows/thank-you.yml (3)

21-21: LGTM! Well-formatted thank you message

The message content is appropriate and properly formatted.


30-32: Verify the fix prevents duplicate pings

Let's confirm the deduplication works as expected.

✅ Verification successful

Deduplication implementation verified successfully

The implementation effectively prevents duplicate pings by:

  • Using Set to ensure unique user mentions by combining assignees and PR author
  • Having a single workflow file (.github/workflows/thank-you.yml) that handles thank you comments
  • Implementing a clean approach to user mentions that won't cause duplicate notifications
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the deduplication logic by checking for potential duplicate scenarios

# Test: Check if there are any other thank you workflows that might cause duplicate pings
echo "Checking for other thank you workflows..."
fd -e yml -e yaml . .github/workflows/ --exec grep -l "thank.*you" {}

# Test: Look for other places where we might be creating comments that could cause duplicate pings
echo "Checking for other comment creation patterns..."
rg -l "createComment.*thank.*you" .

Length of output: 341


Script:

#!/bin/bash
# Let's examine the thank-you workflow implementation more closely

# Check the complete thank-you workflow file
echo "Content of thank-you workflow:"
cat .github/workflows/thank-you.yml

# Look for any other potential user mention patterns
echo -e "\nChecking for other user mention patterns:"
rg "@\{.*login" .

Length of output: 1442

🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)


28-28: 🛠️ Refactor suggestion

Add error handling for the API call

The API call could fail silently. Consider adding error handling to provide better debugging information.

-            const { data : { assignees, user } } = await github.rest.issues.get(options);
+            let assignees, user;
+            try {
+              const { data: { assignees: a, user: u } } = await github.rest.issues.get(options);
+              assignees = a;
+              user = u;
+            } catch (error) {
+              core.setFailed(`Failed to fetch issue details: ${error.message}`);
+              return;
+            }

Likely invalid or redundant comment.

Comment on lines +34 to +37
await github.rest.issues.createComment({
...options,
body: `${taggedUsers} ${thankyouNote}`
});
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 error handling and fix formatting

The comment creation logic looks good, but needs error handling and formatting fixes.

-            await github.rest.issues.createComment({ 
-              ...options, 
-              body: `${taggedUsers} ${thankyouNote}` 
-            });
+            try {
+              await github.rest.issues.createComment({
+                ...options,
+                body: `${taggedUsers} ${thankyouNote}`
+              });
+            } catch (error) {
+              core.setFailed(`Failed to create thank you comment: ${error.message}`);
+            }
📝 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
await github.rest.issues.createComment({
...options,
body: `${taggedUsers} ${thankyouNote}`
});
try {
await github.rest.issues.createComment({
...options,
body: `${taggedUsers} ${thankyouNote}`
});
} catch (error) {
core.setFailed(`Failed to create thank you comment: ${error.message}`);
}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 34-34: trailing spaces

(trailing-spaces)


[error] 35-35: trailing spaces

(trailing-spaces)


[error] 36-36: trailing spaces

(trailing-spaces)

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

🧹 Outside diff range and nitpick comments (2)
.github/workflows/thank-you.yml (2)

28-32: LGTM! Consider a more concise implementation.

The use of Set for deduplication effectively solves the issue of duplicate pings. However, the implementation could be more concise.

Consider this more concise version:

-            const taggedUsers = [...new Set(
-              assignees.map(u => "@"+u.login).concat("@"+user.login)  
-            )].join(" ")
+            const taggedUsers = [...new Set([
+              ...assignees.map(u => `@${u.login}`),
+              `@${user.login}`
+            ])].join(' ');

Also, please fix the trailing spaces at line 31.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)


34-37: LGTM! Fix formatting issues.

The comment creation logic is clean and correctly implemented. However, please fix the trailing spaces at lines 34, 35, and 36.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 34-34: trailing spaces

(trailing-spaces)


[error] 35-35: trailing spaces

(trailing-spaces)


[error] 36-36: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 69824d9 and e179fc2.

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

[error] 31-31: trailing spaces

(trailing-spaces)


[error] 34-34: trailing spaces

(trailing-spaces)


[error] 35-35: trailing spaces

(trailing-spaces)


[error] 36-36: trailing spaces

(trailing-spaces)

🔇 Additional comments (2)
.github/workflows/thank-you.yml (2)

21-26: LGTM!

The thank you note and options setup are well-structured and appropriate for the context.


30-32: Verify the deduplication works as expected.

Let's confirm the solution prevents duplicate pings in various scenarios.

✅ Verification successful

Deduplication implementation is correctly implemented

The implementation uses JavaScript's Set data structure which guarantees unique values, and the logic is sound:

  1. assignees.map() creates an array of "@username" strings for all assignees
  2. .concat("@"+user.login) adds the PR author's username
  3. new Set() removes any duplicates if the PR author was also an assignee
  4. join(" ") creates a space-separated string of unique @mentions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test the deduplication logic by checking if there are any remaining instances 
# of duplicate user mentions in thank you comments

# Search for thank you comments with duplicate mentions
rg -l '@\w+.*@\w+.*thank.*you' .

Length of output: 34


Script:

#!/bin/bash
# Let's analyze the implementation more thoroughly

# First, check the thank-you workflow implementation
cat .github/workflows/thank-you.yml

# Then search for any test files related to this functionality
fd -t f "thank.*test" -E "node_modules"

Length of output: 1292

🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: trailing spaces

(trailing-spaces)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thank you message pings user two times
3 participants