[jsweep] Clean add_labels.cjs - #7634
Closed
github-actions[bot] wants to merge 2 commits into
Closed
Conversation
Collaborator
|
@copilot format, lint, recompile |
Contributor
Collaborator
|
@copilot you need to modify the files in actions/setup |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR cleans up
pkg/workflow/js/add_labels.cjsby applying modern JavaScript patterns and simplifying the code structure.Context
This is a github-script context file that runs within GitHub Actions using the
actions/github-scriptaction. It has access tocore,github, andcontextas global objects.Improvements Made
1. Optional Chaining for Error Checking
labelsResult.error && labelsResult.error.includes("No valid labels")labelsResult.error?.includes("No valid labels")2. Simplified core.summary Calls
.addRaw()calls with separate string arguments.addRaw().write()3. Modern Error Handling
error instanceof Error ? error.message : String(error)error?.message ?? String(error)4. Cleaner Code Structure
Changes Overview
Testing
The file has comprehensive test coverage in
add_labels.test.cjswith 40+ test cases covering:All existing tests should continue to pass as the logic remains unchanged.
Benefits
Part of jsweep initiative: Daily JavaScript unbloating for cleaner, more maintainable code.