Skip to content

fix: actually populate auth user field #7181

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
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
11 changes: 0 additions & 11 deletions eslint_temporary_suppressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,17 +944,6 @@ export default [
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
{
files: ['src/utils/gh-auth.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
{
files: ['src/utils/gitignore.ts'],
rules: {
Expand Down
10 changes: 5 additions & 5 deletions src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ git remote add origin https://github.com/YourUserName/RepoName.git
const NEW_SITE_NO_GIT = 'Yes, create and deploy site manually'
const NO_ABORT = 'No, I will connect this directory with GitHub first'

const { noGitRemoteChoice } = (await inquirer.prompt([
const { noGitRemoteChoice } = await inquirer.prompt<{ noGitRemoteChoice: typeof NEW_SITE_NO_GIT | typeof NO_ABORT }>([
{
type: 'list',
name: 'noGitRemoteChoice',
message: 'Do you want to create a Netlify site without a git repository?',
choices: [NEW_SITE_NO_GIT, NO_ABORT],
},
])) as { noGitRemoteChoice: typeof NEW_SITE_NO_GIT | typeof NO_ABORT }
])

if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
return await createNewSiteAndExit({ state, command })
Expand All @@ -138,15 +138,15 @@ const createOrLinkSiteToRepo = async (command: BaseCommand) => {

const initializeOpts = [EXISTING_SITE, NEW_SITE] as const

const { initChoice } = (await inquirer.prompt([
// TODO(serhalp): inquirer should infer the choice type here, but doesn't. Fix.
const { initChoice } = await inquirer.prompt<{ initChoice: typeof initializeOpts[number] }>([
{
type: 'list',
name: 'initChoice',
message: 'What would you like to do?',
choices: initializeOpts,
},
// TODO(serhalp): inquirer should infer the choice type here, but doesn't. Fix.
])) as { initChoice: typeof initializeOpts[number] }
])

// create site or search for one
if (initChoice === NEW_SITE) {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/build-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import fuzzy from 'fuzzy'
import inquirer from 'inquirer'

import type BaseCommand from '../commands/base-command.js'
import type { DefaultConfig } from '../lib/build.js'

import { chalk, log } from './command-helpers.js'
import type { DefaultConfig } from '../lib/build.js'

/**
* Filters the inquirer settings based on the input
Expand Down
21 changes: 11 additions & 10 deletions src/utils/gh-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export interface Token {
const promptForAuthMethod = async () => {
const authChoiceNetlify = 'Authorize with GitHub through app.netlify.com'
const authChoiceToken = 'Authorize with a GitHub personal access token'
const authChoices = [authChoiceNetlify, authChoiceToken]
const authChoices = [authChoiceNetlify, authChoiceToken] as const

const { authMethod } = await inquirer.prompt([
const { authMethod } = await inquirer.prompt<{ authMethod: typeof authChoices[number] }>([
{
type: 'list',
name: 'authMethod',
Expand Down Expand Up @@ -53,7 +53,7 @@ export const authWithNetlify = async (): Promise<Token> => {
`${
"<html><head><title>Logged in</title><script>if(history.replaceState){history.replaceState({},'','/')}</script><style>html{font-family:system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';line-height:1.5;background:rgb(18 24 31)}body{overflow:hidden;position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;width:100vw;}h3{margin:0}p{margin: 1rem 0 0.5rem}.card{position:relative;display:flex;flex-direction:column;width:75%;max-width:364px;padding:24px;background:white;color:rgb(18 24 31);border-radius:8px;box-shadow:rgb(6 11 16 / 20%) 0px 16px 24px, rgb(6 11 16 / 30%) 0px 6px 30px, rgb(6 11 16 / 40%) 0px 8px 10px;}</style></head>" +
"<body><div class=card><h3>Logged in</h3><p>You're now logged into Netlify CLI with your "
}${parameters.get('provider')} credentials. Please close this window.</p></div>`,
}${parameters.get('provider') ?? ''} credentials. Please close this window.</p></div>`,
)
server.close()
return
Expand All @@ -70,9 +70,9 @@ export const authWithNetlify = async (): Promise<Token> => {
})
})

const webUI = process.env.NETLIFY_WEB_UI || 'https://app.netlify.com'
const webUI = process.env.NETLIFY_WEB_UI ?? 'https://app.netlify.com'
const urlParams = new URLSearchParams({
host: `http://localhost:${port}`,
host: `http://localhost:${port.toString()}`,
provider: 'github',
})
const url = `${webUI}/cli?${urlParams.toString()}`
Expand All @@ -82,13 +82,13 @@ export const authWithNetlify = async (): Promise<Token> => {
return deferredPromise
}

const getPersonalAccessToken = async () => {
const { token } = await inquirer.prompt([
const getPersonalAccessToken = async (): Promise<{ token: string }> => {
const { token } = await inquirer.prompt<{ token: string }>([
{
type: 'password',
name: 'token',
message: 'Your GitHub personal access token:',
filter: (input) => input.trim(),
filter: (input: string) => input.trim(),
},
])

Expand All @@ -105,8 +105,9 @@ const authWithToken = async (): Promise<Token> => {
}

const octokit = new Octokit({ auth: `token ${token}` })
// @ts-expect-error -- XXX(serhalp): actual bug - fixed in stacked PR
const { login: user } = await octokit.users.getAuthenticated()
const {
data: { login: user },
} = await octokit.users.getAuthenticated()

return { token, user, provider: 'github' }
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/init/config-manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const addDeployKey = async (deployKey: DeployKey) => {
}

const getRepoPath = async ({ repoData }: { repoData: RepoData }): Promise<string> => {
const { repoPath } = (await inquirer.prompt([
const { repoPath } = await inquirer.prompt<{ repoPath: string }>([
{
type: 'input',
name: 'repoPath',
message: 'The SSH URL of the remote git repo:',
default: repoData.url,
validate: (url: string) => (SSH_URL_REGEXP.test(url) ? true : 'The URL provided does not use the SSH protocol'),
},
])) as { repoPath: string }
])

return repoPath
}
Expand All @@ -48,14 +48,14 @@ const addDeployHook = async (deployHook: string | undefined): Promise<boolean> =
// FIXME(serhalp): Handle nullish `deployHook` by throwing user-facing error or fixing upstream type.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
log(`\n${deployHook}\n\n`)
const { deployHookAdded } = (await inquirer.prompt([
const { deployHookAdded } = await inquirer.prompt<{ deployHookAdded: boolean }>([
{
type: 'confirm',
name: 'deployHookAdded',
message: 'Continue?',
default: true,
},
])) as { deployHookAdded: boolean }
])

return deployHookAdded
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils/init/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ export const getBuildSettings = async ({
log()
}

const { baseDir, buildCmd, buildDir } = (await inquirer.prompt(
const { baseDir, buildCmd, buildDir } = await inquirer.prompt<{
baseDir?: string | undefined
buildCmd: string
buildDir: string
}>(
getPromptInputs({
defaultBaseDir,
defaultBuildCmd,
defaultBuildDir,
}),
)) as { baseDir?: string | undefined; buildCmd: string; buildDir: string }
)

const pluginsToInstall = recommendedPlugins.map((plugin) => ({ package: plugin }))
const normalizedBaseDir = baseDir ? normalizeBackslash(baseDir) : undefined
Expand Down
Loading