Skip to content

Commit 4d9644d

Browse files
authored
fix(lambda): correct prompter url button for sam deploy sync build commands (#6081)
## Problem We have been using components from sync.ts, where all prompters created for other command still use samSyncUrl. ## Solution Use correct url link for respective command in all prompter button. --- License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent cdccfa2 commit 4d9644d

File tree

9 files changed

+45
-25
lines changed

9 files changed

+45
-25
lines changed

packages/core/src/awsService/appBuilder/explorer/openTemplate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { samSyncUrl } from '../../../shared/constants'
67
import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegistry'
78
import { syncMementoRootKey } from '../../../shared/sam/sync'
89

@@ -17,6 +18,6 @@ export interface OpenTemplateParams {
1718
export class OpenTemplateWizard extends Wizard<OpenTemplateParams> {
1819
public constructor(state: Partial<OpenTemplateParams>, registry: CloudFormationTemplateRegistry) {
1920
super({ initState: state, exitPrompterProvider: createExitPrompter })
20-
this.form.template.bindPrompter(() => createTemplatePrompter(registry, syncMementoRootKey))
21+
this.form.template.bindPrompter(() => createTemplatePrompter(registry, syncMementoRootKey, samSyncUrl))
2122
}
2223
}

packages/core/src/shared/sam/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ export class BuildWizard extends Wizard<BuildParams> {
129129
this.arg = arg
130130
if (this.arg === undefined) {
131131
// "Build" command was invoked on the command palette.
132-
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, buildMementoRootKey))
132+
this.form.template.bindPrompter(() =>
133+
createTemplatePrompter(this.registry, buildMementoRootKey, samBuildUrl)
134+
)
133135
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
134136
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
135137
const existValidSamConfig: boolean | undefined = await validateSamBuildConfig(projectRoot)

packages/core/src/shared/sam/deploy.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,22 @@ export class DeployWizard extends Wizard<DeployParams> {
112112
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
113113
}
114114
)
115-
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(), {
115+
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(samDeployUrl), {
116116
showWhen: ({ paramsSource }) =>
117117
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
118118
})
119119
this.form.bucketName.bindPrompter(
120-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey),
120+
({ region }) =>
121+
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
121122
{
122123
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
123124
}
124125
)
125126
} else if (this.arg && this.arg.regionCode) {
126127
// "Deploy" command was invoked on a regionNode.
127-
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, deployMementoRootKey))
128+
this.form.template.bindPrompter(() =>
129+
createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl)
130+
)
128131
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
129132
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
130133
const existValidSamConfig: boolean | undefined = await validateSamDeployConfig(projectRoot)
@@ -139,12 +142,13 @@ export class DeployWizard extends Wizard<DeployParams> {
139142
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
140143
}
141144
)
142-
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(), {
145+
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(samDeployUrl), {
143146
showWhen: ({ paramsSource }) =>
144147
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
145148
})
146149
this.form.bucketName.bindPrompter(
147-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey),
150+
({ region }) =>
151+
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
148152
{
149153
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
150154
}
@@ -173,20 +177,23 @@ export class DeployWizard extends Wizard<DeployParams> {
173177
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
174178
}
175179
)
176-
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(), {
180+
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(samDeployUrl), {
177181
showWhen: ({ paramsSource }) =>
178182
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
179183
})
180184
this.form.bucketName.bindPrompter(
181-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey),
185+
({ region }) =>
186+
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
182187
{
183188
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
184189
}
185190
)
186191
this.form.projectRoot.setDefault(() => getProjectRoot(templateItem))
187192
} else {
188193
// "Deploy" command was invoked on the command palette.
189-
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, deployMementoRootKey))
194+
this.form.template.bindPrompter(() =>
195+
createTemplatePrompter(this.registry, deployMementoRootKey, samDeployUrl)
196+
)
190197
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
191198
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
192199
const existValidSamConfig: boolean | undefined = await validateSamDeployConfig(projectRoot)
@@ -204,12 +211,13 @@ export class DeployWizard extends Wizard<DeployParams> {
204211
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
205212
}
206213
)
207-
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(), {
214+
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(samDeployUrl), {
208215
showWhen: ({ paramsSource }) =>
209216
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
210217
})
211218
this.form.bucketName.bindPrompter(
212-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey),
219+
({ region }) =>
220+
createBucketNamePrompter(new DefaultS3Client(region!), deployMementoRootKey, samDeployUrl),
213221
{
214222
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
215223
}

packages/core/src/shared/sam/sync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class SyncWizard extends Wizard<SyncParams> {
156156
) {
157157
super({ initState: state, exitPrompterProvider: shouldPromptExit ? createExitPrompter : undefined })
158158
this.registry = registry
159-
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, syncMementoRootKey))
159+
this.form.template.bindPrompter(() => createTemplatePrompter(this.registry, syncMementoRootKey, samSyncUrl))
160160
this.form.projectRoot.setDefault(({ template }) => getProjectRoot(template))
161161

162162
this.form.paramsSource.bindPrompter(async ({ projectRoot }) => {
@@ -175,13 +175,13 @@ export class SyncWizard extends Wizard<SyncParams> {
175175
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
176176
}
177177
)
178-
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(), {
178+
this.form.bucketSource.bindPrompter(() => createBucketSourcePrompter(samSyncUrl), {
179179
showWhen: ({ paramsSource }) =>
180180
paramsSource === ParamsSource.Specify || paramsSource === ParamsSource.SpecifyAndSave,
181181
})
182182

183183
this.form.bucketName.bindPrompter(
184-
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), syncMementoRootKey),
184+
({ region }) => createBucketNamePrompter(new DefaultS3Client(region!), syncMementoRootKey, samSyncUrl),
185185
{
186186
showWhen: ({ bucketSource }) => bucketSource === BucketSource.UserProvided,
187187
}

packages/core/src/shared/ui/sam/bucketPrompter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import { DefaultS3Client } from '../../clients/s3Client'
6-
import { samDeployUrl, samSyncUrl } from '../../constants'
76
import { createCommonButtons } from '../buttons'
87
import { createQuickPick, DataQuickPickItem } from '../pickerPrompter'
98
import type { SyncParams } from '../../sam/sync'
109
import * as nls from 'vscode-nls'
10+
import * as vscode from 'vscode'
1111
import { getRecentResponse } from '../../sam/utils'
1212

1313
const localize = nls.loadMessageBundle()
@@ -23,9 +23,10 @@ export enum BucketSource {
2323
* Provides two options:
2424
* 1. Create a SAM CLI managed bucket
2525
* 2. Specify an existing bucket
26+
* @param samCommandUrl URL to the SAM CLI command documentation
2627
* @returns A QuickPick prompter configured with bucket source options
2728
*/
28-
export function createBucketSourcePrompter() {
29+
export function createBucketSourcePrompter(samCommandUrl: vscode.Uri) {
2930
const items: DataQuickPickItem<BucketSource>[] = [
3031
{
3132
label: 'Create a SAM CLI managed S3 bucket',
@@ -40,7 +41,7 @@ export function createBucketSourcePrompter() {
4041
return createQuickPick(items, {
4142
title: 'Specify S3 bucket for deployment artifacts',
4243
placeholder: 'Press enter to proceed with highlighted option',
43-
buttons: createCommonButtons(samDeployUrl),
44+
buttons: createCommonButtons(samCommandUrl),
4445
})
4546
}
4647

@@ -49,9 +50,10 @@ export function createBucketSourcePrompter() {
4950
* The prompter supports choosing from existing s3 bucket name or creating a new one
5051
* @param client S3 client
5152
* @param mementoRootKey Memento key to store recent bucket name (e.g 'samcli.deploy.params')
53+
* @param samCommandUrl URL to the SAM CLI command documentation
5254
* @returns A quick pick prompter configured with bucket name options
5355
*/
54-
export function createBucketNamePrompter(client: DefaultS3Client, mementoRootKey: string) {
56+
export function createBucketNamePrompter(client: DefaultS3Client, mementoRootKey: string, samCommandUrl: vscode.Uri) {
5557
const recentBucket = getRecentResponse(mementoRootKey, client.regionCode, 'bucketName')
5658
const items = client.listBucketsIterable().map((b) => [
5759
{
@@ -64,7 +66,7 @@ export function createBucketNamePrompter(client: DefaultS3Client, mementoRootKey
6466
return createQuickPick(items, {
6567
title: 'Select an S3 Bucket',
6668
placeholder: 'Select a bucket (or enter a name to create one)',
67-
buttons: createCommonButtons(samSyncUrl),
69+
buttons: createCommonButtons(samCommandUrl),
6870
filterBoxInputSettings: {
6971
label: 'Create a New Bucket',
7072
// This is basically a hack. I need to refactor `createQuickPick` a bit.

packages/core/src/shared/ui/sam/templatePrompter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as path from 'path'
77
import * as vscode from 'vscode'
88
import { getSamInitDocUrl } from '../..'
99
import * as CloudFormation from '../../cloudformation/cloudformation'
10-
import { samSyncUrl } from '../../constants'
1110
import { CloudFormationTemplateRegistry } from '../../fs/templateRegistry'
1211
import { createCommonButtons } from '../buttons'
1312
import { createQuickPick } from '../pickerPrompter'
@@ -27,6 +26,7 @@ export interface TemplateItem {
2726
*
2827
* @param registry - Registry containing CloudFormation templates
2928
* @param mementoRootKey - Root key for storing recent template selections (e.g 'samcli.deploy.params')
29+
* @param samCommandUrl URL to the SAM CLI command documentation
3030
* @param projectRoot - Optional URI of the project root to filter templates
3131
* @returns A QuickPick prompter configured for template selection
3232
*
@@ -37,6 +37,7 @@ export interface TemplateItem {
3737
export function createTemplatePrompter(
3838
registry: CloudFormationTemplateRegistry,
3939
mementoRootKey: string,
40+
samCommandUrl: vscode.Uri,
4041
projectRoot?: vscode.Uri
4142
) {
4243
const folders = new Set<string>()
@@ -63,7 +64,7 @@ export function createTemplatePrompter(
6364
return createQuickPick(trimmedItems, {
6465
title: 'Select a SAM/CloudFormation Template',
6566
placeholder: 'Select a SAM/CloudFormation Template',
66-
buttons: createCommonButtons(samSyncUrl),
67+
buttons: createCommonButtons(samCommandUrl),
6768
noItemsFoundItem: {
6869
label: localize('aws.sam.noWorkspace', 'No SAM template.yaml file(s) found. Select for help'),
6970
data: undefined,

packages/core/src/test/shared/ui/sam/bucketPrompter.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as SamUtilsModule from '../../../../shared/sam/utils'
1111
import { createBucketNamePrompter } from '../../../../shared/ui/sam/bucketPrompter'
1212
import { AsyncCollection } from '../../../../shared/utilities/asyncCollection'
1313
import { RequiredProps } from '../../../../shared/utilities/tsUtils'
14+
import { samDeployUrl } from '../../../../shared/constants'
1415

1516
describe('createBucketNamePrompter', () => {
1617
let sandbox: sinon.SinonSandbox
@@ -39,7 +40,7 @@ describe('createBucketNamePrompter', () => {
3940
sandbox.stub(SamUtilsModule, 'getRecentResponse').returns(undefined) // Mock recent bucket
4041

4142
// Act
42-
const prompter = createBucketNamePrompter(s3Client, mementoRootKey)
43+
const prompter = createBucketNamePrompter(s3Client, mementoRootKey, samDeployUrl)
4344

4445
// Assert
4546
assert.ok(stub.calledOnce)
@@ -63,7 +64,7 @@ describe('createBucketNamePrompter', () => {
6364
sandbox.stub(SamUtilsModule, 'getRecentResponse').returns(undefined) // Mock recent bucket
6465

6566
// Act
66-
const prompter = createBucketNamePrompter(s3Client, mementoRootKey)
67+
const prompter = createBucketNamePrompter(s3Client, mementoRootKey, samDeployUrl)
6768

6869
// Assert
6970
assert.ok(stub.calledOnce)

packages/core/src/test/shared/ui/sam/templatePrompter.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { WatchedItem } from '../../../../shared/fs/watchedFiles'
1313
import * as SamUtilsModule from '../../../../shared/sam/utils'
1414
import { createTemplatePrompter } from '../../../../shared/ui/sam/templatePrompter'
1515
import { assertEqualPaths } from '../../../testUtil'
16+
import { samDeployUrl } from '../../../../shared/constants'
1617

1718
describe('createTemplatePrompter', () => {
1819
let registry: CloudFormationTemplateRegistry
@@ -41,7 +42,7 @@ describe('createTemplatePrompter', () => {
4142
const workspaceFolder = vscode.workspace.workspaceFolders?.[0]
4243
assert.ok(workspaceFolder)
4344

44-
const prompter = createTemplatePrompter(registry, mementoRootKey)
45+
const prompter = createTemplatePrompter(registry, mementoRootKey, samDeployUrl)
4546

4647
assert.strictEqual(prompter.quickPick.items.length, 2)
4748
assertEqualPaths(prompter.quickPick.items[0].label, '/path/to/template1.yaml')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "SAM: Fix prompter button URLs for build, deploy and sync commands"
4+
}

0 commit comments

Comments
 (0)