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

fixing the message users get when code:push to an app with latest live version #102

Merged
merged 5 commits into from
Sep 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaycom/apps-cli",
"version": "4.1.0",
"version": "4.1.1",
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
"author": "monday.com Apps Team",
"type": "module",
Expand Down
3 changes: 3 additions & 0 deletions src/consts/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export const VAR_UNKNOWN = 'unknown';
export const APP_FEATURE_ID_TO_ENTER = 'Please enter the app feature id of your app:';

export const BUILD_ID_TO_ENTER = 'Please enter the build id of your app:';

export const LIVE_VERSION_ERROR_LOG =
'Operation failed: The latest app version is live. Create a new draft version or use --force to override';
11 changes: 8 additions & 3 deletions src/services/app-versions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ export const listAppVersionsByAppId = async (appId: AppId): Promise<Array<AppVer
}
};

export const defaultVersionByAppId = async (appId: AppId, useLiveVersion = false): Promise<AppVersion | undefined> => {
export const defaultVersionByAppId = async (
appId: AppId,
options: { customLogMessage?: string; useLiveVersion?: boolean } = {},
): Promise<AppVersion | undefined> => {
const defaults = { useLiveVersion: false };
options = { ...defaults, ...options };
logger.info(`Getting the latest valid version for app id - ${appId}`);

const appVersions = await listAppVersionsByAppId(appId);
const latestVersion = appVersions.sort((a, b) => b.id - a.id)[0];
const allowedStatuses = useLiveVersion
const allowedStatuses = options?.useLiveVersion
? [APP_VERSION_STATUS.LIVE, APP_VERSION_STATUS.DRAFT]
: [APP_VERSION_STATUS.DRAFT];

const validVersion = allowedStatuses.includes(latestVersion.status) ? latestVersion : undefined;
if (validVersion) {
logger.info(`Using version - ${validVersion?.id} for app id - ${appId}`);
} else {
logger.error(`No valid version found for app id - ${appId}`);
logger.info(options?.customLogMessage || `No valid version found for app id - ${appId}`);
}

return validVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/services/apps-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const cloneAppTemplateAndLoadManifest = async (
};

export const createFeatures = async (ctx: AppCreateCommandTasksContext) => {
const defaultVersion = await defaultVersionByAppId(ctx.appId!, false);
const defaultVersion = await defaultVersionByAppId(ctx.appId!);
const baseUrl = await getTunnelingDomain();
if (!defaultVersion) throw new Error(`No default version found for app id - ${ctx.appId}`);
ctx.appVersionId = defaultVersion.id;
Expand Down
6 changes: 5 additions & 1 deletion src/services/dynamic-choices-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { listAppFeaturesByAppVersionId } from 'services/app-features-service';
import { defaultVersionByAppId, listAppVersionsByAppId } from 'services/app-versions-service';
import { listApps } from 'services/apps-service';
import { PromptService } from 'services/prompt-service';
import { LIVE_VERSION_ERROR_LOG } from 'src/consts/messages';
import { AppFeature, AppFeatureType } from 'src/types/services/app-features-service';

export const DynamicChoicesService = {
Expand Down Expand Up @@ -57,7 +58,10 @@ export const DynamicChoicesService = {
if (useLiveVersion) filterByStatus.push(APP_VERSION_STATUS.LIVE);

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

return { appId, appVersionId: defaultVersion.id };
Expand Down
Loading