Skip to content
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

feat: speed up netlify status by removing extra api call #6181

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
39 changes: 13 additions & 26 deletions src/commands/status/status.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createStatusHooksCommand } from './status-hooks.mjs'
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
const status = async (options, command) => {
const { api, globalConfig, site } = command.netlify
const { api, globalConfig, site, siteInfo } = command.netlify
const current = globalConfig.get('userId')
// @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0.
const [accessToken] = await getToken()
Expand All @@ -34,6 +34,7 @@ const status = async (options, command) => {
let user

try {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;[accounts, user] = await Promise.all([api.listAccountsForUser(), api.getCurrentUser()])
} catch (error_) {
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
Expand Down Expand Up @@ -68,35 +69,21 @@ const status = async (options, command) => {
warn('Did you run `netlify link` yet?')
error(`You don't appear to be in a folder that is linked to a site`)
}
let siteData
try {
siteData = await api.getSite({ siteId })
} catch (error_) {
// unauthorized
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
if (error_.status === 401) {
warn(`Log in with a different account or re-link to a site you have permission for`)
error(`Not authorized to view the currently linked site (${siteId})`)
}
// missing
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
if (error_.status === 404) {
error(`The site this folder is linked to can't be found`)
}
// @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
error(error_)

if (!siteInfo) {
error(`No site info found for site ${siteId}`)
}

// Json only logs out if --json flag is passed
if (options.json) {
logJson({
account: cleanAccountData,
siteData: {
'site-name': `${siteData.name}`,
'site-name': `${siteInfo.name}`,
'config-path': site.configPath,
'admin-url': siteData.admin_url,
'site-url': siteData.ssl_url || siteData.url,
'site-id': siteData.id,
'admin-url': siteInfo.admin_url,
'site-url': siteInfo.ssl_url || siteInfo.url,
'site-id': siteInfo.id,
},
})
}
Expand All @@ -106,11 +93,11 @@ const status = async (options, command) => {
β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜`)
log(
prettyjson.render({
'Current site': `${siteData.name}`,
'Current site': `${siteInfo.name}`,
'Netlify TOML': site.configPath,
'Admin URL': chalk.magentaBright(siteData.admin_url),
'Site URL': chalk.cyanBright(siteData.ssl_url || siteData.url),
'Site Id': chalk.yellowBright(siteData.id),
'Admin URL': chalk.magentaBright(siteInfo.admin_url),
'Site URL': chalk.cyanBright(siteInfo.ssl_url || siteInfo.url),
'Site Id': chalk.yellowBright(siteInfo.id),
}),
)
log()
Expand Down
Loading