-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAcrRepositoriesListStep.ts
More file actions
45 lines (40 loc) · 2.84 KB
/
AcrRepositoriesListStep.ts
File metadata and controls
45 lines (40 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { QuickPickItem } from "vscode";
import { acrDomain, currentlyDeployed, quickStartImageName } from "../../../../constants";
import type { ContainerAppModel } from "../../../../tree/ContainerAppItem";
import { createContainerRegistryClient } from "../../../../utils/azureClients";
import { parseImageName } from "../../../../utils/imageNameUtils";
import { nonNullProp, nonNullValue } from "../../../../utils/nonNull";
import { IContainerRegistryImageContext } from "../IContainerRegistryImageContext";
import { RegistryRepositoriesListStepBase } from "../RegistryRepositoriesListBaseStep";
import { getLatestContainerAppImage } from "../getLatestContainerImage";
export class AcrRepositoriesListStep extends RegistryRepositoriesListStepBase {
public async getPicks(context: IContainerRegistryImageContext): Promise<QuickPickItem[]> {
const client = createContainerRegistryClient(context, nonNullValue(context.registry));
const repositoryNames: string[] = await uiUtils.listAllIterator(client.listRepositoryNames());
const containerApp: ContainerAppModel = nonNullProp(context, 'targetContainer');
const { registryDomain, repositoryName, imageNameReference } = parseImageName(getLatestContainerAppImage(containerApp));
// If the image is not the default quickstart image, then we can try to suggest a repository based on the latest Container App image
let suggestedRepository: string | undefined;
if (registryDomain === acrDomain && imageNameReference !== quickStartImageName) {
suggestedRepository = repositoryName;
}
// Does the suggested repositoryName exist in the list of pulled repositories? If so, move it to the front of the list
const srIndex: number = repositoryNames.findIndex((rn) => !!suggestedRepository && rn === suggestedRepository);
const srExists: boolean = srIndex !== -1;
if (srExists) {
const sr: string = repositoryNames.splice(srIndex, 1)[0];
repositoryNames.unshift(sr);
}
// Preferring 'suppressPersistence: true' over 'priority: highest' to avoid the possibility of a double parenthesis appearing in the description
return repositoryNames.map((rn) => {
return !!suggestedRepository && rn === suggestedRepository ?
{ label: rn, description: currentlyDeployed, suppressPersistence: true } :
{ label: rn, suppressPersistence: srExists };
});
}
}