Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 1, 2026

Summary

Cleaned and modernized campaign_labels.cjs with improved modern JavaScript patterns and comprehensive test coverage.

Changes Made

Code Improvements

  • Nullish coalescing: Replaced || with ?? for more precise null/undefined handling in getCampaignLabelsFromEnv()
  • Inline function call: Removed intermediate specificLabel variable and inlined formatCampaignLabel() call
  • Code clarity: Maintained clean, readable code with proper JSDoc annotations

Test Coverage

Created comprehensive test suite (campaign_labels.test.cjs) with 18 test cases:

formatCampaignLabel tests (8):

  • ✅ Simple campaign ID formatting
  • ✅ Uppercase to lowercase conversion
  • ✅ Space replacement with hyphens
  • ✅ Underscore replacement with hyphens
  • ✅ Mixed space/underscore handling
  • ✅ Numeric campaign IDs
  • ✅ Empty string edge case
  • ✅ Complex campaign ID patterns

getCampaignLabelsFromEnv tests (10):

  • ✅ No campaign ID (disabled)
  • ✅ Empty string (disabled)
  • ✅ Whitespace only (disabled)
  • ✅ Valid campaign ID (enabled with labels)
  • ✅ Trimming whitespace
  • ✅ Uppercase conversion
  • ✅ Space handling
  • ✅ Underscore handling
  • ✅ Complex campaign ID
  • ✅ Numeric campaign ID

Context

Execution Context: Node.js (pure CommonJS module)

This is a utility module that normalizes campaign IDs and retrieves campaign labels from environment variables. It's used by the safe outputs system to add campaign-specific labels to GitHub resources.

Validation Results

All validation checks passed successfully:

  • Formatting: npm run format:cjs - All files formatted correctly
  • Linting: npm run lint:cjs - No linting errors
  • Type checking: npm run typecheck - No type errors (already had @ts-check enabled)
  • Tests: npm run test:js - 18/18 tests passed (100% pass rate)

Stats

  • Lines changed: 4 lines modified in source file
  • Test file: 138 lines added
  • Test cases: 18 comprehensive test cases
  • Test coverage: All public functions fully tested with edge cases

AI generated by jsweep - JavaScript Unbloater

- Use nullish coalescing (??) for more precise null/undefined handling
- Inline formatCampaignLabel call to reduce intermediate variable
- Add comprehensive test suite with 18 test cases
  - 8 tests for formatCampaignLabel (various input formats)
  - 10 tests for getCampaignLabelsFromEnv (enabled/disabled states)
- All validation checks passed:
  ✅ Format: npm run format:cjs
  ✅ Lint: npm run lint:cjs
  ✅ Type check: npm run typecheck
  ✅ Tests: 18/18 passed
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.

1 participant