Skip to content

Commit 5bbc102

Browse files
authored
Phale/w 9749255 (#222)
* fix: prevent expired or from being used in interactive mode @W-9749255@ * chore: use env from core * chore: improve question set around expired org * chore: update yarn.lock
1 parent 4244696 commit 5bbc102

File tree

6 files changed

+408
-313
lines changed

6 files changed

+408
-313
lines changed

messages/deploy.metadata.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,19 @@ All child components are included. If you specify this flag, don’t specify --m
108108

109109
Deploying to %s using %s API.
110110

111+
# save.as.default
112+
113+
Save %s as default target-org?
114+
111115
# errors.NoOrgsToSelect
112116

113117
Can't find any active scratch orgs, Dev Hubs, or other orgs.
114118
Either log into an org or create a scratch org, and then try again.
119+
120+
# error.UserTerminatedDeployForExpiredOrg
121+
122+
The target-org found in the configuration is expired. The user terminated the deploy.
123+
124+
# warning.TargetOrgIsExpired
125+
126+
The target-org, "%s", is expired. Do you want to pick another org?

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"eslint-config-salesforce-license": "^0.1.6",
3838
"eslint-config-salesforce-typescript": "^0.2.8",
3939
"eslint-plugin-header": "^3.1.1",
40-
"eslint-plugin-import": "2.24.2",
40+
"eslint-plugin-import": "2.25.4",
4141
"eslint-plugin-jsdoc": "^35.5.1",
4242
"eslint-plugin-prettier": "^3.4.1",
4343
"husky": "^7.0.4",
@@ -48,7 +48,7 @@
4848
"prettier": "^2.5.1",
4949
"pretty-quick": "^3.1.3",
5050
"shx": "0.3.4",
51-
"sinon": "11.1.1",
51+
"sinon": "11.1.2",
5252
"ts-node": "^10.7.0",
5353
"typescript": "^4.6.2"
5454
},

src/commands/deploy/metadata.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export default class DeployMetadata extends SfCommand<DeployMetadataResult> {
9292
'ENVIRONMENT VARIABLES',
9393
EnvironmentVariable.SF_TARGET_ORG,
9494
EnvironmentVariable.SFDX_DEFAULTUSERNAME,
95-
EnvironmentVariable.SFDX_USE_PROGRESS_BAR
95+
EnvironmentVariable.SFDX_USE_PROGRESS_BAR,
96+
EnvironmentVariable.SF_USE_PROGRESS_BAR
9697
);
9798

9899
public async run(): Promise<DeployMetadataResult> {

src/utils/metadataDeployer.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { EOL } from 'os';
9-
import { cyan } from 'chalk';
9+
import { cyan, red } from 'chalk';
1010
import { Duration } from '@salesforce/kit';
1111
import {
1212
AuthInfo,
@@ -142,7 +142,32 @@ export class MetadataDeployer extends Deployer {
142142
const aliasOrUsername = ConfigAggregator.getValue(OrgConfigProperties.TARGET_ORG)?.value as string;
143143
const globalInfo = await GlobalInfo.getInstance();
144144
const allAliases = globalInfo.aliases.getAll();
145-
if (!aliasOrUsername) {
145+
let targetOrgAuth: OrgAuthorization;
146+
// make sure the "target-org" can be used in this deploy
147+
if (aliasOrUsername) {
148+
targetOrgAuth = (
149+
await AuthInfo.listAllAuthorizations(
150+
(a) => a.username === aliasOrUsername || a.aliases.some((alias) => alias === aliasOrUsername)
151+
)
152+
).find((a) => a);
153+
if (targetOrgAuth) {
154+
if (targetOrgAuth?.isExpired) {
155+
const continueAnswer = await this.prompt<{ continue: boolean }>([
156+
{
157+
name: 'continue',
158+
type: 'confirm',
159+
message: red(messages.getMessage('warning.TargetOrgIsExpired', [aliasOrUsername])),
160+
},
161+
]);
162+
if (!continueAnswer.continue) {
163+
throw messages.createError('error.UserTerminatedDeployForExpiredOrg');
164+
}
165+
} else {
166+
return globalInfo.aliases.resolveUsername(aliasOrUsername);
167+
}
168+
}
169+
}
170+
if (!aliasOrUsername || targetOrgAuth?.isExpired) {
146171
const authorizations = (
147172
await AuthInfo.listAllAuthorizations((orgAuth) => !orgAuth.error && orgAuth.isExpired !== true)
148173
).map((orgAuth) => {
@@ -170,12 +195,23 @@ export class MetadataDeployer extends Deployer {
170195
choices: generateTableChoices(columns, options, false),
171196
},
172197
]);
198+
if (targetOrgAuth?.isExpired) {
199+
const setTargetOrg = await this.prompt<{ save: boolean }>([
200+
{
201+
name: 'save',
202+
type: 'confirm',
203+
message: messages.getMessage('save.as.default', [username]),
204+
},
205+
]);
206+
if (setTargetOrg.save) {
207+
const authInfo = await AuthInfo.create({ username });
208+
await authInfo.setAsDefault({ org: true });
209+
}
210+
}
173211
return username;
174212
} else {
175213
throw messages.createError('errors.NoOrgsToSelect');
176214
}
177-
} else {
178-
return globalInfo.aliases.resolveUsername(aliasOrUsername);
179215
}
180216
}
181217

src/utils/progressBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { env } from '@salesforce/kit';
8+
import { envVars as env, EnvironmentVariable } from '@salesforce/core';
99
import { MetadataApiDeploy } from '@sf/sdr';
1010
import { Messages } from '@salesforce/core';
1111
import { Progress } from '@salesforce/sf-plugins-core';
@@ -23,7 +23,7 @@ export class DeployProgress extends Progress {
2323
};
2424

2525
public constructor(private deploy: MetadataApiDeploy, jsonEnabled = false) {
26-
super(!jsonEnabled && env.getBoolean('SF_USE_PROGRESS_BAR', true));
26+
super(!jsonEnabled && env.getBoolean(EnvironmentVariable.SF_USE_PROGRESS_BAR, true));
2727
}
2828

2929
public start(): void {

0 commit comments

Comments
 (0)