Skip to content

Commit

Permalink
Merge branch 'main' of github.com:HubSpot/hubspot-cli into jy/fix-gh-…
Browse files Browse the repository at this point in the history
…rate-limit
  • Loading branch information
joe-yeager committed Jan 9, 2025
2 parents 69045d1 + 4c2655d commit 479f254
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 129 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @hubspot/cli

[![Official Release](https://img.shields.io/npm/v/@hubspot/cli/latest?label=Official%20Release)](https://www.npmjs.com/package/@hubspot/cli) [![Latest Version](https://img.shields.io/github/v/tag/hubspot/hubspot-cli?label=Latest%20Version)](https://www.npmjs.com/package/@hubspot/cli?activeTab=versions)
[![Official Release](https://img.shields.io/npm/v/@hubspot/cli/latest?label=Official%20Release)](https://www.npmjs.com/package/@hubspot/cli) [![Latest Beta Version](https://img.shields.io/npm/v/@hubspot/cli/next?label=Latest%20Beta%20Version)](https://www.npmjs.com/package/@hubspot/cli?activeTab=versions)

A CLI for HubSpot developers to enable local development and automation. [Learn more about building on HubSpot](https://developers.hubspot.com).

Expand Down Expand Up @@ -58,14 +58,15 @@ There are two ways that the tools can authenticate with HubSpot.
3. Select `OAuth2` and follow the steps

_**Note:** The Account ID used should be the Test Account ID (not the developer app ID). Client ID and Client Secret are from the developer app._

### Exit Codes

The CLI will exit with one of the following exit codes:

- `0`: A successful run
- `1`: There was a config problem or an internal error
- `2`: There are warnings or validation issues


## Changelog

The best way to stay up to date is to check out the [Github Releases](https://github.com/HubSpot/hubspot-cli/releases) and also follow our [developer changelog posts](https://developers.hubspot.com/changelog) for an easier to read breakdown of major changes.
36 changes: 36 additions & 0 deletions acceptance-tests/tests/commands/hs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, beforeAll, it, expect, afterAll } from 'vitest';
import { TestState } from '../../lib/TestState';

describe('hs', () => {
let testState: TestState;

beforeAll(async () => {
testState = new TestState();
});

afterAll(() => {
testState.cleanup();
});

describe('hs', () => {
it('should log out the help message', async () => {
const output = await testState.cli.executeWithTestConfig([]);

expect(output).toContain(
'The command line interface to interact with HubSpot'
);
});

it('should log out the help message when --help is passed', async () => {
const output = await testState.cli.executeWithTestConfig(['--help']);

expect(output).toContain(
'The command line interface to interact with HubSpot'
);
});

it('should not throw when --version is passed', async () => {
await testState.cli.executeWithTestConfig(['--version']);
});
});
});
4 changes: 2 additions & 2 deletions acceptance-tests/tests/workflows/secretsFlow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const SECRET = {
};

const secretPollingOptions = {
interval: 2000,
timeout: 20000,
interval: 5000,
timeout: 60000,
};

async function waitForSecretsListToContainSecret(testState: TestState) {
Expand Down
18 changes: 16 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const handleFailure = (msg, err, yargs) => {
}

if (msg === null) {
yargs.showHelp();
yargs.showHelp('log');
process.exit(EXIT_CODES.SUCCESS);
} else {
process.exit(EXIT_CODES.ERROR);
Expand Down Expand Up @@ -177,6 +177,11 @@ const SKIP_CONFIG_VALIDATION = {
};

const loadConfigMiddleware = async options => {
// Skip this when no command is provided
if (!options._.length) {
return;
}

const maybeValidateConfig = () => {
if (
!isTargetedCommand(options, SKIP_CONFIG_VALIDATION) &&
Expand All @@ -201,7 +206,11 @@ const loadConfigMiddleware = async options => {
maybeValidateConfig();
};

const checkAndWarnGitInclusionMiddleware = () => {
const checkAndWarnGitInclusionMiddleware = options => {
// Skip this when no command is provided
if (!options._.length) {
return;
}
checkAndWarnGitInclusion(getConfigPath());
};

Expand Down Expand Up @@ -231,6 +240,11 @@ const SKIP_ACCOUNT_VALIDATION = {
};

const validateAccountOptions = async options => {
// Skip this when no command is provided
if (!options._.length) {
return;
}

let validAccount = true;
if (!isTargetedCommand(options, SKIP_ACCOUNT_VALIDATION)) {
validAccount = await validateAccount(options);
Expand Down
8 changes: 5 additions & 3 deletions commands/customObject/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ exports.describe = i18n(`${i18nKey}.describe`);
exports.handler = async options => {
const { path, name: providedName, derivedAccountId } = options;
let definitionPath = path;
let name = providedName;

trackCommandUsage('custom-object-batch-create', null, derivedAccountId);

if (!name) {
name = await inputPrompt(i18n(`${i18nKey}.inputName`));
}

if (!definitionPath) {
definitionPath = await inputPrompt(i18n(`${i18nKey}.inputPath`));
}
Expand All @@ -34,9 +39,6 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

const name =
providedName || (await inputPrompt(i18n(`${i18nKey}.inputSchema`)));

try {
await batchCreateObjects(derivedAccountId, name, objectJson);
logger.success(i18n(`${i18nKey}.success.objectsCreated`));
Expand Down
4 changes: 2 additions & 2 deletions commands/hubdb/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ exports.handler = async options => {

let filePath;
try {
const { path: filePath } =
const filePath =
'path' in options
? path.resolve(getCwd(), options.path)
: await selectPathPrompt(options);
: path.resolve(getCwd(), (await selectPathPrompt(options)).path);
if (!checkAndConvertToJson(filePath)) {
process.exit(EXIT_CODES.ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion commands/project/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ exports.handler = async options => {
latestBuild.buildId === deployedBuildId
? undefined
: latestBuild.buildId,
validate: () =>
validate: buildId =>
validateBuildId(
buildId,
deployedBuildId,
Expand Down
12 changes: 7 additions & 5 deletions commands/secret/deleteSecret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ exports.handler = async options => {
})
);
} catch (err) {
logger.error(
i18n(`${i18nKey}.errors.delete`, {
secretName,
})
);
if (secretName) {
logger.error(
i18n(`${i18nKey}.errors.delete`, {
secretName,
})
);
}
logError(
err,
new ApiErrorContext({
Expand Down
4 changes: 2 additions & 2 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ en:
describe: "Schema name to add the object instance to"
success:
objectsCreated: "Objects created"
inputSchema: "What would you like to name the schema?"
inputPath: "[--path] Where is the JSON file containing the object definitions?"
inputName: "[--name] Enter the name of the schema for the custom object(s) you'd like to create:"
inputPath: "[--path] Enter the path to the JSON file containing the object definitions:"
schema:
describe: "Commands for managing custom object schemas."
subcommands:
Expand Down
Loading

0 comments on commit 479f254

Please sign in to comment.