-
Notifications
You must be signed in to change notification settings - Fork 33
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
Soft fail in cases where label is not present #1473
Conversation
WalkthroughThe changes primarily focus on enhancing error handling and feedback in the GitHub Actions workflow for removing labels. The code now uses asynchronous functions and provides more informative logging, especially when a label is not found on an issue or pull request. Changes
TipsChat with CodeRabbit Bot (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1473 +/- ##
=============================================
Coverage 50.69204% 50.69204%
=============================================
Files 356 356
Lines 24276 24276
Branches 268 268
=============================================
Hits 12306 12306
Misses 10775 10775
Partials 1195 1195
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Files selected for processing (1)
- .github/actions/remove-label/action.yml (2 hunks)
Additional comments (Suppressed): 2
.github/actions/remove-label/action.yml (2)
- 2-2: The description of the action has been changed from "Remove a label to the issue or pull request" to "Remove\ a label to the issue or pull request". The backslash before the space seems unnecessary and might be a typo. Please verify.
- description: Remove\ a label to the issue or pull request + description: Remove a label from the issue or pull request
- 38-56: The code has been refactored to use an async function and a try-catch block for improved error handling. This is a good practice as it allows for better control over the flow of the program and makes it easier to handle errors. The logging for cases when the label does not exist on the issue is a good addition as it provides better feedback in such scenarios. However, the function
removeLabel
is declared and immediately invoked. It would be more readable and maintainable to directly execute the code without wrapping it in a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (1)
- .github/actions/remove-label/action.yml (1 hunks)
Additional comments (Suppressed): 2
.github/actions/remove-label/action.yml (2)
44-44: The label name is now passed as a string instead of an array. This change is correct as the
removeLabel
method expects a string for the label name. However, please verify that this change does not affect other parts of the code that may be expecting an array.48-52: The error handling has been improved to provide more specific feedback. If the label does not exist on the issue (status code 404), a log message is generated. For other errors, the error message is logged. This is a good practice as it provides more detailed feedback and makes debugging easier.
async function removeLabel() { | ||
try { | ||
await github.rest.issues.removeLabel({ | ||
issue_number: ${{ steps.resolve_issue_number.outputs.issue }}, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: '${{ inputs.label }}' | ||
}); | ||
} catch (error) { | ||
// Log the error if it's about the label not being present. | ||
if (error.status === 404) { | ||
console.log(`The label '${{ inputs.label }}' does not exist on the issue.`); | ||
} else { | ||
console.error('Unexpected error:', error); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new hunk introduces an async function removeLabel
to handle the label removal process. This function includes a try-catch block to handle errors, which is a good practice for error handling. However, the function is not awaited when called on line 56, which could lead to unhandled promise rejections if an error occurs. To fix this, you should use an immediately invoked function expression (IIFE) to allow awaiting the removeLabel
function.
- removeLabel();
+ (async () => {
+ await removeLabel();
+ })();
#1466 introduced a regression where if label is not present,
./.github/actions/remove-label
will exit w/ status code 1. This is problematic since inpackages.yml
, we always try to remove the label (see this failure on #472 for example):Summary by CodeRabbit