Skip to content

Conversation

@github-actions
Copy link
Contributor

Summary

Cleaned check_permissions.cjs by applying modern JavaScript patterns and improving code clarity.

Changes Made

Code Improvements

  • Used destructuring for context properties - Extracted eventName, actor, and repo from context in a single destructuring operation
  • Avoided property shadowing - Renamed destructured repo property to repoName when further destructuring owner and repo from context.repo
  • Reduced nested destructuring - Combined extraction of owner and repo from context.repo into the function's destructuring pattern
  • Reduced file size - From 50 to 48 lines (2 lines saved)

Execution Context

  • Context: github-script (uses core, github, and context globals)
  • Type checking: Already enabled with @ts-check directive
  • JSDoc annotations: Already present and comprehensive

Testing

  • Existing tests: 14 comprehensive test cases covering all scenarios
  • New tests added: 0 (existing coverage already comprehensive)
  • Test coverage: All scenarios covered (safe events, permissions validation, error handling, different actors)

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
Tests: npm run test:js -- check_permissions.test.cjs - All 14 tests passed

Code Comparison

Before:

async function main() {
  const { eventName } = context;
  // ...
  const actor = context.actor;
  const { owner, repo } = context.repo;
  const requiredPermissions = parseRequiredPermissions();
  // ...
  const result = await checkRepositoryPermission(actor, owner, repo, requiredPermissions);
}

After:

async function main() {
  const { eventName, actor, repo } = context;
  const { owner, repo: repoName } = repo;
  // ...
  const requiredPermissions = parseRequiredPermissions();
  // ...
  const result = await checkRepositoryPermission(actor, owner, repoName, requiredPermissions);
}

Impact

  • No breaking changes - All original functionality preserved
  • Improved readability - More concise and modern JavaScript patterns
  • Type safety maintained - TypeScript checking enabled and passing
  • Test coverage maintained - All 14 existing tests passing

Part of the ongoing effort to modernize and clean JavaScript files in the actions/setup/js/ directory.

AI generated by jsweep - JavaScript Unbloater

@pelikhan
Copy link
Contributor

@copilot add tests

Copy link
Contributor

Copilot AI commented Jan 25, 2026

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

@pelikhan pelikhan merged commit 1505836 into main Jan 25, 2026
50 checks passed
@pelikhan pelikhan deleted the jsweep-clean-check-permissions-c972a94c40363ff1 branch January 25, 2026 18: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.

2 participants