-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: onboard command #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Eomm
wants to merge
3
commits into
main
Choose a base branch
from
onboard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+137
−14
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GITHUB_TOKEN=YOUR_GITHUB_TOKEN_HERE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,59 @@ | ||
import readline from 'node:readline/promises' | ||
|
||
/** | ||
* Onboards a user to an organization. | ||
* @param {{ client: import('../github-api.js').default, logger: import('pino').Logger }} deps | ||
* @param {{ org: string, username: string, dryRun: boolean }} options | ||
* @returns {Promise<void>} | ||
*/ | ||
export default async function onboard ({ client, logger }, { org, username, dryRun }) { | ||
const orgId = await client.getOrgId(org) | ||
logger.info('Organization ID %s', orgId) | ||
export default async function onboard ({ client, logger }, { org, username, joiningTeams, dryRun }) { | ||
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) | ||
} | ||
|
||
const orgChart = await client.getOrgChart(org) | ||
const orgData = await client.getOrgData(org) | ||
logger.info('Organization ID %s', orgData.id) | ||
|
||
const orgTeams = await client.getOrgChart(orgData) | ||
const destinationTeams = orgTeams.filter(t => joiningTeams.includes(t.slug)) | ||
if (destinationTeams.length !== joiningTeams.length) { | ||
const missing = joiningTeams.filter(t => destinationTeams.find(dt => dt.slug === t) == null) | ||
logger.error('Team %s not found in organization %s', missing, org) | ||
process.exit(1) | ||
} | ||
|
||
// TODO Implement onboarding logic here | ||
if (dryRun) { | ||
logger.info(`[DRY RUN] Would onboard user: ${username}`) | ||
logger.info('[DRY-RUN] This user %s should be added to team %s', joiningUser.login, destinationTeams.map(t => t.slug)) | ||
} else { | ||
logger.info(`Onboarding user: ${username}`) | ||
for (const targetTeam of destinationTeams) { | ||
await client.addUserToTeam(org, targetTeam.slug, joiningUser.login) | ||
logger.info('Added %s to team %s', joiningUser.login, targetTeam.slug) | ||
} | ||
} | ||
|
||
logger.info('GitHub onboarding completed for user %s ✅ ', joiningUser.login) | ||
|
||
logger.warn('To complete the NPM onboarding, please following these steps:') | ||
// This step cannot be automated, there are no API to add members to an org on NPM | ||
logger.info('1. Invite the user to the organization on NPM: https://www.npmjs.com/org/%s/invite?track=existingOrgAddMembers', org) | ||
logger.info('2. Add the user to the relevant teams by using the commands:'); | ||
[ | ||
{ slug: 'developers' }, // NPM has a default team for every org | ||
...destinationTeams | ||
].forEach(team => { | ||
logger.info('npm team add @%s:%s %s', org, team.slug, joiningUser.login) | ||
}) | ||
logger.info('When it will be done, the NPM onboarding will be completed for user %s ✅ ', joiningUser.login) | ||
} | ||
|
||
async function confirm (q) { | ||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}) | ||
const answer = await rl.question(`${q} (y/n)`) | ||
rl.close() | ||
return answer.trim().toLowerCase() === 'y' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you use the Set difference?
If you make
joiningTeams
a set, you can also use it on line 20, to replace the includes with the has.