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

Alpha 2 #80

Merged
merged 2 commits into from
Jan 14, 2024
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
41 changes: 32 additions & 9 deletions cli/mrcli-company.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

// Import required modules
import { CompanyStandalone } from '../src/report/companies.js'
import { Companies, Studies } from '../src/api/gitHubServer.js'
import { Interactions, Companies, Studies, Users } from '../src/api/gitHubServer.js'
import GitHubFunctions from '../src/api/github.js'
import AddCompany from '../src/cli/companyWizard.js'
import Environmentals from '../src/cli/env.js'
import CLIOutput from '../src/cli/output.js'
Expand Down Expand Up @@ -46,6 +47,7 @@ myArgs = myArgs.opts()
// Read the environmental settings
const myConfig = environment.readConfig(myArgs.conf_file)
let myEnv = environment.getEnv(myArgs, myConfig)
myEnv.company = 'Unknown'
const accessToken = await environment.verifyAccessToken()
const processName = 'mrcli-company'

Expand All @@ -57,10 +59,11 @@ const wutils = new WizardUtils()

// Construct the controller objects
const companyCtl = new Companies(accessToken, myEnv.gitHubOrg, processName)
// const studyCtl = new Studies(accessToken, myEnv.gitHubOrg, processName)
const interactionCtl = new Interactions(accessToken, myEnv.gitHubOrg, processName)
const gitHubCtl = new GitHubFunctions(accessToken, myEnv.gitHubOrg, processName)

// TODO: We need to create a higher level abstraction for capturing the owning company
// const owningCompany = await serverOps.getOwningCompany(companyCtl)
// const studyCtl = new Studies(accessToken, myEnv.gitHubOrg, processName)
const userCtl = new Users(accessToken, myEnv.gitHubOrg, processName)

// Predefine the results variable
let [success, stat, results] = [null, null, null]
Expand Down Expand Up @@ -211,20 +214,30 @@ if (myArgs.report) {
stat = foundObjects[1]
results = foundObjects[2]
} else if (myArgs.update) {
const lockResp = await companyCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
const myCLIObj = JSON.parse(myArgs.update)
const mySpinner = new ora(`Updating company [${myCLIObj.name}] object ...`)
const mySpinner = new ora(`Updating company [${myCLIObj.name}] ...`)
mySpinner.start()
const [success, stat, resp] = await companyCtl.updateObj(myCLIObj)
mySpinner.stop()
if(success) {
console.log(`SUCCESS: ${stat.status_msg}`)
process.exit(0)
} else {
} else {
console.log(`ERROR: ${stat.status_msg}`)
process.exit(-1)
}
// TODO: Need to reimplement the below to account for GitHub
} else if (myArgs.delete) {
const lockResp = await companyCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
// Use operationOrNot to confirm the delete
const deleteOrNot = await wutils.operationOrNot(`Preparing to delete the company [${myArgs.delete}], are you sure?`)
if(!deleteOrNot) {
Expand All @@ -248,19 +261,29 @@ if (myArgs.report) {
process.exit(-1)
}
} else if (myArgs.add_wizard) {
const lockResp = await companyCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
myEnv.DEFAULT = {company: 'Unknown'}
const newCompany = new AddCompany(myEnv, companyCtl)
const newCompany = new AddCompany(myEnv, {github: gitHubCtl, interaction: interactionCtl, company: companyCtl, user: userCtl})
const result = await newCompany.wizard()
if(result[0]) {
console.log('SUCCESS: Created new company in the backend')
console.log(`SUCCESS: ${result[1].status_msg}`)
process.exit(0)
} else {
console.log(`ERROR: Failed to create company object with:, ${result[2]}`)
console.log(`ERROR: ${result[1].status_msg}`)
process.exit(-1)
}
} else if (myArgs.reset_by_type) {
console.error(`WARNING: CLI function not yet implemented for companies: %d`, -1)
process.exit(-1)
const lockResp = companyCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
// TODO: Need to reimplement the below to account for GitHub, and this is where we will start to use the new CLIOutput
} else {
[success, stat, results] = await companyCtl.getAll()
Expand Down
26 changes: 23 additions & 3 deletions cli/mrcli-interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ if (myArgs.report) {
stat = foundObjects[1]
results = foundObjects[2]
} else if (myArgs.update) {
const lockResp = await interactionCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
const myCLIObj = JSON.parse(myArgs.update)
const mySpinner = new ora(`Updating interaction [${myCLIObj.name}] object ...`)
mySpinner.start()
Expand All @@ -197,6 +202,11 @@ if (myArgs.report) {
process.exit(-1)
}
} else if (myArgs.delete) {
const lockResp = await interactionCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
// Use operationOrNot to confirm the delete
const deleteOrNot = await wutils.operationOrNot(`Preparing to delete the interaction [${myArgs.delete}], are you sure?`)
if(!deleteOrNot) {
Expand All @@ -216,18 +226,28 @@ if (myArgs.report) {
process.exit(-1)
}
} else if (myArgs.add_wizard) {
const lockResp = await interactionCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
const newInteraction = new AddInteraction(myEnv, {github: gitHubCtl, interaction: interactionCtl, company: companyCtl, user: userCtl})
const result = await newInteraction.wizard()
if(result[0]) {
console.log(`SUCCESS: Added new interaction object(s).`)
console.log(`SUCCESS: ${result[1].status_msg}`)
process.exit(0)
} else {
console.log(`ERROR: Unable to add interaction object due to [${result[1].status_msg}].`)
console.log(`ERROR: ${result[1].status_msg}.`)
process.exit(-1)
}
} else if (myArgs.reset_by_type) {
console.error('ERROR (%d): Reset by type not implemented.', -1)
console.log('ERROR: Reset by type not implemented.')
process.exit(-1)
const lockResp = interactionCtl.checkForLock()
if(lockResp[0]) {
console.log(`ERROR: ${lockResp[1].status_msg}`)
process.exit(-1)
}
const resetResponses = await resetStatuses(myArgs.reset_by_type, interactionCtl)
if(resetResponses[0]) {
console.log(`SUCCESS: Reset status of ${resetResponses[2].successful.length} interactions.`)
Expand Down
90 changes: 16 additions & 74 deletions cli/mrcli-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import inquirer from "inquirer"

import Environmentals from '../src/cli/env.js'
import { GitHubAuth } from '../src/api/authorize.js'
import { Companies } from '../src/api/gitHubServer.js'
import { Companies, Users } from '../src/api/gitHubServer.js'
import GitHubFunctions from "../src/api/github.js"
import Table from 'cli-table'
import ora from "ora"
Expand Down Expand Up @@ -96,9 +96,8 @@ async function simplePrompt(message) {
function printNextSteps() {
// Print out the next steps
console.log(`Now that you\'ve performed the initial registration here\'s what\'s next.`)
console.log(chalk.blue.bold(`\t1. Create and register additional companies with mrcli company --add_wizard.`))
console.log(chalk.blue.bold(`\t2. Register and add interactions with mrcli interaction --add_wizard.`))
console.log('\nWith additional companies and new interactions registered the mediumroast.io caffeine\nservice will perform basic company comparisons.')
console.log(chalk.blue.bold(`\t1. Create and register additional companies with \'mrcli company --add_wizard\'.`))
console.log(chalk.blue.bold(`\t2. Register and add interactions with \'mrcli interaction --add_wizard\'.`))
cliOutput.printLine()
}

Expand Down Expand Up @@ -298,6 +297,7 @@ cliOutput.printLine()
let prevInstall = false
// Construct the controller objects
const companyCtl = new Companies(myConfig.GitHub.token, myConfig.GitHub.org, `mrcli-setup`)
const userCtl = new Users(myConfig.GitHub.token, myConfig.GitHub.org, `mrcli-setup`)
// const studyCtl = new Studies(myConfig.GitHub.token, myConfig.GitHub.org, `mrcli-setup`)

// Check to see if the company and study objects exist
Expand Down Expand Up @@ -334,8 +334,8 @@ if(!configExists[0]) {
// Confirm that Document directory exists and if not create it
const docDir = myConfig.DEFAULT.report_output_dir
const reportDirExists = fsUtils.safeMakedir(docDir)
if(reportDirExists[0]) {
console.log(chalk.bold.yellow(`WARNING: Report output directory [${docDir}] not detected, created.`))
if(!reportDirExists[0]) {
console.log(chalk.bold.red(`ERROR: Unable to create report directory [${docDir}].`))
}

/* --------- End save config file ---------- */
Expand Down Expand Up @@ -390,109 +390,51 @@ cliOutput.printLine()
/* ----------------------------------------- */
/* ---- Begin initial objects creation ----- */

// Create needed objects
let companies = []
// let studies = []

// Create the owning company
console.log(chalk.blue.bold('Creating your owning company'))
myConfig.DEFAULT.company = myConfig.GitHub.org
myConfig.company = myConfig.GitHub.org
myEnv.splash = false
const cWizard = new AddCompany(
myConfig,
companyCtl,
{github: gitHubCtl, interaction: null, company: companyCtl, user: userCtl},
myConfig.DEFAULT.company_dns
)
const owningCompanyResp = await cWizard.wizard(true, false)
let owningCompany = owningCompanyResp[2]

// Create the first company
// Reset company user name to user name set in the company wizard
myConfig.DEFAULT.company = 'Unknown'
myConfig.company = 'Unknown'
const firstComp = new AddCompany(
myConfig,
companyCtl, // NOTE: Company creation is commented out
{github: gitHubCtl, interaction: null, company: companyCtl, user: userCtl},
myConfig.DEFAULT.company_dns
)
console.log(chalk.blue.bold('Creating the first company ...'))
let firstCompanyResp = await firstComp.wizard(false, false)
const firstCompany = firstCompanyResp[2]

// NOTE: For the first release studies aren't needed, therefore we're commenting out anything related to them
// const linkedCompanies = companyCtl.linkObj([owningCompany, firstCompany])

// Create a default study for good housekeeping
process.stdout.write(chalk.blue.bold(`Creating default study ... `))
let myStudy = {
name: 'Default Study',
description: 'A placeholder study to ensure that interactions are able to have something to link to',
public: false,
groups: 'default:default',
document: {},
linked_companies: linkedCompanies,
linked_interactions: {}
}
console.log(chalk.bold.green('Ok'))

// NOTE: Since studies aren't needed in the alpha_2 series of releases we will comment things out related to them.
// Additionally, in alpha_3 we'll determine if we need to create a default study or not. So leaving this
// code in place for now.
// Obtain the link object for studies
// const linkedStudies = studyCtl.linkObj([myStudy])
// const linkedStudies = {}

// Link the study to the companies
// owningCompany.linked_studies = linkedStudies
// firstCompany.linked_studies = linkedStudies
// companies = [owningCompany, firstCompany]

// Set up the spinner
let spinner

// Save the companies to GitHub
spinner = ora(chalk.bold.blue('Saving companies to GitHub ... '))
spinner.start() // Start the spinner
const companyResp = await companyCtl.createObj(companies)
const companyResp = await companyCtl.createObj([owningCompany, firstCompany])
spinner.stop() // Stop the spinner
// If the company creation failed then exit
if(!companyResp[0]) {
console.log(chalk.red.bold(`Failed to create companies, exiting with: [${companyResp[1]}], you may need to clean up the repo.`))
console.log(chalk.red.bold(`FAILED: ${companyResp[1].status_msg}, you may need to clean up the repository.`))
process.exit(-1)
} else {
console.log(chalk.bold.green('\tCompanies saved to GitHub.'))
}

// Save the default study to GitHub
// spinner = ora(chalk.bold.blue('Saving study to GitHub ... '))
// spinner.start() // Start the spinner
// const studyResp = await studyCtl.createObj([myStudy])
// spinner.stop() // Stop the spinner
// // If the study creation failed then exit
// if(!studyResp[0]) {
// console.log(chalk.red.bold(`Failed to create study, exiting with: [${studyResp[1]}], you may need to clean up the repo.`))
// process.exit(-1)
// } else {
// console.log(chalk.bold.green('\tDefault study saved to GitHub.'))
// }

}
cliOutput.printLine()

/* ------ End initial objects creation ----- */
/* ----------------------------------------- */

// List all created objects to the console
let results

// Studies output
console.log(chalk.blue.bold(`Fetching and listing all created objects`))
cliOutput.printLine()
// console.log(chalk.blue.bold(`Default study:`))
// results = await studyCtl.getAll()
// cliOutput.outputCLI(results[2].mrJson)
// cliOutput.printLine()

// Companies output
console.log(chalk.blue.bold(`Owning and first companies:`))
results = await companyCtl.getAll()
console.log(chalk.blue.bold(`Fetching and listing Owning and first companies:`))
const results = await companyCtl.getAll()
cliOutput.outputCLI(results[2].mrJson)
cliOutput.printLine()
cliOutput.printLine()
Expand Down
4 changes: 4 additions & 0 deletions cli/mrcli-study.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { Studies } from '../src/api/gitHubServer.js'
// import AddStudy from '../src/cli/studyWizard.js'
import Environmentals from '../src/cli/env.js'
import CLIOutput from '../src/cli/output.js'
import chalk from 'chalk'

console.log(chalk.bold.yellow('NOTICE: Studies aren\'t supported in this release, exiting.'))
process.exit()

// Globals
const objectType = 'Studies'
Expand Down
3 changes: 1 addition & 2 deletions cli/mrcli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import program from 'commander'

program
.name('mrcli')
.version('0.7.0')
.version('0.4.35')
.description('mediumroast.io command line interface')
.command('setup', 'setup the mediumroast.io system via the command line').alias('f')
.command('interaction', 'manage and report on mediumroast.io interaction objects').alias('i')
.command('company', 'manage and report on mediumroast.io company objects').alias('c')
.command('study', 'manage and report on mediumroast.io study objects').alias('s')
.command('user', 'manage and report on mediumroast.io users').alias('u')
.command('github', 'test code to interoperate with GitHub').alias('g')

program.parse(process.argv)
7 changes: 2 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediumroast_js",
"version": "0.4.25",
"version": "0.4.35",
"description": "A Command Line Interface (CLI) and Javascript SDK to interact with mediumroast.io.",
"main": "cli/mrcli.js",
"scripts": {
Expand Down Expand Up @@ -63,7 +63,6 @@
"box-plot": "^1.0.0",
"cli-progress": "^3.11.2",
"cli-table": "^0.3.11",
"cli-truncate": "^3.1.0",
"commander": "^8.3.0",
"configparser": "^0.3.9",
"docx": "^7.4.1",
Expand All @@ -74,8 +73,6 @@
"octokit": "^3.1.2",
"open": "^9.1.0",
"ora": "^6.1.2",
"prompt-sync": "^4.2.0",
"terminal-link": "^3.0.0",
"uninstall": "^0.0.0",
"wrap-ansi": "^8.1.0",
"xlsx": "^0.18.5"
Expand Down
Loading