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

test: Fixing slack notifications posts #1146

Merged
merged 1 commit into from
Aug 22, 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
status: ${{ job.status }}
notify_when: 'failure'
notification_title: 'CLI Build failed'
notification_title: 'CLI build failure'
message_format: '{emoji} *Build* {status_message} in <{repo_url}|{repo}> on <{commit_url}|{commit_sha}>"'
footer: '<{run_url}|View Run>'
env:
Expand Down
191 changes: 95 additions & 96 deletions packages/cli/commands/list.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
//const chalk = require('chalk');
const chalk = require('chalk');
const {
addAccountOptions,
addConfigOptions,
// getAccountId,
getAccountId,
addUseEnvironmentOptions,
} = require('../lib/commonOpts');
//const { trackCommandUsage } = require('../lib/usageTracking');
//const { isPathFolder } = require('../lib/filesystem');

//const { logger } = require('@hubspot/local-dev-lib/logger');
// const {
// logApiErrorInstance,
// ApiErrorContext,
// } = require('../lib/errorHandlers/apiErrors');
// const {
// getDirectoryContentsByPath,
// } = require('@hubspot/local-dev-lib/api/fileMapper');
//const { HUBSPOT_FOLDER, MARKETPLACE_FOLDER } = require('../lib/constants');
//const { loadAndValidateOptions } = require('../lib/validation');
const { trackCommandUsage } = require('../lib/usageTracking');
const { isPathFolder } = require('../lib/filesystem');

const { logger } = require('@hubspot/local-dev-lib/logger');
const {
logApiErrorInstance,
ApiErrorContext,
} = require('../lib/errorHandlers/apiErrors');
const {
getDirectoryContentsByPath,
} = require('@hubspot/local-dev-lib/api/fileMapper');
const { HUBSPOT_FOLDER, MARKETPLACE_FOLDER } = require('../lib/constants');
const { loadAndValidateOptions } = require('../lib/validation');
const { i18n } = require('../lib/lang');

const i18nKey = 'commands.list';
//const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { EXIT_CODES } = require('../lib/enums/exitCodes');

exports.command = 'list [path]';
exports.describe = i18n(`${i18nKey}.describe`);

exports.handler = async () => {
throw new Error('broken command');
// await loadAndValidateOptions(options);

// const { path } = options;
// const directoryPath = path || '/';
// const accountId = getAccountId(options);
// let contentsResp;

// trackCommandUsage('list', null, accountId);

// logger.debug(
// i18n(`${i18nKey}.gettingPathContents`, {
// path: directoryPath,
// })
// );

// try {
// contentsResp = await getDirectoryContentsByPath(accountId, directoryPath);
// } catch (e) {
// logApiErrorInstance(e, new ApiErrorContext({ accountId, directoryPath }));
// process.exit(EXIT_CODES.SUCCESS);
// }

// if (!contentsResp.folder) {
// logger.info(
// i18n(`${i18nKey}.noFilesFoundAtPath`, {
// path: directoryPath,
// })
// );
// return;
// }
// // getDirectoryContentsByPath omits @hubspot
// const contents =
// directoryPath === '/'
// ? ['@hubspot', ...contentsResp.children]
// : contentsResp.children;

// if (contents.length === 0) {
// logger.info(
// i18n(`${i18nKey}.noFilesFoundAtPath`, {
// path: directoryPath,
// })
// );
// return;
// }

// const folderContentsOutput = contents
// .map(addColorToContents)
// .sort(sortContents)
// .join('\n');

// logger.log(folderContentsOutput);
exports.handler = async options => {
await loadAndValidateOptions(options);

const { path } = options;
const directoryPath = path || '/';
const accountId = getAccountId(options);
let contentsResp;

trackCommandUsage('list', null, accountId);

logger.debug(
i18n(`${i18nKey}.gettingPathContents`, {
path: directoryPath,
})
);

try {
contentsResp = await getDirectoryContentsByPath(accountId, directoryPath);
} catch (e) {
logApiErrorInstance(e, new ApiErrorContext({ accountId, directoryPath }));
process.exit(EXIT_CODES.SUCCESS);
}

if (!contentsResp.folder) {
logger.info(
i18n(`${i18nKey}.noFilesFoundAtPath`, {
path: directoryPath,
})
);
return;
}
// getDirectoryContentsByPath omits @hubspot
const contents =
directoryPath === '/'
? ['@hubspot', ...contentsResp.children]
: contentsResp.children;

if (contents.length === 0) {
logger.info(
i18n(`${i18nKey}.noFilesFoundAtPath`, {
path: directoryPath,
})
);
return;
}

const folderContentsOutput = contents
.map(addColorToContents)
.sort(sortContents)
.join('\n');

logger.log(folderContentsOutput);
};

exports.builder = yargs => {
Expand All @@ -95,30 +94,30 @@ exports.builder = yargs => {
return yargs;
};

// const addColorToContents = fileOrFolder => {
// if (!isPathFolder(fileOrFolder)) {
// return chalk.reset.cyan(fileOrFolder);
// }
// if (fileOrFolder === HUBSPOT_FOLDER || fileOrFolder === MARKETPLACE_FOLDER) {
// return chalk.reset.bold.blue(fileOrFolder);
// }
// return chalk.reset.blue(fileOrFolder);
// };

// const sortContents = (a, b) => {
// // Pin @hubspot folder to top
// if (a === HUBSPOT_FOLDER) {
// return -1;
// } else if (b === HUBSPOT_FOLDER) {
// return 1;
// }

// // Pin @marketplace folder to top
// if (a === MARKETPLACE_FOLDER) {
// return -1;
// } else if (b === MARKETPLACE_FOLDER) {
// return 1;
// }

// return a.localeCompare(b);
// };
const addColorToContents = fileOrFolder => {
if (!isPathFolder(fileOrFolder)) {
return chalk.reset.cyan(fileOrFolder);
}
if (fileOrFolder === HUBSPOT_FOLDER || fileOrFolder === MARKETPLACE_FOLDER) {
return chalk.reset.bold.blue(fileOrFolder);
}
return chalk.reset.blue(fileOrFolder);
};

const sortContents = (a, b) => {
// Pin @hubspot folder to top
if (a === HUBSPOT_FOLDER) {
return -1;
} else if (b === HUBSPOT_FOLDER) {
return 1;
}

// Pin @marketplace folder to top
if (a === MARKETPLACE_FOLDER) {
return -1;
} else if (b === MARKETPLACE_FOLDER) {
return 1;
}

return a.localeCompare(b);
};
Loading