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

Soft fail in cases where label is not present #1473

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Changes from all 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
25 changes: 19 additions & 6 deletions .github/actions/remove-label/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,22 @@ runs:
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: ${{ steps.resolve_issue_number.outputs.issue }},
owner: context.repo.owner,
repo: context.repo.repo,
name: ['${{ inputs.label }}']
})
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);
}
}
}
Comment on lines +38 to +54
Copy link
Contributor

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();
+           })();


removeLabel();