-
Notifications
You must be signed in to change notification settings - Fork 4
TA-4197: Add deployment commands #248
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
Merged
Laberion Ajvazi (LaberionAjvazi)
merged 4 commits into
master
from
TA-4197-deployment-commands
Sep 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d89b18
TA-4197: Add deployment commands
LaberionAjvazi 524b9a3
TA-4197: Add beta tag, update docs, add pagination to list history
LaberionAjvazi cb79e56
TA-4197: Show deployment date as readable string
LaberionAjvazi 8046588
TA-4197: Show deployment date as readable string
LaberionAjvazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,123 @@ | ||
| import { HttpClient } from "../../core/http/http-client"; | ||
| import { Context } from "../../core/command/cli-context"; | ||
| import { | ||
| CreateDeploymentRequest, | ||
| DeployableTransport, | ||
| DeploymentStatus, | ||
| DeploymentTransport, | ||
| GetDeploymentsRequest, | ||
| TargetTransport, | ||
| } from "./deployment.interfaces"; | ||
| import { FatalError } from "../../core/utils/logger"; | ||
|
|
||
| export class DeploymentApi { | ||
| private httpClient: () => HttpClient; | ||
|
|
||
| constructor(context: Context) { | ||
| this.httpClient = () => context.httpClient; | ||
| } | ||
|
|
||
| public async createDeployment(request: CreateDeploymentRequest): Promise<DeploymentTransport> { | ||
| if (!request.packageKey || request.packageKey.trim() === "") { | ||
| throw new FatalError("Package key is required to create a deployment."); | ||
| } | ||
| if (!request.packageVersion || request.packageVersion.trim() === "") { | ||
| throw new FatalError("Package version is required to create a deployment."); | ||
| } | ||
| if (!request.deployableType || request.deployableType.trim() === "") { | ||
| throw new FatalError("Deployable type is required to create a deployment."); | ||
| } | ||
| if (!request.targetId || request.targetId.trim() === "") { | ||
| throw new FatalError("Target ID is required to create a deployment."); | ||
| } | ||
|
ZgjimHaziri marked this conversation as resolved.
Outdated
|
||
|
|
||
| return this.httpClient() | ||
| .post("/pacman/api/deployments", request) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem creating deployment: ${e}`); | ||
| }); | ||
| } | ||
|
|
||
| public async getDeployments(filter: GetDeploymentsRequest): Promise<DeploymentTransport[]> { | ||
| const queryParams = new URLSearchParams(); | ||
|
|
||
| if (filter.packageKey) { | ||
| queryParams.set("packageKey", filter.packageKey); | ||
| } | ||
| if (filter.targetId) { | ||
| queryParams.set("targetId", filter.targetId); | ||
| } | ||
| if (filter.deployableType) { | ||
| queryParams.set("deployableType", filter.deployableType); | ||
| } | ||
| if (filter.status && filter.status !== DeploymentStatus.UNKNOWN) { | ||
| queryParams.set("status", filter.status); | ||
| } | ||
| if (filter.createdBy) { | ||
| queryParams.set("createdBy", filter.createdBy); | ||
| } | ||
|
|
||
| return this.httpClient() | ||
| .get(`/pacman/api/deployments/history?${queryParams.toString()}`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem getting deployments: ${e}`); | ||
| }); | ||
| } | ||
|
|
||
| public async getActiveDeploymentsForPackage( | ||
| packageKey: string, | ||
| targetIds?: string[], | ||
| limit = 100, | ||
| offset = 0 | ||
| ): Promise<DeploymentTransport[]> { | ||
| const queryParams = new URLSearchParams(); | ||
| queryParams.set("limit", limit.toString()); | ||
| queryParams.set("offset", offset.toString()); | ||
|
|
||
| if (targetIds && targetIds.length > 0) { | ||
| queryParams.set("targetIds", targetIds.join(",")); | ||
| } | ||
|
|
||
| return this.httpClient() | ||
| .get(`/pacman/api/deployments/packages/${packageKey}/active?${queryParams.toString()}`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem getting active deployments for package ${packageKey}: ${e}`); | ||
| }); | ||
| } | ||
|
|
||
| public async getActiveDeploymentForTarget(targetId: string): Promise<DeploymentTransport> { | ||
| return this.httpClient() | ||
| .get(`/pacman/api/deployments/targets/${targetId}/active`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem getting active deployment for target ${targetId}: ${e}`); | ||
| }); | ||
| } | ||
|
|
||
| public async getTargets(deployableType: string, packageKey?: string): Promise<TargetTransport[]> { | ||
| const queryParams = new URLSearchParams(); | ||
| queryParams.set("deployableType", deployableType); | ||
|
|
||
| if (packageKey) { | ||
| queryParams.set("packageKey", packageKey); | ||
| } | ||
|
|
||
| return this.httpClient() | ||
| .get(`/pacman/api/deployments/targets?${queryParams.toString()}`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem getting targets: ${e}`); | ||
| }); | ||
| } | ||
|
|
||
| public async getDeployables(flavor?: string): Promise<DeployableTransport[]> { | ||
| const queryParams = new URLSearchParams(); | ||
| if (flavor) { | ||
| queryParams.set("flavor", flavor); | ||
| } | ||
|
|
||
| return this.httpClient() | ||
| .get(`/pacman/api/deployments/deployables?${queryParams.toString()}`) | ||
| .catch((e) => { | ||
| throw new FatalError(`Problem getting deployables: ${e}`); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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,53 @@ | ||
| export interface DeploymentTransport { | ||
| id: string; | ||
| packageKey: string; | ||
| packageVersion: string; | ||
| deployableType: string; | ||
| target: TargetTransport; | ||
| status: DeploymentStatus; | ||
| statusMessage: string; | ||
| createdBy: string; | ||
| createdAt: string; | ||
| deployedAt: string; | ||
| } | ||
|
|
||
| export interface TargetTransport { | ||
| id: string; | ||
| name: string; | ||
| } | ||
|
|
||
| export interface DeployableTransport { | ||
| name: string; | ||
| type: string; | ||
| targetType: string; | ||
| flavor: string; | ||
| } | ||
|
|
||
| export enum DeploymentStatus { | ||
| UNKNOWN = "unknown", | ||
| PENDING = "PENDING", | ||
| IN_PROGRESS = "IN_PROGRESS", | ||
| SUCCESS = "SUCCESS", | ||
| FAILED = "FAILED", | ||
| } | ||
|
|
||
| export interface CreateDeploymentRequest { | ||
| packageKey: string; | ||
| packageVersion: string; | ||
| deployableType: string; | ||
| targetId: string; | ||
| } | ||
|
|
||
| export interface GetDeploymentsRequest { | ||
| packageKey: string; | ||
| targetId: string; | ||
| deployableType: string; | ||
| status: DeploymentStatus; | ||
| createdBy: string; | ||
| } | ||
|
|
||
| export function fromString(value: string): DeploymentStatus { | ||
| return (Object.values(DeploymentStatus) as string[]).includes(value) | ||
| ? (value as DeploymentStatus) | ||
| : DeploymentStatus.UNKNOWN; | ||
| } |
This file contains hidden or 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,108 @@ | ||
| import { DeploymentApi } from "./deployment-api"; | ||
| import { CreateDeploymentRequest, fromString, GetDeploymentsRequest } from "./deployment.interfaces"; | ||
| import { Context } from "../../core/command/cli-context"; | ||
| import { fileService, FileService } from "../../core/utils/file-service"; | ||
| import { logger } from "../../core/utils/logger"; | ||
| import { v4 as uuidv4 } from "uuid"; | ||
|
|
||
| export class DeploymentService { | ||
| private deploymentApi: DeploymentApi; | ||
|
|
||
| constructor(context: Context) { | ||
| this.deploymentApi = new DeploymentApi(context); | ||
| } | ||
|
|
||
| public async createDeployment(packageKey: string, packageVersion: string, deployableType: string, targetId: string, jsonResponse: boolean): Promise<void> { | ||
| const request: CreateDeploymentRequest = { | ||
| packageKey, | ||
| packageVersion, | ||
| deployableType, | ||
| targetId | ||
| }; | ||
|
|
||
| const deployment = await this.deploymentApi.createDeployment(request); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(deployment), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| logger.info(`Deployment created with ID: ${deployment.id}, Status: ${deployment.status}`); | ||
| } | ||
| } | ||
|
|
||
| public async getDeployments(jsonResponse: boolean, packageKey?: string, targetId?: string, deployableType?: string, status?: string, createdBy?: string): Promise<void> { | ||
| const filter: GetDeploymentsRequest = { | ||
| packageKey, | ||
| targetId, | ||
| deployableType, | ||
| status: fromString(status), | ||
| createdBy | ||
| }; | ||
| const deployments = await this.deploymentApi.getDeployments(filter); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(deployments), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| deployments.forEach(deployment => { | ||
| logger.info(`ID: ${deployment.id}, Package: ${deployment.packageKey}, Version: ${deployment.packageVersion}, Status: ${deployment.status}, Created at: ${new Date(deployment.createdAt).toISOString()}`); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public async getActiveDeploymentForTarget(targetId: string, jsonResponse: boolean): Promise<void> { | ||
| const deployment = await this.deploymentApi.getActiveDeploymentForTarget(targetId); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(deployment), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| logger.info(`ID: ${deployment.id}, Package: ${deployment.packageKey}, Version: ${deployment.packageVersion}, Status: ${deployment.status}, Deployed at: ${new Date(deployment.deployedAt).toISOString()}`); | ||
| } | ||
| } | ||
|
|
||
| public async getActiveDeploymentsForPackage(packageKey: string, jsonResponse: boolean, targetIds?: string[], limit?: number, offset?:number): Promise<void> { | ||
| const deployments = await this.deploymentApi.getActiveDeploymentsForPackage(packageKey, targetIds, limit, offset); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(deployments), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| deployments.forEach(deployment => { | ||
| logger.info(`ID: ${deployment.id}, Package: ${deployment.packageKey}, Version: ${deployment.packageVersion}, Status: ${deployment.status}, Deployed at: ${deployment.deployedAt}`); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public async getTargets(jsonResponse: boolean, deployableType: string, packageKey?: string): Promise<void> { | ||
| const targets = await this.deploymentApi.getTargets(deployableType, packageKey); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(targets), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| targets.forEach(target => { | ||
| logger.info(`ID: ${target.id}, Name: ${target.name}`); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public async getDeployables(jsonResponse: boolean, flavor?: string): Promise<void> { | ||
| const deployables = await this.deploymentApi.getDeployables(flavor); | ||
|
|
||
| if (jsonResponse) { | ||
| const filename = uuidv4() + ".json"; | ||
| fileService.writeToFileWithGivenName(JSON.stringify(deployables), filename); | ||
| logger.info(FileService.fileDownloadedMessage + filename); | ||
| } else { | ||
| deployables.forEach(deployable => { | ||
| logger.info(`Name: ${deployable.name}, Type: ${deployable.type}`); | ||
| }); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.