33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { QuickPickItem } from "vscode" ;
7- import { loadMoreQp , QuickPicksCache } from "../../../../constants" ;
6+ import type { QuickPickItem } from "vscode" ;
7+ import { currentlyDeployed , dockerHubDomain , loadMoreQp , QuickPicksCache , quickStartImageName } from "../../../../constants" ;
8+ import { parseImageName } from "../../../../utils/imageNameUtils" ;
89import { localize } from "../../../../utils/localize" ;
910import { nonNullProp } from "../../../../utils/nonNull" ;
11+ import { getLatestContainerAppImage } from "../getLatestContainerImage" ;
1012import { IContainerRegistryImageContext } from "../IContainerRegistryImageContext" ;
1113import { RegistryRepositoriesListStepBase } from "../RegistryRepositoriesListBaseStep" ;
1214import { getReposForNamespace } from "./DockerHubV2ApiCalls" ;
15+ import type { DockerHubV2Repository } from "./DockerHubV2Types" ;
1316
1417export class DockerHubContainerRepositoryListStep extends RegistryRepositoriesListStepBase {
1518 public async getPicks ( context : IContainerRegistryImageContext , cachedPicks : QuickPicksCache ) : Promise < QuickPickItem [ ] > {
@@ -19,7 +22,33 @@ export class DockerHubContainerRepositoryListStep extends RegistryRepositoriesLi
1922 await context . ui . showWarningMessage ( localize ( 'noRepos' , 'Unable to find any repositories associated to namespace "{0}"' , context . dockerHubNamespace ) , { modal : true } ) ;
2023 }
2124
22- cachedPicks . cache . push ( ...response . results . map ( ( r ) => { return { label : r . name , description : r . description } } ) ) ;
25+ // Try to suggest a repository only when the user is deploying to a Container App
26+ let suggestedRepository : string | undefined ;
27+ let srExists : boolean = false ;
28+ if ( context . targetContainer ) {
29+ const { registryDomain, repositoryName, imageNameReference } = parseImageName ( getLatestContainerAppImage ( context . targetContainer ) ) ;
30+
31+ // If the image is not the default quickstart image, then we can try to suggest a repository based on the latest Container App image
32+ if ( registryDomain === dockerHubDomain && imageNameReference !== quickStartImageName ) {
33+ suggestedRepository = repositoryName ;
34+ }
35+
36+ // Does the suggested repositoryName exist in the list of pulled repositories? If so, move it to the front of the list
37+ const srIndex : number = response . results . findIndex ( ( r ) => ! ! suggestedRepository && r . name === suggestedRepository ) ;
38+ srExists = srIndex !== - 1 ;
39+ if ( srExists ) {
40+ const sr : DockerHubV2Repository = response . results . splice ( srIndex , 1 ) [ 0 ] ;
41+ response . results . unshift ( sr ) ;
42+ }
43+ }
44+
45+ // Preferring 'suppressPersistence: true' over 'priority: highest' to avoid the possibility of a double parenthesis appearing in the description
46+ const quickPicks : QuickPickItem [ ] = response . results . map ( ( r ) => {
47+ return ! ! suggestedRepository && r . name === suggestedRepository ?
48+ { label : r . name , description : r . description ? `${ r . description } ${ currentlyDeployed } ` : currentlyDeployed , suppressPersistence : true } :
49+ { label : r . name , description : r . description , suppressPersistence : srExists }
50+ } ) ;
51+ cachedPicks . cache . push ( ...quickPicks ) ;
2352
2453 if ( response . next ) {
2554 cachedPicks . next = response . next ;
0 commit comments