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

cli-test: adding shell and app.list APIs, exposing QA environment flags, added more traces available in CLI v2.25.0 #1804

Merged
merged 4 commits into from
Jun 3, 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
7 changes: 5 additions & 2 deletions packages/cli-test/src/cli/commands/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@
* @param appPath path to app
* @returns command output
*/
export const list = async function appList(appPath: string): Promise<string> {
export const list = async function appList(
appPath: string,
options?: { qa?: boolean },
): Promise<string> {

Check warning on line 61 in packages/cli-test/src/cli/commands/app.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/app.ts#L59-L61

Added lines #L59 - L61 were not covered by tests
// TODO: (breaking change) separate parameters vs single-param-object
const cmd = new SlackCLIProcess('app list');
const cmd = new SlackCLIProcess('app list', options);

Check warning on line 63 in packages/cli-test/src/cli/commands/app.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/app.ts#L63

Added line #L63 was not covered by tests
try {
const proc = await cmd.execAsync({
cwd: appPath,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli-test/src/cli/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@
/** team domain to logout from */
teamFlag?: string;
/** perform the logout for all authentications */
allWorkspaces?: boolean
allWorkspaces?: boolean;
qa?: boolean;

Check warning on line 91 in packages/cli-test/src/cli/commands/auth.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/auth.ts#L90-L91

Added lines #L90 - L91 were not covered by tests
}): Promise<string> {
// TODO: (breaking change) inconsistent use of object-as-params vs. separate parameters
// Create the command with workspaces to logout of
const globalOpts: SlackCLIGlobalOptions = {};
const globalOpts: SlackCLIGlobalOptions = { qa: options?.qa };

Check warning on line 95 in packages/cli-test/src/cli/commands/auth.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/auth.ts#L95

Added line #L95 was not covered by tests
const cmdOpts: SlackCLICommandOptions = {};
if (options?.teamFlag) {
globalOpts.team = options.teamFlag;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-test/src/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @returns command output
*/
export const create = async function create(
appName?: string,
appName?: string, // TODO: bad arg name. it should be app path, because this is effectively how it is used

Check warning on line 11 in packages/cli-test/src/cli/commands/create.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/create.ts#L11

Added line #L11 was not covered by tests
globalOpts?: SlackCLIGlobalOptions,
commandOpts?: SlackCLICommandOptions,
shellOpts?: SpawnOptionsWithoutStdio,
Expand Down Expand Up @@ -43,7 +43,7 @@
shellOpts = {},
}: {
templateString: string;
appName?: string;
appName?: string; // TODO: bad arg name. it should be app path, because this is effectively how it is used

Check warning on line 46 in packages/cli-test/src/cli/commands/create.ts

View check run for this annotation

Codecov / codecov/patch

packages/cli-test/src/cli/commands/create.ts#L46

Added line #L46 was not covered by tests
branchName?: string;
shellOpts?: SpawnOptionsWithoutStdio;
}): Promise<string> {
Expand Down
8 changes: 5 additions & 3 deletions packages/cli-test/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const SlackCLI = {
appPath,
appTeamID,
isLocalApp,
qa,
}: {
// TODO: (breaking change) model these types better, if appPath isn't provided then appTeamId
// and isLocalApp are not needed either
Expand All @@ -74,15 +75,16 @@ export const SlackCLI = {
/** Team domain or ID where app is installed */
appTeamID: string;
isLocalApp?: boolean;
qa?: boolean;
}): Promise<void> {
if (appPath) {
// List instances of app installation if app path provided
const installedAppsOutput = await SlackCLI.app.list(appPath);
const installedAppsOutput = await SlackCLI.app.list(appPath, { qa });
// If app is installed
if (!installedAppsOutput.includes('This project has no apps')) {
// Soft app delete
try {
await SlackCLI.app.delete(appPath, appTeamID, { isLocalApp });
await SlackCLI.app.delete(appPath, appTeamID, { isLocalApp, qa });
} catch (error) {
logger.warn(`stopSession could not delete app gracefully, continuing. Error: ${error}`);
}
Expand All @@ -97,7 +99,7 @@ export const SlackCLI = {

// Log out if logged in
try {
await SlackCLI.logout({ allWorkspaces: true });
await SlackCLI.logout({ allWorkspaces: true, qa });
} catch (error) {
// TODO: maybe should error instead? this seems pretty bad
logger.warn(`Could not logout gracefully. Error: ${error}`);
Expand Down
1 change: 1 addition & 0 deletions packages/cli-test/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { SlackCLI } from './cli';
export { SlackCLIProcess } from './cli/cli-process';
export { SlackTracerId, SlackProduct } from './utils/constants';
export { shell } from './cli/shell';

// Check for cli binary path
if (!process.env.SLACK_CLI_PATH) {
Expand Down
13 changes: 12 additions & 1 deletion packages/cli-test/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: would be nice to add JSDocs for each of these to describe when they appear in CLI output
/**
* This file should be kept up to date with the source of truth in the Slack CLI repo
*/
Expand All @@ -12,16 +13,26 @@ export const SlackTracerId = {
SLACK_TRACE_AUTH_LIST_SUCCESS: 'SLACK_TRACE_AUTH_LIST_SUCCESS',
SLACK_TRACE_AUTH_LOGIN_START: 'SLACK_TRACE_AUTH_LOGIN_START',
SLACK_TRACE_AUTH_LOGIN_SUCCESS: 'SLACK_TRACE_AUTH_LOGIN_SUCCESS',
SLACK_TRACE_AUTH_LOGOUT_START: 'SLACK_TRACE_AUTH_LOGOUT_START',
SLACK_TRACE_AUTH_LOGOUT_SUCCESS: 'SLACK_TRACE_AUTH_LOGOUT_SUCCESS',
SLACK_TRACE_AUTH_REVOKE_START: 'SLACK_TRACE_AUTH_REVOKE_START',
SLACK_TRACE_AUTH_REVOKE_SUCCESS: 'SLACK_TRACE_AUTH_REVOKE_SUCCESS',
SLACK_TRACE_COLLABORATOR_ADD_COLLABORATOR: 'SLACK_TRACE_COLLABORATOR_ADD_COLLABORATOR',
SLACK_TRACE_COLLABORATOR_ADD_SUCCESS: 'SLACK_TRACE_COLLABORATOR_ADD_SUCCESS',
SLACK_TRACE_COLLABORATOR_LIST_COLLABORATOR: 'SLACK_TRACE_COLLABORATOR_LIST_COLLABORATOR',
SLACK_TRACE_COLLABORATOR_LIST_COUNT: 'SLACK_TRACE_COLLABORATOR_LIST_COUNT',
SLACK_TRACE_COLLABORATOR_LIST_SUCCESS: 'SLACK_TRACE_COLLABORATOR_LIST_SUCCESS',
SLACK_TRACE_COLLABORATOR_REMOVE_COLLABORATOR: 'SLACK_TRACE_COLLABORATOR_REMOVE_COLLABORATOR',
SLACK_TRACE_COLLABORATOR_REMOVE_SUCCESS: 'SLACK_TRACE_COLLABORATOR_REMOVE_SUCCESS',
SLACK_TRACE_CREATE_DEPENDENCIES_SUCCESS: 'SLACK_TRACE_CREATE_DEPENDENCIES_SUCCESS',
SLACK_TRACE_CREATE_ERROR: 'SLACK_TRACE_CREATE_ERROR',
SLACK_TRACE_CREATE_PROJECT_PATH: 'SLACK_TRACE_CREATE_PROJECT_PATH',
SLACK_TRACE_CREATE_START: 'SLACK_TRACE_CREATE_START',
SLACK_TRACE_CREATE_SUCCESS: 'SLACK_TRACE_CREATE_SUCCESS',
SLACK_TRACE_CREATE_TEMPLATE_OPTIONS: 'SLACK_TRACE_CREATE_TEMPLATE_OPTIONS',
SLACK_TRACE_DATASTORE_COUNT_DATASTORE: 'SLACK_TRACE_DATASTORE_COUNT_DATASTORE',
SLACK_TRACE_DATASTORE_COUNT_SUCCESS: 'SLACK_TRACE_DATASTORE_COUNT_SUCCESS',
SLACK_TRACE_DATASTORE_COUNT_TOTAL: 'SLACK_TRACE_DATASTORE_COUNT_TOTAL',
SLACK_TRACE_CREATE_TEMPLATE_OPTIONS: 'SLACK_TRACE_CREATE_TEMPLATE_OPTIONS',
SLACK_TRACE_FEEDBACK_MESSAGE: 'SLACK_TRACE_FEEDBACK_MESSAGE',
SLACK_TRACE_MANIFEST_VALIDATE_SUCCESS: 'SLACK_TRACE_MANIFEST_VALIDATE_SUCCESS',
SLACK_TRACE_PLATFORM_DEPLOY_SUCCESS: 'SLACK_TRACE_PLATFORM_DEPLOY_SUCCESS',
Expand Down
1 change: 0 additions & 1 deletion packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import isStream from 'is-stream';
import pQueue from 'p-queue';
import pRetry, { AbortError } from 'p-retry';
import axios, { AxiosHeaderValue, AxiosInstance, AxiosResponse } from 'axios';
// eslint-disable-next-line @typescript-eslint/naming-convention
import FormData from 'form-data';
import isElectron from 'is-electron';
import {
Expand Down
Loading