From 744d600b6550419734f0aef0b287171fe502ba23 Mon Sep 17 00:00:00 2001 From: Charlie Gerard Date: Fri, 12 Apr 2024 16:20:26 -0700 Subject: [PATCH 01/21] [WIP] analytics --- lib/commands/analytics/index.js | 121 ++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 lib/commands/analytics/index.js diff --git a/lib/commands/analytics/index.js b/lib/commands/analytics/index.js new file mode 100644 index 00000000..47d2ec5a --- /dev/null +++ b/lib/commands/analytics/index.js @@ -0,0 +1,121 @@ +/* eslint-disable no-console */ + +import meow from 'meow' +import ora from 'ora' + +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' + +/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */ +export const analytics = { + description: 'Look up analytics data', + async run (argv, importMeta, { parentName }) { + const name = parentName + ' analytics' + + const input = setupCommand(name, analytics.description, argv, importMeta) + if (input) { + const spinner = ora("Fetching analytics data").start() + console.log(input) + if(input.scope === 'org'){ + await fetchOrgAnalyticsData(input.time, spinner) + } else { + // await fetchRepoAnalyticsData(input.time, spinner) + } + } + } +} + +// Internal functions + +/** + * @typedef CommandContext + * @property {string} scope + * @property {string} time + */ + +/** + * @param {string} name + * @param {string} description + * @param {readonly string[]} argv + * @param {ImportMeta} importMeta + * @returns {void|CommandContext} + */ +function setupCommand (name, description, argv, importMeta) { + const flags = { + ...outputFlags, + ...validationFlags, + } + + const cli = meow(` + Usage + $ ${name}