Skip to content

Commit

Permalink
Fix: allow choosing live versions (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: Your Full Name <[email protected]>
  • Loading branch information
tsemachLi and Your Full Name authored Jan 10, 2024
1 parent 90d5533 commit c796e4a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaycom/apps-cli",
"version": "2.2.1",
"version": "2.2.2",
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
"author": "monday.com Apps Team",
"type": "module",
Expand Down
5 changes: 4 additions & 1 deletion src/commands/app-features/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export default class Build extends AuthenticatedCommand {
}

if (!appVersionId) {
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion({ appId });
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, false, {
appId,
autoSelectVersion: false,
});
appVersionId = appAndAppVersion.appVersionId;
appId = appAndAppVersion.appId;
}
Expand Down
5 changes: 4 additions & 1 deletion src/commands/app-features/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default class AppFeatureList extends AuthenticatedCommand {
let appVersionId = flags.appVersionId;

if (!appVersionId) {
const appIdAndAppVersionId = await DynamicChoicesService.chooseAppAndAppVersion({ appId });
const appIdAndAppVersionId = await DynamicChoicesService.chooseAppAndAppVersion(true, true, {
appId,
autoSelectVersion: false,
});
appVersionId = Number(appIdAndAppVersionId.appVersionId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/app-version/builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class AppVersionBuilds extends AuthenticatedCommand {
const { flags } = await this.parse(Status);
let appVersionId = flags.appVersionId;
if (!appVersionId) {
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion();
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(true, true);
appVersionId = appAndAppVersion.appVersionId;
}

Expand Down
5 changes: 2 additions & 3 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ export default class AppDeploy extends AuthenticatedCommand {
async getAppVersionId(appVersionId: string | undefined, appId: string | undefined, force: boolean): Promise<string> {
if (appVersionId) return appVersionId;

const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion({
const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, Boolean(force), {
appId: Number(appId),
useDefaultVersion: true,
useLiveVersion: force,
autoSelectVersion: true,
});

return latestDraftVersion.appVersionId.toString();
Expand Down
83 changes: 42 additions & 41 deletions src/commands/code/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,50 @@ export default class Logs extends AuthenticatedCommand {

static args = {};
DEBUG_TAG = 'logs';

public async run(): Promise<void> {
try {
const { flags } = await this.parse(Logs);

const appVersionId = await this.getAppVersionId(flags.appVersionId);

const eventSource = (flags.eventSource || (await eventSourcePrompt())) as EventSource;
const logsType = await this.getLogType(eventSource, flags.logsType);
const logsFilterCriteria = await this.getLogsFilterCriteria(
eventSource,
flags.logsStartDate,
flags.logsEndDate,
flags.logSearchFromText,
);

const args: LogsCommandArguments = {
appVersionId,
logsType,
logsFilterCriteria,
};

this.preparePrintCommand(this, {
appVersionId,
logsType,
eventSource,
logsStartDate: logsFilterCriteria?.fromDate && `"${logsFilterCriteria.fromDate.toString()}"`,
logsEndDate: logsFilterCriteria?.toDate && `"${logsFilterCriteria.toDate.toString()}"`,
logSearchFromText: logsFilterCriteria?.text,
});

const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria);
await streamMessages(clientChannel);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);

// need to signal to the parent process that the command failed
process.exit(1);
}
}

private async getAppVersionId(appVersionId?: number): Promise<number> {
if (!appVersionId) {
const { appVersionId: inputAppVersionId } = await DynamicChoicesService.chooseAppAndAppVersion();
const { appVersionId: inputAppVersionId } = await DynamicChoicesService.chooseAppAndAppVersion(true, true);
return inputAppVersionId;
}

Expand Down Expand Up @@ -199,44 +240,4 @@ export default class Logs extends AuthenticatedCommand {

return { fromDate, toDate, text };
}

public async run(): Promise<void> {
try {
const { flags } = await this.parse(Logs);

const appVersionId = await this.getAppVersionId(flags.appVersionId);

const eventSource = (flags.eventSource || (await eventSourcePrompt())) as EventSource;
const logsType = await this.getLogType(eventSource, flags.logsType);
const logsFilterCriteria = await this.getLogsFilterCriteria(
eventSource,
flags.logsStartDate,
flags.logsEndDate,
flags.logSearchFromText,
);

const args: LogsCommandArguments = {
appVersionId,
logsType,
logsFilterCriteria,
};

this.preparePrintCommand(this, {
appVersionId,
logsType,
eventSource,
logsStartDate: logsFilterCriteria?.fromDate && `"${logsFilterCriteria.fromDate.toString()}"`,
logsEndDate: logsFilterCriteria?.toDate && `"${logsFilterCriteria.toDate.toString()}"`,
logSearchFromText: logsFilterCriteria?.text,
});

const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria);
await streamMessages(clientChannel);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);

// need to signal to the parent process that the command failed
process.exit(1);
}
}
}
6 changes: 3 additions & 3 deletions src/commands/code/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export default class Push extends AuthenticatedCommand {
if (!appVersionId) {
const force = flags.force;
const appId = flags.appId;
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion({
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, Boolean(force), {
appId: Number(appId),
useDefaultVersion: true,
useLiveVersion: force,
autoSelectVersion: true,
});

appVersionId = appAndAppVersion.appVersionId;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/code/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Status extends AuthenticatedCommand {
let appVersionId = flags.appVersionId;
try {
if (!appVersionId) {
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion();
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(true, true);
appVersionId = appAndAppVersion.appVersionId;
}

Expand Down
16 changes: 10 additions & 6 deletions src/services/dynamic-choices-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ export const DynamicChoicesService = {
return selectedAppVersionId;
},

async chooseAppAndAppVersion(options?: { appId?: number; useDefaultVersion?: boolean; useLiveVersion?: boolean }) {
const { appId, useDefaultVersion = false, useLiveVersion = false } = options || {};
const filterByStatus = useLiveVersion
? [APP_VERSION_STATUS.LIVE, APP_VERSION_STATUS.DRAFT]
: [APP_VERSION_STATUS.DRAFT];
async chooseAppAndAppVersion(
useDeprecatedVersion: boolean,
useLiveVersion: boolean,
options?: { appId?: number; autoSelectVersion?: boolean },
) {
const { appId, autoSelectVersion = false } = options || {};
const filterByStatus = [APP_VERSION_STATUS.DRAFT];
if (useDeprecatedVersion) filterByStatus.push(APP_VERSION_STATUS.DEPRECATED);
if (useLiveVersion) filterByStatus.push(APP_VERSION_STATUS.LIVE);

if (useDefaultVersion && appId) {
if (appId && autoSelectVersion) {
const defaultVersion = await defaultVersionByAppId(appId, useLiveVersion);
if (!defaultVersion) throw new Error(`No default version found for app id - ${appId}`);

Expand Down

0 comments on commit c796e4a

Please sign in to comment.