Skip to content

Commit

Permalink
cli-test: adding shell and app.list APIs, exposing QA environment…
Browse files Browse the repository at this point in the history
… flags, added more traces available in CLI v2.25.0 (#1804)
  • Loading branch information
filmaj authored Jun 3, 2024
1 parent cf80469 commit 17ef7ae
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
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 @@ export const install = async function workspaceInstall(
* @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> {
// TODO: (breaking change) separate parameters vs single-param-object
const cmd = new SlackCLIProcess('app list');
const cmd = new SlackCLIProcess('app list', options);
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 @@ export default {
/** team domain to logout from */
teamFlag?: string;
/** perform the logout for all authentications */
allWorkspaces?: boolean
allWorkspaces?: boolean;
qa?: boolean;
}): 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 };
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 @@ import commandError from '../command-error';
* @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
globalOpts?: SlackCLIGlobalOptions,
commandOpts?: SlackCLICommandOptions,
shellOpts?: SpawnOptionsWithoutStdio,
Expand Down Expand Up @@ -43,7 +43,7 @@ export const createAppFromTemplate = async function createAppFromTemplate({
shellOpts = {},
}: {
templateString: string;
appName?: string;
appName?: string; // TODO: bad arg name. it should be app path, because this is effectively how it is used
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

0 comments on commit 17ef7ae

Please sign in to comment.