-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDockerHubContainerRepositoryListStep.ts
More file actions
60 lines (51 loc) · 3.52 KB
/
DockerHubContainerRepositoryListStep.ts
File metadata and controls
60 lines (51 loc) · 3.52 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { QuickPickItem } from "vscode";
import { currentlyDeployed, dockerHubDomain, loadMoreQp, QuickPicksCache, quickStartImageName } from "../../../../constants";
import { parseImageName } from "../../../../utils/imageNameUtils";
import { localize } from "../../../../utils/localize";
import { nonNullProp } from "../../../../utils/nonNull";
import { getLatestContainerAppImage } from "../getLatestContainerImage";
import { IContainerRegistryImageContext } from "../IContainerRegistryImageContext";
import { RegistryRepositoriesListStepBase } from "../RegistryRepositoriesListBaseStep";
import { getReposForNamespace } from "./DockerHubV2ApiCalls";
import type { DockerHubV2Repository } from "./DockerHubV2Types";
export class DockerHubContainerRepositoryListStep extends RegistryRepositoriesListStepBase {
public async getPicks(context: IContainerRegistryImageContext, cachedPicks: QuickPicksCache): Promise<QuickPickItem[]> {
const response = await getReposForNamespace(context, nonNullProp(context, 'dockerHubNamespace'), cachedPicks.next);
if (response.count === 0) {
await context.ui.showWarningMessage(localize('noRepos', 'Unable to find any repositories associated to namespace "{0}"', context.dockerHubNamespace), { modal: true });
}
// Try to suggest a repository only when the user is deploying to a Container App
let suggestedRepository: string | undefined;
let srExists: boolean = false;
if (context.targetContainer) {
const { registryDomain, repositoryName, imageNameReference } = parseImageName(getLatestContainerAppImage(context.targetContainer));
// If the image is not the default quickstart image, then we can try to suggest a repository based on the latest Container App image
if (registryDomain === dockerHubDomain && 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 = response.results.findIndex((r) => !!suggestedRepository && r.name === suggestedRepository);
srExists = srIndex !== -1;
if (srExists) {
const sr: DockerHubV2Repository = response.results.splice(srIndex, 1)[0];
response.results.unshift(sr);
}
}
// Preferring 'suppressPersistence: true' over 'priority: highest' to avoid the possibility of a double parenthesis appearing in the description
const quickPicks: QuickPickItem[] = response.results.map((r) => {
return !!suggestedRepository && r.name === suggestedRepository ?
{ label: r.name, description: r.description ? `${r.description} ${currentlyDeployed}` : currentlyDeployed, suppressPersistence: true } :
{ label: r.name, description: r.description, suppressPersistence: srExists }
});
cachedPicks.cache.push(...quickPicks);
if (response.next) {
cachedPicks.next = response.next;
return cachedPicks.cache.concat(loadMoreQp);
}
return cachedPicks.cache;
}
}