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

Default account names for hs init and hs auth #979

Merged
merged 8 commits into from
Jan 23, 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
29 changes: 22 additions & 7 deletions packages/cli/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
} = require('@hubspot/cli-lib/lib/constants');
const { i18n } = require('../lib/lang');
const {
updateConfigWithPersonalAccessKey,
getAccessToken,
updateConfigWithAccessToken,
} = require('@hubspot/local-dev-lib/personalAccessKey');
const {
updateAccountConfig,
Expand All @@ -17,7 +18,10 @@ const {
getConfigPath,
loadConfig,
} = require('@hubspot/local-dev-lib/config');
const { commaSeparatedValues } = require('@hubspot/local-dev-lib/text');
const {
commaSeparatedValues,
toKebabCase,
} = require('@hubspot/local-dev-lib/text');
const { promptUser } = require('../lib/prompts/promptUtils');
const {
personalAccessKeyPrompt,
Expand All @@ -40,6 +44,7 @@ const { trackAuthAction, trackCommandUsage } = require('../lib/usageTracking');
const { authenticateWithOauth } = require('../lib/oauth');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { uiFeatureHighlight } = require('../lib/ui');
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');

const i18nKey = 'cli.commands.auth';

Expand Down Expand Up @@ -85,6 +90,8 @@ exports.handler = async options => {
let updatedConfig;
let validName;
let successAuthMethod;
let token;
let defaultName;

switch (authType) {
case OAUTH_AUTH_METHOD.value:
Expand All @@ -98,10 +105,18 @@ exports.handler = async options => {
case PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
configData = await personalAccessKeyPrompt({ env, account });

updatedConfig = await updateConfigWithPersonalAccessKey(
configData.personalAccessKey,
env
);
try {
token = await getAccessToken(configData.personalAccessKey, env);
defaultName = toKebabCase(token.hubName);

updatedConfig = await updateConfigWithAccessToken(
token,
configData.personalAccessKey,
env
);
} catch (e) {
logErrorInstance(e);
}

if (!updatedConfig) {
break;
Expand All @@ -110,7 +125,7 @@ exports.handler = async options => {
validName = updatedConfig.name;

if (!validName) {
const { name: namePrompt } = await enterAccountNamePrompt();
const { name: namePrompt } = await enterAccountNamePrompt(defaultName);
validName = namePrompt;
}

Expand Down
13 changes: 9 additions & 4 deletions packages/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ const {
const { i18n } = require('../lib/lang');
const { logger } = require('@hubspot/cli-lib/logger');
const {
updateConfigWithPersonalAccessKey,
getAccessToken,
updateConfigWithAccessToken,
} = require('@hubspot/local-dev-lib/personalAccessKey');
const { getCwd } = require('@hubspot/local-dev-lib/path');
const { toKebabCase } = require('@hubspot/local-dev-lib/text');
const { trackCommandUsage, trackAuthAction } = require('../lib/usageTracking');
const { setLogLevel, addTestingOptions } = require('../lib/commonOpts');
const { promptUser } = require('../lib/prompts/promptUtils');
Expand All @@ -52,12 +54,15 @@ const TRACKING_STATUS = {

const personalAccessKeyConfigCreationFlow = async (env, account) => {
const { personalAccessKey } = await personalAccessKeyPrompt({ env, account });
const { name } = await enterAccountNamePrompt();

let updatedConfig;

try {
updatedConfig = updateConfigWithPersonalAccessKey(
const token = await getAccessToken(personalAccessKey, env);
const defaultName = toKebabCase(token.hubName);
const { name } = await enterAccountNamePrompt(defaultName);

updatedConfig = updateConfigWithAccessToken(
token,
personalAccessKey,
env,
name,
Expand Down
14 changes: 11 additions & 3 deletions packages/cli/lib/sandboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const { i18n } = require('./lang');
const { handleExit, handleKeypress } = require('./process');
const { logger } = require('@hubspot/cli-lib/logger');
const {
updateConfigWithPersonalAccessKey,
getAccessToken,
updateConfigWithAccessToken,
} = require('@hubspot/local-dev-lib/personalAccessKey');
const { EXIT_CODES } = require('./enums/exitCodes');
const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt');
Expand Down Expand Up @@ -247,7 +248,9 @@ const saveSandboxToConfig = async (env, result, force = false) => {
let updatedConfig;

try {
updatedConfig = await updateConfigWithPersonalAccessKey(
const token = await getAccessToken(personalAccessKey, env);
updatedConfig = await updateConfigWithAccessToken(
token,
personalAccessKey,
env
);
Expand Down Expand Up @@ -329,6 +332,7 @@ function pollSyncTaskStatus(
const mergeTasks = {
'lead-flows': 'forms', // lead-flows are a subset of forms. We combine these in the UI as a single item, so we want to merge here for consistency.
};
const ignoreTasks = ['gates'];
let progressCounter = {};
let pollInterval;
// Handle manual exit for return key and ctrl+c
Expand Down Expand Up @@ -365,7 +369,11 @@ function pollSyncTaskStatus(
for (const task of taskResult.tasks) {
// For each sync task, show a progress bar and increment bar each time we run this interval until status is 'COMPLETE'
const taskType = task.type;
if (!progressBar.get(taskType) && !mergeTasks[taskType]) {
if (
!progressBar.get(taskType) &&
!mergeTasks[taskType] &&
!ignoreTasks.includes(taskType)
) {
// skip creation of lead-flows bar because we're combining lead-flows into the forms bar, otherwise create a bar instance for the type
progressCounter[taskType] = 0;
progressBar.create(taskType, 100, 0, {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@hubspot/cli-lib": "^8.0.1",
"@hubspot/local-dev-lib": "^0.1.1",
"@hubspot/local-dev-lib": "^0.2.1",
"@hubspot/serverless-dev-runtime": "5.1.1",
"@hubspot/ui-extensions-dev-server": "0.8.6",
"archiver": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-dev-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"dependencies": {
"@hubspot/cli-lib": "^8.0.1",
"@hubspot/local-dev-lib": "^0.1.1",
"@hubspot/local-dev-lib": "^0.2.1",
"body-parser": "^1.19.0",
"chalk": "^4.1.0",
"chokidar": "^3.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cms-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@hubspot/cli-lib": "^8.0.1",
"@hubspot/local-dev-lib": "^0.1.1"
"@hubspot/local-dev-lib": "^0.2.1"
},
"gitHead": "0659fd19cabc3645af431b177c11d0c1b089e0f8"
}
Loading
Loading