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

Fix: allow choosing live versions #72

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 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), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, Boolean(force), {
const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, !!force, {

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint: use Boolean(force) instead.(no-implicit-coercion)

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 },
Comment on lines +48 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment:
Transfering true, true can cause issues as well.
What do you say about having an object for the arguments? not optional, but an object for better readability

Suggested change
async chooseAppAndAppVersion(
useDeprecatedVersion: boolean,
useLiveVersion: boolean,
options?: { appId?: number; autoSelectVersion?: boolean },
async chooseAppAndAppVersion(
{ useDeprecatedVersion: boolean,
useLiveVersion: boolean },
options?: { appId?: number; autoSelectVersion?: boolean },

This will make sure people understand what is true and what is false

) {
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
Loading