Skip to content

[jsweep] Clean campaign_discovery.cjs - #11518

Merged
pelikhan merged 2 commits into
mainfrom
jsweep-campaign-discovery-2026-01-23-01ec0b0064ef6ac0
Jan 23, 2026
Merged

[jsweep] Clean campaign_discovery.cjs#11518
pelikhan merged 2 commits into
mainfrom
jsweep-campaign-discovery-2026-01-23-01ec0b0064ef6ac0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Cleaned campaign_discovery.cjs by extracting duplicate pagination logic into a reusable helper function and modernizing the code with ES6+ patterns.

Context

Execution context: github-script (uses core.info(), core.warning(), github API)

Lines changed: 570 → 463 lines (107 lines saved, 18.8% reduction)

Key Improvements

Code Deduplication

  • Extracted searchItems helper function: Eliminated 120+ lines of duplicate pagination logic between searchByTrackerId and searchByLabel
  • Both search functions now use a single, reusable pagination implementation
  • Reduced code duplication while maintaining identical behavior

Modernization

  • Simplified buildScopeParts using spread operator and optional chaining (repos?.length)
  • Replaced try-catch blocks with .catch() chaining for cleaner error handling
  • Optimized array filtering by computing openItems, closedItems, mergedItems once and reusing
  • Combined sort comparison with logical OR operator (|| instead of nested if)
  • Simplified budget exhaustion logic with nested ternary expressions

Function Improvements

  • buildScopeParts: 10 lines → 5 lines (spread operator, optional chaining)
  • searchByTrackerId: 79 lines → 17 lines (uses searchItems helper)
  • searchByLabel: 79 lines → 17 lines (uses searchItems helper)
  • discover: Multiple optimizations including cached filter results

Test Coverage

All 17 test cases pass (100% success rate)

Tests cover:

  • Item normalization (issues, PRs, closed, merged)
  • Cursor persistence
  • Pagination budgets
  • Multi-repo/org queries
  • Discovery manifest generation
  • Deterministic sorting
  • Summary count calculations

Validation Results

All checks passed:

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js ✓ (17/17 tests passed)

File Changes

  • actions/setup/js/campaign_discovery.cjs: Main implementation
  • actions/setup/js/campaign_discovery.test.cjs: Updated imports to include new exports

Labels

unbloat, automation

AI generated by jsweep - JavaScript Unbloater

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot format, lint, add tests

CopilotAI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

@pelikhan I've opened a new pull request, #11552, to work on those changes. Once the pull request is ready, I'll request review from you.

@pelikhan
pelikhan merged commit 7363c70 into mainJan 23, 2026
49 checks passed
@pelikhan
pelikhan deleted the jsweep-campaign-discovery-2026-01-23-01ec0b0064ef6ac0 branch January 23, 2026 19:53
Sign up for freeto 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.

2 participants

@pelikhan