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

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/thank-you.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ jobs:
uses: actions/[email protected]
with:
script: |
const thankyouNote = 'Your efforts have helped advance digital healthcare and TeleICU systems. :rocket: Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! :raised_hands:'
const thankyouNote = 'Your efforts have helped advance digital healthcare and TeleICU systems. :rocket: Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! :raised_hands:';
const options = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
}
};

const result = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const { assignees, user } = await github.rest.issues.get(options);

const { assignees, user } = result.data
const uniqueUsers = new Set(
assignees.length > 0
? assignees.map(u => u.login)
: [user.login]
);

const assignees_tagged = assignees.map((user) => '@' + user.login).join(' ')
const owner_tagged = '@' + user.login
const taggedUsers = Array.from(uniqueUsers)
.map(login => '@' + login)
.join(' ');

if (assignees.length == 0) {
await github.rest.issues.createComment({ ...options, body: `${owner_tagged} ${thankyouNote}` })
} else {
await github.rest.issues.createComment({ ...options, body: `${assignees_tagged} ${owner_tagged} ${thankyouNote}` })
}
await github.rest.issues.createComment({
...options,
body: `${taggedUsers} ${thankyouNote}`
});
Comment on lines +34 to +37
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)

Loading