Skip to content

Commit

Permalink
start implementing an analytics command
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed Apr 15, 2024
1 parent 9546bbd commit 8e25786
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/commands/analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
Expand All @@ -32,8 +32,8 @@ export const analytics = {

/**
* @typedef CommandContext
* @property {string} scope
* @property {string} time
* @property {string} scope
* @property {string} time
*/

/**
Expand Down Expand Up @@ -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')
}

Expand All @@ -106,16 +106,17 @@ function setupCommand (name, description, argv, importMeta) {
*/
// * @returns {Promise<void|AnalyticsData>}
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 {

// }
}

0 comments on commit 8e25786

Please sign in to comment.