From 8e25786cb910a2f3a86c2c7fca351d27e8aa1585 Mon Sep 17 00:00:00 2001 From: Charlie Gerard Date: Mon, 15 Apr 2024 14:31:34 -0700 Subject: [PATCH] start implementing an analytics command --- lib/commands/analytics/index.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/commands/analytics/index.js b/lib/commands/analytics/index.js index 47d2ec5a..23955423 100644 --- a/lib/commands/analytics/index.js +++ b/lib/commands/analytics/index.js @@ -7,7 +7,7 @@ import { outputFlags, validationFlags } from '../../flags/index.js' // import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' import { InputError } from '../../utils/errors.js' import { printFlagList } from '../../utils/formatting.js' -import { FREE_API_KEY, getDefaultKey, setupSdk } from '../../utils/sdk.js' +// import { FREE_API_KEY, getDefaultKey, setupSdk } from '../../utils/sdk.js' /** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ export const analytics = { @@ -17,9 +17,9 @@ export const analytics = { const input = setupCommand(name, analytics.description, argv, importMeta) if (input) { - const spinner = ora("Fetching analytics data").start() + const spinner = ora('Fetching analytics data').start() console.log(input) - if(input.scope === 'org'){ + if (input.scope === 'org') { await fetchOrgAnalyticsData(input.time, spinner) } else { // await fetchRepoAnalyticsData(input.time, spinner) @@ -32,8 +32,8 @@ export const analytics = { /** * @typedef CommandContext - * @property {string} scope - * @property {string} time + * @property {string} scope + * @property {string} time */ /** @@ -68,24 +68,24 @@ function setupCommand (name, description, argv, importMeta) { const scope = cli.input[0] - if(!scope){ - throw new InputError("Please provide a scope to get analytics data") + if (!scope) { + throw new InputError('Please provide a scope to get analytics data') } - if(!cli.input.length){ - throw new InputError("Please provide a scope and a time to get analytics data") + if (!cli.input.length) { + throw new InputError('Please provide a scope and a time to get analytics data') } - if(scope && !['org', 'repo'].includes(scope)){ + if (scope && !['org', 'repo'].includes(scope)) { throw new InputError("The scope must either be 'scope' or 'repo'") } const time = cli.input[1] - if(!time){ - throw new InputError("Please provide a time to get analytics data") + if (!time) { + throw new InputError('Please provide a time to get analytics data') } - if (time && !['7','30','60'].includes(time)) { + if (time && !['7', '30', '60'].includes(time)) { throw new InputError('The time filter must either be 7, 30 or 60') } @@ -106,16 +106,17 @@ function setupCommand (name, description, argv, importMeta) { */ // * @returns {Promise} async function fetchOrgAnalyticsData (time, spinner) { - const socketSdk = await setupSdk(getDefaultKey() || FREE_API_KEY) +// const socketSdk = await setupSdk(getDefaultKey() || FREE_API_KEY) console.table(time) + console.log(spinner) // const result = await handleApiCall(socketSdk.getOrgAnalytics(time), 'fetching analytics data') - + // if (result.success === false) { // return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner) // } // return { - + // } }