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 bugs and things #93

Merged
merged 7 commits into from
Feb 19, 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
39 changes: 38 additions & 1 deletion cli/Company.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[Back](./README.md)
---
# Companies
Company objects are central to Mediumroast for GitHub. [Interactions](./Interaction.md) and in the future Studies rely on Companies to function. After setup is run, via `mrcli setup`, two companies are present to work with. Additional companies can be added, updated, or removed; essentially, `company` is an `mrcli` sub-command that affords users Create, Read, Update and Delete capabilities. Each of the major functions for `mrcli company` are described in this document.

Expand Down Expand Up @@ -41,13 +43,48 @@ Company data can be output in either a CSV or XLSX files to enable consumption i
<img width="1627" alt="companies_numbers" src="https://github.com/mediumroast/mediumroast_js/assets/10818650/6ab2266b-bacc-4cb0-9608-db8025866ccb">

## Filter company outputs
The CLI offers the ability to filter outputs by almost any company attribute. This is manifest by two switches on the company sub-command one specific to finding companies by name, `--find_by_name` and the other by an arbitrary attribute, `--find_by_x`. Note all output format options, like JSON, CSV, etc., are available when the outputs are filtered.
The CLI offers the ability to filter outputs by almost any company attribute. This is manifest by two switches on the company sub-command one specific to finding companies by name, `--find_by_name` and the other by an arbitrary attribute, `--find_by_x`. Note all output format options, like JSON, CSV, etc., are available when the outputs are filtered. Finally, only exact matches are supported, meaning if you want to search for a company using any attribute you have to fully provide the attribute's value (i.e., "Med" wouod not matche Mediumroast, Inc., but "Mediumroast, Inc. would).
### Filter in a company by name
To zero in on a specific company using the find by name switch is provided.
### Command(s) run
- `mrcli c --find_by_name="Mediumroast, Inc."`
### Screenshot with output
<img width="1530" alt="companies_filter_by_name" src="https://github.com/mediumroast/mediumroast_js/assets/10818650/4d6d88eb-740f-4d4d-a16b-bea12be54330">
### Filter a company by attribute
Find a specific company by a particular attribute in the example below the switch filters on the attribute `company_type`.
### Command(s) run
- `mrcli c --find_by_x='{"company_type": "Public"}'`
### Screenshot with output
<img width="1786" alt="companies_filter_by_x" src="https://github.com/mediumroast/mediumroast_js/assets/10818650/5c3e00d2-5365-40e8-bd91-31025cb821ae">
# Update a company attribute
To update a company attribute the `--update` switch is provided. A properly formatted JSON stanza is supplied to the `--update` switch that specifies the name o the company to update, the key to update, and finally the value of the key to update.

## Command(s) run
- `mrcli c --update='{"name": "Atlassian Corp", "key": "company_type", "value": "Public"}'`

## Screencast with output

https://github.com/mediumroast/mediumroast_js/assets/10818650/a74cb8cd-f8cb-4a8d-8968-ccf9b875d86b

# Delete a company
Remove a company and associated interactions if in the repository. There is a confirmation prompt which defaults to yes. Note that the exact company name is needed to proceed with a deletion.

## Command(s) run
- `mrcli c --delete="Atlassian Corp"

## Screenshot with output
<img width="1786" alt="companies_delete" src="https://github.com/mediumroast/mediumroast_js/assets/10818650/85d98dee-ce3b-4d90-9567-9410e58872a3">

# Add a company
A command line prompt based wizard steps the user through either a semi-automated process or a fully-automated process to define a company. The semi-automated process is typically used for companies that aren't public. While the fully-automated process is typically used for companies that are public. In either case the user is asked to verify the steps taken before the company is committed to the repository.

## Command(s) run
- `mrcli c --add_wizard`

## Screenshot with output

<img width="1786" alt="companies_add" src="https://github.com/mediumroast/mediumroast_js/assets/10818650/d948fce2-6c31-4537-983d-9dad4c04c248">




6 changes: 5 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[Back](../README.md)

---

# Mediumroast for GitHub CLI (Command Line Interface)
The CLI is divided into two sets one for administrative interactions with the system and another for interacting with **Mediumroast for GitHub** objects like Companies and Interactions. This document covers both the administrative CLI and makes reference to the CLI set for **Mediumroast for GitHub** objects.

Expand Down Expand Up @@ -29,7 +33,7 @@ To help users quickly get on board with **Mediumroast for GitHub** the setup CLI

# **Mediumroast for GitHub** primary object CLIs
This CLIs to create, read, update, and delete **Mediumroast for GitHub** are linked below.
- [Companies](./Company.md)
- [Company](./Company.md)
- [Interaction](./Interaction.md)


10 changes: 6 additions & 4 deletions cli/mrcli-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ async function confirmGitHubOrg(token, env) {
//
const output = new CLIOutput(env, 'Org')
// Prompt and confirm user's the GitHub organization
const gitHubOrgName = await simplePrompt('Please enter your GitHub organization.')
let gitHubOrgName = await simplePrompt('Please enter your GitHub organization.')
// URL encode the organization name
gitHubOrgName = encodeURI(gitHubOrgName)

// Construct the GitHubFunctions object
let gitHubCtl = new GitHubFunctions(myConfig.token, gitHubOrgName)
Expand All @@ -156,8 +158,9 @@ async function confirmGitHubOrg(token, env) {

// Obtain the intel based upon the organization the user input
const gitHubOrg = await gitHubCtl.getGitHubOrg()
// console.log(gitHubOrg)
if(!gitHubOrg[0]){
const tryAgain = await wizardUtils.operationOrNot(
tryAgain = await wizardUtils.operationOrNot(
`Unfortunately, no organization matching [${gitHubOrgName}] was found. Maybe you mistyped it, try again?`
)
if(tryAgain) {
Expand All @@ -168,7 +171,7 @@ async function confirmGitHubOrg(token, env) {
}
}
// Only print the table if we're not trying again
if (!tryAgain) {cliOutput.outputCLI([gitHubOrg[1]])}
if (!tryAgain) {output.outputCLI([gitHubOrg[1]])}

// Confirm that the organization is correct
tryAgain = await wizardUtils.operationOrNot(
Expand Down Expand Up @@ -472,7 +475,6 @@ cliOutput.printLine()
/* ------------ Install actions ------------ */
process.stdout.write(chalk.bold.blue(`Installing actions and workflows ... `))
const actionsManifest = generateActionsManifest()
console.log(actionsManifest)
const installResp = await installActions(actionsManifest)
if(installResp[0]) {
console.log(chalk.bold.green('Ok'))
Expand Down
4 changes: 2 additions & 2 deletions cli/mrcli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* The wrapping CLI to engage all mediumroast.io CLIs
* @author Michael Hay <michael.hay@mediumroast.io>
* @file mrcli.js
* @copyright 2022 Mediumroast, Inc. All rights reserved.
* @copyright 2024 Mediumroast, Inc. All rights reserved.
* @license Apache-2.0
* @version 1.0.0
*/
Expand All @@ -14,7 +14,7 @@ import program from 'commander'

program
.name('mrcli')
.version('0.4.44')
.version('0.4.46')
.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')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediumroast_js",
"version": "0.4.44",
"version": "0.4.46",
"description": "A Command Line Interface (CLI) and Javascript SDK to interact with mediumroast.io.",
"main": "cli/mrcli.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/cli/companyWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ class AddCompany {
// Company type
'company_type' in myCompany ? prototype.company_type.value = myCompany.company_type :
prototype.company_type.value = prototype.company_type.value

// If prototype.company_type.value has text after "Public" then set it to "Public"
if (prototype.company_type.value.search(/Public/g)) {
prototype.company_type.value = "Public"
}

// Company firmographics url
'firmographicsURL' in myCompany ? prototype.firmographics_url.value = myCompany.firmographicsURL :
Expand Down
12 changes: 6 additions & 6 deletions src/cli/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ class Environmentals {
// Operational command line switches
.option(
'--find_by_name <name>',
'Find an individual object by name'
`Find an individual a ${this.objectType} by name`
)
.option(
'--find_by_id <ID>',
'Find an individual Interaction by ID'
`Find an individual a ${this.objectType} by ID`
)
.option(
'--find_by_x <JSON>',
'Find object by an arbitrary attribute as specified by JSON (ex \'{\"zip_postal\":\"92131\"}\')'
`Find a ${this.objectType} by an arbitrary attribute as specified by JSON (ex \'{\"zip_postal\":\"92131\"}\')`
)
.option(
'--update <JSON>',
'Update an object from the backend by specifying the object\'s name plus attribute and value to update in JSON'
`Update a ${this.objectType} from the backend by specifying the object\'s name plus attribute and value to update in JSON`
)
.option(
'--delete <NAME>',
'Delete an object from the backend by specifying the object\'s id'
`Delete a ${this.objectType} from the backend by specifying the object\'s id`
)
.option(
'--report <NAME>',
'Create an MS word document for an object by specifying the object\'s id'
`Create an MS word document for a ${this.objectType} by specifying the object\'s id`
)
.option(
'--package',
Expand Down
4 changes: 2 additions & 2 deletions src/cli/installInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ tool will fail.
You can learn more about and install the GitHub Application by visiting the following
URL: https://github.com/apps/mediumroast-for-github

A more detailed product description, help and other related documentation ca be found
here: https://www.mediumroast.io/
A more detailed product description, help and other related documentation can be found
here: https://www.mediumroast.io/.

WARNING: This setup installs two GitHub Actions, and their associated workflows, into
the repository that it creates. These Actions consume GitHub Actions minutes and may incur
Expand Down
30 changes: 16 additions & 14 deletions src/cli/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,26 @@ class CLIOutput {
table = new Table({
head: ['Id', 'Name', 'GitHub Url', 'Description'],
})
table.push([
gitHubOrg.id,
gitHubOrg.name,
gitHubOrg.html_url,
gitHubOrg.description,
])
for (const myObj in objects) {
table.push([
objects[myObj].id !== null ? objects[myObj].id : 'No Id',
objects[myObj].name !== null ? objects[myObj].name : 'No Name',
objects[myObj].html_url !== null ? objects[myObj].html_url : 'No GitHub Url',
objects[myObj].description !== null ? objects[myObj].description : 'No Description'
])
}
} else if (this.objectType === 'MyUser') {
table = new Table({
head: ['GitHub Id', 'Login', 'Name', 'Type', 'Company', 'GitHub Website'],
})
for (const myObj in objects) {
table.push([
objects[myObj].id,
objects[myObj].login,
objects[myObj].name,
objects[myObj].type,
objects[myObj].company,
objects[myObj].html_url
objects[myObj].id !== null ? objects[myObj].id : 'No Id',
objects[myObj].login !== null ? objects[myObj].login : 'No Login',
objects[myObj].name !== null ? objects[myObj].name : 'No Name',
objects[myObj].type !== null ? objects[myObj].type : 'No Type',
objects[myObj].company !== null ? objects[myObj].company : 'No Company',
objects[myObj].html_url !== null ? objects[myObj].html_url : 'No GitHub Website'
])
}
// Study, Company and Interaction objects output
Expand Down Expand Up @@ -191,9 +193,9 @@ class CLIOutput {
try {
const csv = csvParser.parse(objects)
this.fileSystem.saveTextFile(myFile, csv)
return [true, null]
return [true, {status_code: 200, status_msg: `wrote [${this.objectType}] objects to [${myFile}]`}, null]
} catch (err) {
return [false, err]
return [false, {}, err]
}
}

Expand Down