Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion commands/offboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exit } from 'node:process'
import { confirm } from './utils/input.js'
import { removeFromNpm } from './utils/remove-from-npm.js'
/**
Expand All @@ -10,7 +11,7 @@ export default async function offboard ({ logger, client }, { org, username, dry
const joiningUser = await client.getUserInfo(username)
if (!await confirm(`Are you sure you want to offboard ${joiningUser.login} [${joiningUser.name}] to ${org}?`)) {
logger.warn('Aborting offboarding')
process.exit(0)
exit(0)
}

const orgData = await client.getOrgData(org)
Expand Down
5 changes: 3 additions & 2 deletions commands/onboard.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { exit } from 'node:process'
import { confirm } from './utils/input.js'

/**
Expand All @@ -10,7 +11,7 @@ export default async function onboard ({ client, logger }, { org, username, join
const joiningUser = await client.getUserInfo(username)
if (!await confirm(`Are you sure you want to onboard ${joiningUser.login} [${joiningUser.name}] to ${org}?`)) {
logger.warn('Aborting onboarding')
process.exit(0)
exit(0)
}

const orgData = await client.getOrgData(org)
Expand All @@ -23,7 +24,7 @@ export default async function onboard ({ client, logger }, { org, username, join
const wrongInputTeams = joiningTeams.difference(teamSlugs)
if (wrongInputTeams.size) {
logger.error('Team %s not found in organization %s', [...wrongInputTeams], org)
process.exit(1)
exit(1)
}

if (dryRun) {
Expand Down
5 changes: 3 additions & 2 deletions commands/utils/input.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stdin, stdout } from 'node:process'
import readline from 'node:readline/promises'

export async function confirm (q) {
Expand All @@ -7,8 +8,8 @@ export async function confirm (q) {

export async function askForInput (message) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
input: stdin,
output: stdout
})
const answer = await rl.question(message)
rl.close()
Expand Down
3 changes: 2 additions & 1 deletion commands/utils/remove-from-npm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { env } from 'node:process'
import { spawn } from 'node:child_process'
import { askForInput } from './input.js'

function runSpawn (cmd, args) {
return new Promise((resolve, reject) => {
const cli = spawn(cmd, args, { env: process.env })
const cli = spawn(cmd, args, { env })
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The spawn call now passes only the imported env object (which contains environment variables like GITHUB_TOKEN) instead of the full process.env. This changes the behavior - spawn expects the env option to be a complete environment object with all necessary variables (like PATH, HOME, etc.), not just a subset. The spawned npm process will lack critical system environment variables and will likely fail. Change to { env: env } to maintain the original behavior, or import the entire process.env if the intent was to pass all environment variables.

Copilot uses AI. Check for mistakes.
cli.stdout.setEncoding('utf8')
cli.stderr.setEncoding('utf8')

Expand Down
7 changes: 4 additions & 3 deletions github-api.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { env } from 'node:process'
import { Octokit } from '@octokit/rest'
import { graphql } from '@octokit/graphql'

export default class AdminClient {
/** @param {import('pino').Logger} [logger] */
constructor (logger) {
if (!process.env.GITHUB_TOKEN) {
if (!env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN environment variable is not set')
}

this.logger = logger || console
this.restClient = new Octokit({
auth: process.env.GITHUB_TOKEN,
auth: env.GITHUB_TOKEN,
userAgent: 'fastify-org-admin-cli',
})

this.graphqlClient = graphql.defaults({
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
authorization: `token ${env.GITHUB_TOKEN}`,
},
})
}
Expand Down
Loading