-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: support builds * Feat: support builds --------- Co-authored-by: Your Full Name <[email protected]>
- Loading branch information
Showing
9 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Flags } from '@oclif/core'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
|
||
import Status from 'commands/code/status'; | ||
import { AuthenticatedCommand } from 'commands-base/authenticated-command'; | ||
import { APP_VERSION_ID_TO_ENTER } from 'consts/messages'; | ||
import { listAppBuilds } from 'services/app-builds-service'; | ||
import { DynamicChoicesService } from 'services/dynamic-choices-service'; | ||
import { AppRelease } from 'services/schemas/app-releases-schema'; | ||
import { HttpError } from 'types/errors'; | ||
import logger from 'utils/logger'; | ||
|
||
const printBuilds = (appBuilds: Array<AppRelease>) => { | ||
const appBuildsTable = appBuilds.map(appBuild => { | ||
return { | ||
category: appBuild.category, | ||
...(appBuild.data?.liveUrl && { 'live url': appBuild.data?.liveUrl }), | ||
...(appBuild.data?.url && { url: appBuild.data?.url }), | ||
...(appBuild.data?.latestUrl && { 'static url (latest deployment)': appBuild.data?.latestUrl }), | ||
...(appBuild.data?.sourceUrl && { 'source url (download)': appBuild.data?.sourceUrl }), | ||
...(appBuild.data?.microFrontendName && { 'micro frontend name': appBuild.data?.microFrontendName }), | ||
}; | ||
}); | ||
|
||
logger.table(appBuildsTable); | ||
}; | ||
|
||
export default class AppVersionBuilds extends AuthenticatedCommand { | ||
static description = 'List all builds for a specific app version'; | ||
static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID']; | ||
static flags = AppVersionBuilds.serializeFlags({ | ||
appVersionId: Flags.integer({ | ||
char: 'i', | ||
aliases: ['v'], | ||
description: APP_VERSION_ID_TO_ENTER, | ||
}), | ||
}); | ||
|
||
DEBUG_TAG = 'app_version_builds'; | ||
|
||
public async run(): Promise<void> { | ||
const { flags } = await this.parse(Status); | ||
let appVersionId = flags.appVersionId; | ||
if (!appVersionId) { | ||
const appAndAppVersion = await DynamicChoicesService.chooseAppAndAppVersion(); | ||
appVersionId = appAndAppVersion.appVersionId; | ||
} | ||
|
||
try { | ||
this.preparePrintCommand(this, { appVersionId }); | ||
const appReleases = await listAppBuilds(appVersionId); | ||
printBuilds(appReleases); | ||
} catch (error: unknown) { | ||
if (error instanceof HttpError && error.code === StatusCodes.NOT_FOUND) { | ||
logger.error(`No builds found for provided app version id - "${appVersionId}"`); | ||
} else { | ||
logger.error(`An unknown error happened while fetching builds for app version id - "${appVersionId}"`); | ||
} | ||
|
||
process.exit(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { appReleasesUrl } from 'consts/urls'; | ||
import { execute } from 'services/api-service'; | ||
import { AppRelease, AppReleasesResponse, appReleasesSchema } from 'services/schemas/app-releases-schema'; | ||
import { HttpError } from 'types/errors'; | ||
import { AppVersionId } from 'types/general'; | ||
import { HttpMethodTypes } from 'types/services/api-service'; | ||
import { appsUrlBuilder } from 'utils/urls-builder'; | ||
|
||
export const listAppBuilds = async (appVersionId: AppVersionId): Promise<Array<AppRelease>> => { | ||
try { | ||
const path = appReleasesUrl(appVersionId); | ||
const url = appsUrlBuilder(path); | ||
const response = await execute<AppReleasesResponse>( | ||
{ | ||
url, | ||
headers: { Accept: 'application/json' }, | ||
method: HttpMethodTypes.GET, | ||
}, | ||
appReleasesSchema, | ||
); | ||
return response.appReleases; | ||
} catch (error: any) { | ||
if (error instanceof HttpError) { | ||
throw error; | ||
} | ||
|
||
throw new Error('Failed to list app versions.'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { z } from 'zod'; | ||
|
||
import { baseResponseHttpMetaDataSchema } from 'services/schemas/api-service-schemas'; | ||
import { appReleaseIdSchema, appVersionIdSchema } from 'services/schemas/general-schemas'; | ||
|
||
export const appReleaseSchema = z.object({ | ||
id: appReleaseIdSchema, | ||
// eslint-disable-next-line camelcase | ||
app_version_id: appVersionIdSchema, | ||
kind: z.string(), | ||
category: z.string(), | ||
state: z.string(), | ||
data: z | ||
.object({ | ||
url: z.string().optional(), | ||
latestUrl: z.string().optional(), | ||
liveUrl: z.string().optional(), | ||
deploymentState: z.string().optional(), | ||
sourceUrl: z.string().optional(), | ||
microFrontendName: z.string().optional(), | ||
}) | ||
.optional(), | ||
}); | ||
|
||
export const appReleasesSchema = z | ||
.object({ | ||
appReleases: z.array(appReleaseSchema), | ||
}) | ||
.merge(baseResponseHttpMetaDataSchema); | ||
|
||
export type AppReleasesResponse = z.infer<typeof appReleasesSchema>; | ||
export type AppRelease = z.infer<typeof appReleaseSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { z } from 'zod'; | ||
|
||
import { appIdSchema } from 'services/schemas/general-schemas'; | ||
import { appIdSchema, appVersionIdSchema } from 'services/schemas/general-schemas'; | ||
|
||
export type AppId = z.infer<typeof appIdSchema>; | ||
export type AppVersionId = z.infer<typeof appVersionIdSchema>; |