Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Refactors check_team_member.cjs and its test file to use modern JavaScript patterns and eliminate comma operator abuse that severely impacted readability.

Main File (check_team_member.cjs)

  • Add JSDoc type annotation for main() function
  • Use object property shorthand in API call: { owner, repo } instead of { owner: owner, repo: repo }

Test File (check_team_member.test.cjs)

The test file extensively abused the comma operator to chain statements, making it difficult to read and maintain:

Before:

// Variable declarations chained with commas
const mockCore = { /* ... */ },
  mockGithub = { /* ... */ },
  mockContext = { /* ... */ };

// Test logic all on one line with comma operators
((global.context.actor = "different-user"),
  mockGithub.rest.repos.getCollaboratorPermissionLevel.mockResolvedValue({ data: { permission: "admin" } }),
  await eval(`(async () => { ${checkTeamMemberScript}; await main(); })()`),
  expect(mockCore.setOutput).toHaveBeenCalledWith("is_team_member", "true"));

After:

// Proper const declarations
const mockCore = { /* ... */ };
const mockGithub = { /* ... */ };
const mockContext = { /* ... */ };

// Readable individual statements
global.context.actor = "different-user";
mockGithub.rest.repos.getCollaboratorPermissionLevel.mockResolvedValue({ data: { permission: "admin" } });
await eval(`(async () => { ${checkTeamMemberScript}; await main(); })()`);
expect(mockCore.setOutput).toHaveBeenCalledWith("is_team_member", "true");

Changes:

  • Replace !1 with false
  • Split comma-separated variable declarations into individual const statements
  • Convert comma operator chains into proper statement sequences
  • Maintain all 10 existing tests with identical coverage

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/repos/githubnext/gh-aw/actions/artifacts/5329152817/zip
    • Triggering command: /usr/bin/curl curl -L -H Accept: application/vnd.github+json -H Authorization: ****** X-GitHub-Api-Version: 2022-11-28 REDACTED -o agent-artifacts.zip (http block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>[jsweep] Clean check_team_member.cjs</issue_title>
<issue_description>## Summary

Cleaned check_team_member.cjs to use modern JavaScript patterns and improve code readability.

Changes Made

Main File (check_team_member.cjs)

  • ✅ Added JSDoc type annotation for main() function
  • ✅ Used object shorthand in API call: { owner, repo } instead of { owner: owner, repo: repo }
  • ✅ Code already had @ts-check directive and was fairly clean

Test File (check_team_member.test.cjs)

  • Removed extensive comma operator abuse throughout the file
  • ✅ Replaced !1 with false for better readability
  • ✅ Split comma-separated variable declarations into proper const declarations
  • ✅ Converted comma-separated test setup/expectations into individual statements
  • ✅ Improved test readability with proper statement separation

Validation Results

All validation checks passed successfully:

  • Format: npm run format:cjs - All files formatted correctly
  • Lint: npm run lint:cjs - All files pass linting
  • Type checking: npm run typecheck - No type errors
  • Tests: npm run test:js - 10/10 tests passed for check_team_member

Context

  • Execution context: GitHub Actions script (uses core, github, context globals)
  • Purpose: Checks if a user has admin or maintainer permissions on a repository
  • Test improvements: Eliminated comma operator abuse, making tests much more readable and maintainable

Test Coverage

The test file already had comprehensive coverage:

  • ✅ Admin permission check
  • ✅ Maintain permission check
  • ✅ Write permission check (denied)
  • ✅ Read permission check (denied)
  • ✅ None permission check (denied)
  • ✅ API error handling
  • ✅ Different actor names
  • ✅ Different repository contexts
  • ✅ Authentication error handling
  • ✅ Rate limiting error handling

All 10 tests pass successfully.

AI generated by jsweep - JavaScript Unbloater


[!NOTE]
This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download patch artifact

The patch file is available in the agent-artifacts artifact in the workflow run linked above.

To apply the patch locally:

# Download the artifact from the workflow run https://github.com/githubnext/gh-aw/actions/runs/21546230869
# (Use GitHub MCP tools if gh CLI is not available)
gh run download 21546230869 -n agent-artifacts

# The patch file will be at agent-artifacts/tmp/gh-aw/aw.patch after download
# Apply the patch
git am agent-artifacts/tmp/gh-aw/aw.patch
Show patch preview (370 of 370 lines)
From bc934b6bdcd39e56b82fed993ba1382065dba04f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 31 Jan 2026 15:00:54 +0000
Subject: [PATCH] [jsweep] Clean check_team_member.cjs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- Added JSDoc type annotations for main function
- Used object shorthand in API call (owner, repo instead of owner: owner)
- Improved test file by removing comma operator abuse
- Replaced             {                 echo ___BEGIN___COMMAND_OUTPUT_MARKER___;                 PS1=;PS2=;unset HISTFILE;                 EC=0;                 echo ___BEGIN___COMMAND_DONE_MARKER___0;             } with false for better readability
- Split comma-separated variable declarations into proper statements
- Improved test readability with proper statement separation

All validation checks passed:
- ✅ Format: npm run format:cjs
- ✅ Lint: npm run lint:cjs
- ✅ Type check: npm run typecheck
- ✅ Tests: npm run test:js (10/10 tests passed)

Context: GitHub Actions script (github-script)
Test improvements: Eliminated comma operator abuse, improved readability
---
 actions/setup/js/check_team_member.cjs      |   8 +-
 actions/setup/js/check_team_member.test.cjs | 301 ++++++++++++--------
 2 files changed, 186 insertions(+), 123 deletions(-)

diff --git a/actions/setup/js/check_team_member.cjs b/actions/setup/js/check_team_member.cjs
index 493f558..293c0ea 100644
--- a/actions/setup/js/check_team_member.cjs
+++ b/actions/setup/js/check_team_member.cjs
@@ -1,6 +1,10 @@
 // @ts-check
 /// <reference types="@actions/github-script" />
 
+/**
+ * Check if the actor is a team member (admin or maintainer)
+ * @returns {Promise<void>}
+ */
 async function main() {
   const actor = context.actor;
   const { owner, repo } = context.repo;
@@ -10,8 +14,8 @@ async function main() {
     core.info(`Checking if user '${actor}' is admin or maintainer of ${owner}/${repo}`)
... (truncated)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add JSDoc type annotation to main() function
- Use object shorthand in API call ({owner, repo})
- Remove comma operator abuse from test file
- Replace !1 with false
- Split comma-separated declarations into proper const
- Convert comma-separated statements to individual lines
- All 10 tests passing
- All linting and type checks passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Clean check_team_member.cjs for better readability Clean check_team_member.cjs: remove comma operator abuse and modernize Jan 31, 2026
Copilot AI requested a review from pelikhan January 31, 2026 16:45
@pelikhan pelikhan marked this pull request as ready for review January 31, 2026 16:46
@pelikhan pelikhan merged commit ffebf4b into main Jan 31, 2026
121 checks passed
@pelikhan pelikhan deleted the copilot/clean-check-team-member-file branch January 31, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jsweep] Clean check_team_member.cjs

2 participants