Skip to content

[jsweep] Clean add_labels.cjs#23417

Merged
pelikhan merged 2 commits intomainfrom
jsweep/clean-add-labels-d4dcb1eebb56c736
Mar 29, 2026
Merged

[jsweep] Clean add_labels.cjs#23417
pelikhan merged 2 commits intomainfrom
jsweep/clean-add-labels-d4dcb1eebb56c736

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Cleaned add_labels.cjs — the oldest uncleaned file — with targeted syntax modernizations and expanded test coverage.

Context

Execution context: github-script — uses core, github, context globals.

Changes to add_labels.cjs

  • Destructuring with defaults for allowed/blocked config arrays, replacing individual config.x || [] assignments:
    // Before
    const allowedLabels = config.allowed || [];
    const blockedPatterns = config.blocked || [];
    
    // After
    const { allowed: allowedLabels = [], blocked: blockedPatterns = [] } = config;
  • Collapsed single-line if bodies — logging statements like if (cond) { core.info(...) }if (cond) core.info(...) for conciseness
  • Removed inline stage comment (// Check if we're in staged mode) and // Extract configuration header comment — the code speaks for itself
  • maxCount keeps || 10 (not changed to ??) to preserve existing behavior where max: 0 falls back to the default 10

Changes to add_labels.test.cjs

Added 3 new edge case tests (29 → 32 tests total):

Test Purpose
should use default max=10 when config.max is not provided Documents the `
should handle labels array containing only whitespace strings gracefully Verifies whitespace-only labels are sanitized away (success=true, labelsAdded=[])
should log initialization info without allowed/blocked when not configured Verifies conditional logging works

Validation ✅

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs ✓ — All matched files use Prettier code style!
  • Type checking: npm run typecheck ✓ — No errors
  • Tests: npm run test:js -- --no-file-parallelism add_labels ✓ — 32 passed

The 14 failures in the full suite (assign_issue.test.cjs, git_helpers.test.cjs, safe_outputs_tools_loader.test.cjs) are pre-existing and unrelated to this change.

Generated by jsweep - JavaScript Unbloater ·

  • expires on Mar 31, 2026, 4:49 AM UTC

- Use destructuring with defaults for allowed/blocked config arrays
- Collapse single-line if-body logging statements for readability
- Remove redundant comments that restate the code
- Add 3 new edge case tests (total: 29 → 32 tests):
  - default max behavior when not provided
  - whitespace-only labels sanitized gracefully
  - initialization logging without allowed/blocked config

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 29, 2026 10:19
Copilot AI review requested due to automatic review settings March 29, 2026 10:19
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot merge main

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Modernizes and “cleans” the add_labels safe-output handler and expands its test coverage with additional edge cases.

Changes:

  • Refactors add_labels.cjs config extraction (destructuring defaults) and condenses some logging conditionals.
  • Adds 3 new edge-case tests to add_labels.test.cjs around max defaults, whitespace labels, and initialization logging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
actions/setup/js/add_labels.cjs Refactors config parsing/logging in the add-labels handler factory.
actions/setup/js/add_labels.test.cjs Adds new edge-case tests for default behavior and logging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +657 to +658
const result = await handler({ item_number: 1, labels: ["bug"] }, {});
expect(result.success).toBe(true);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name/doc comment says it verifies the default max=10, but it only asserts a single call succeeds. That would still pass for many incorrect defaults (e.g., 1, 100, or even undefined). To actually cover the || 10 behavior, assert that the handler allows 10 processed items and rejects the 11th (or otherwise observe maxCount being used).

Suggested change
const result = await handler({ item_number: 1, labels: ["bug"] }, {});
expect(result.success).toBe(true);
// First 10 items should succeed
for (let i = 1; i <= 10; i++) {
const result = await handler({ item_number: i, labels: ["bug"] }, {});
expect(result.success).toBe(true);
}
// 11th item should be rejected due to default max=10
const eleventhResult = await handler(
{ item_number: 11, labels: ["bug"] },
{}
);
expect(eleventhResult.success).toBe(false);

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +35
const { allowed: allowedLabels = [], blocked: blockedPatterns = [] } = config;
const maxCount = config.max || 10;
const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig(config);
const githubClient = await createAuthenticatedGitHubClient(config);

// Check if we're in staged mode
const isStaged = isStagedMode(config);

core.info(`Add labels configuration: max=${maxCount}`);
if (allowedLabels.length > 0) {
core.info(`Allowed labels: ${allowedLabels.join(", ")}`);
}
if (blockedPatterns.length > 0) {
core.info(`Blocked patterns: ${blockedPatterns.join(", ")}`);
}
if (allowedLabels.length > 0) core.info(`Allowed labels: ${allowedLabels.join(", ")}`);
if (blockedPatterns.length > 0) core.info(`Blocked patterns: ${blockedPatterns.join(", ")}`);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The destructuring default only applies when config.allowed/config.blocked are undefined, not when they are explicitly set to null. With the current change, a config like { allowed: null } will set allowedLabels to null and then allowedLabels.length will throw. The previous config.allowed || [] behavior treated null as “not configured”. Consider normalizing with const allowedLabels = config.allowed ?? [] and const blockedPatterns = config.blocked ?? [] (or equivalent) so null continues to fall back to [].

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review comments

…ls-d4dcb1eebb56c736

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

@copilot merge main

Done — merged origin/main into this branch (759a50e). Build and recompile completed successfully with no conflicts.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0 --jq .object.sha (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan March 29, 2026 10:28
@pelikhan pelikhan merged commit 1b303b2 into main Mar 29, 2026
53 of 54 checks passed
@pelikhan pelikhan deleted the jsweep/clean-add-labels-d4dcb1eebb56c736 branch March 29, 2026 10:31
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.

3 participants