const { Octokit } = await npm("octokit");
const { createOAuthDeviceAuth } = await npm("@octokit/auth-oauth-device");
let octokit;
if (env.GITHUB_TOKEN_NO_SCOPES) {
octokit = new Octokit({
auth: env.GITHUB_TOKEN_NO_SCOPES,
});
} else {
const auth = createOAuthDeviceAuth({
clientType: "oauth-app",
clientId: "34e4eac44e03b0daa82b",
onVerification(verification) {
copy(verification.user_code);
arg({
placeholder: `Press <enter> after granting permissions`,
ignoreBlur: true,
hint: `
Open <a href="${verification.verification_uri}">${verification.verification_uri}</a>, paste code from clipboard
`,
});
},
});
const { token } = await auth({
type: "oauth",
});
octokit = new Octokit({
auth: token,
});
await cli("set-env-var", "GITHUB_TOKEN_NO_SCOPES", token);
}
const { data: me } = await octokit.rest.users.getAuthenticated();
const username = await arg("Enter a GitHub username:");
let { data: user } = await octokit.rest.users.getByUsername({ username });
const userFirstNameOrUsername = user.name.trim()
? user.name.trim().split(/\s+/)[0]
: `@${user.login}`;
copy(userFirstNameOrUsername);
setPlaceholder(`"${userFirstNameOrUsername}" copied to your clipboard`);
setIgnoreBlur(false);
setHint(`Press esc to close this prompt`);