Skip to content

Commit

Permalink
refactor: add deploy url to json output
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Oct 14, 2024
1 parent 23bd739 commit b512688
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 13 deletions.
6 changes: 6 additions & 0 deletions schemas/project-deploy-cancel.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -574,6 +577,9 @@
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
},
"id": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions schemas/project-deploy-quick.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -580,6 +583,9 @@
"success": {
"type": "boolean"
},
"deployUrl": {
"type": "string"
},
"done": {
"type": "boolean"
}
Expand Down
6 changes: 6 additions & 0 deletions schemas/project-deploy-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -574,6 +577,9 @@
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
},
"id": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions schemas/project-deploy-resume.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -582,6 +585,9 @@
},
"done": {
"type": "boolean"
},
"deployUrl": {
"type": "string"
}
},
"required": ["files", "status"]
Expand Down
6 changes: 6 additions & 0 deletions schemas/project-deploy-start.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
},
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -574,6 +577,9 @@
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
},
"id": {
"type": "string"
},
Expand Down
6 changes: 6 additions & 0 deletions schemas/project-deploy-validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"errorStatusCode": {
"type": "string"
},
"deployUrl": {
"type": "string"
},
"ignoreWarnings": {
"type": "boolean"
},
Expand Down Expand Up @@ -574,6 +577,9 @@
"stateDetail": {
"type": "string"
},
"deployUrl": {
"type": "string"
},
"id": {
"type": "string"
},
Expand Down
16 changes: 12 additions & 4 deletions src/commands/project/deploy/quick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {

public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);

private deployUrl?: string;

public async run(): Promise<DeployResultJson> {
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataQuick), DeployCache.create()]);

Expand All @@ -91,13 +93,13 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
rest: api === API['REST'],
});
this.log(`Deploy ID: ${ansis.bold(deployId)}`);
const deployUrl = buildDeployUrl(deployId);
this.log(`Deploy URL: ${ansis.bold(deployUrl)}`);
this.deployUrl = buildDeployUrl(deployId);
this.log(`Deploy URL: ${ansis.bold(this.deployUrl)}`);

if (flags.async) {
const asyncFormatter = new AsyncDeployResultFormatter(deployId);
if (!this.jsonEnabled()) asyncFormatter.display();
return asyncFormatter.getJson();
return this.mixinUrlMeta(await asyncFormatter.getJson());
}

const mdapiDeploy = new MetadataApiDeploy({
Expand Down Expand Up @@ -125,7 +127,7 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
this.log(messages.getMessage('error.QuickDeployFailure', [deployId, result.response.status]));
}

return formatter.getJson();
return this.mixinUrlMeta(await formatter.getJson());
}

protected catch(error: SfCommand.Error): Promise<never> {
Expand All @@ -140,6 +142,12 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
}
return super.catch(error);
}
private mixinUrlMeta(json: DeployResultJson): DeployResultJson {
if (this.deployUrl) {
json.deployUrl = this.deployUrl;
}
return json;
}
}

/** Resolve a job ID for a validated deploy using cache, most recent, or a job ID flag. */
Expand Down
14 changes: 11 additions & 3 deletions src/commands/project/deploy/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {

public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);

private deployUrl?: string;

public async run(): Promise<DeployResultJson> {
const [{ flags }, cache] = await Promise.all([this.parse(DeployMetadataResume), DeployCache.create()]);
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id'], true);
Expand Down Expand Up @@ -131,8 +133,8 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
);

this.log(`Deploy ID: ${ansis.bold(jobId)}`);
const deployUrl = buildDeployUrl(jobId);
this.log(`Deploy URL: ${ansis.bold(deployUrl)}`);
this.deployUrl = buildDeployUrl(jobId);
this.log(`Deploy URL: ${ansis.bold(this.deployUrl)}`);
new DeployProgress(deploy, this.jsonEnabled()).start();
result = await deploy.pollStatus(500, wait.seconds);

Expand All @@ -154,6 +156,12 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {

if (!this.jsonEnabled()) formatter.display();

return formatter.getJson();
return this.mixinUrlMeta(await formatter.getJson());
}
private mixinUrlMeta(json: DeployResultJson): DeployResultJson {
if (this.deployUrl) {
json.deployUrl = this.deployUrl;
}
return json;
}
}
8 changes: 6 additions & 2 deletions src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {

private zipSize?: number;
private zipFileCount?: number;
private deployUrl?: string;

public async run(): Promise<DeployResultJson> {
const { flags } = await this.parse(DeployMetadata);
Expand Down Expand Up @@ -246,8 +247,8 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
throw new SfError('The deploy id is not available.');
}
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);
const deployUrl = buildDeployUrl(deploy.id);
this.log(`Deploy URL: ${ansis.bold(deployUrl)}`);
this.deployUrl = buildDeployUrl(deploy.id);
this.log(`Deploy URL: ${ansis.bold(this.deployUrl)}`);

if (flags.async) {
if (flags['coverage-formatters']) {
Expand Down Expand Up @@ -306,6 +307,9 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
if (this.zipFileCount) {
json.zipFileCount = this.zipFileCount;
}
if (this.deployUrl) {
json.deployUrl = this.deployUrl;
}
return json;
}
}
16 changes: 12 additions & 4 deletions src/commands/project/deploy/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>

public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);

private deployUrl?: string;

public async run(): Promise<DeployResultJson> {
const [{ flags }, api] = await Promise.all([this.parse(DeployMetadataValidate), resolveApi(this.configAggregator)]);

Expand Down Expand Up @@ -196,13 +198,13 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
throw new SfError('The deploy id is not available.');
}
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);
const deployUrl = buildDeployUrl(deploy.id);
this.log(`Deploy URL: ${ansis.bold(deployUrl)}`);
this.deployUrl = buildDeployUrl(deploy.id);
this.log(`Deploy URL: ${ansis.bold(this.deployUrl)}`);

if (flags.async) {
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
if (!this.jsonEnabled()) asyncFormatter.display();
return asyncFormatter.getJson();
return this.mixinUrlMeta(await asyncFormatter.getJson());
}

new DeployProgress(deploy, this.jsonEnabled()).start();
Expand Down Expand Up @@ -252,6 +254,12 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
.setData({ deployId: deploy.id });
}

return formatter.getJson();
return this.mixinUrlMeta(await formatter.getJson());
}
private mixinUrlMeta(json: DeployResultJson): DeployResultJson {
if (this.deployUrl) {
json.deployUrl = this.deployUrl;
}
return json;
}
}
2 changes: 2 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type AsyncDeployResultJson = Omit<Partial<MetadataApiDeployStatus>, 'stat
files: FileResponse[];
zipSize?: number;
zipFileCount?: number;
deployUrl?: string;
};

type ConvertEntry = {
Expand Down Expand Up @@ -79,6 +80,7 @@ export type DeployResultJson =
replacements?: Record<string, string[]>;
zipSize?: number;
zipFileCount?: number;
deployUrl?: string;
})
| AsyncDeployResultJson;

Expand Down

0 comments on commit b512688

Please sign in to comment.