Skip to content

Commit 55edbea

Browse files
authored
Bugfix: Populate Includes Metadata for Package from Containerregistry Repository (#1861)
1 parent 6a8efee commit 55edbea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/code/PSResourceInfo.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,15 @@ public static bool TryConvertFromContainerRegistryJson(
10821082
{ "NormalizedVersion", metadata["NormalizedVersion"].ToString() }
10831083
};
10841084

1085+
ParseHttpMetadataType(metadata["Tags"] as string[], out ArrayList commandNames, out ArrayList cmdletNames, out ArrayList dscResourceNames);
1086+
var resourceHashtable = new Hashtable {
1087+
{ nameof(PSResourceInfo.Includes.Command), new PSObject(commandNames) },
1088+
{ nameof(PSResourceInfo.Includes.Cmdlet), new PSObject(cmdletNames) },
1089+
{ nameof(PSResourceInfo.Includes.DscResource), new PSObject(dscResourceNames) }
1090+
};
1091+
1092+
var includes = new ResourceIncludes(resourceHashtable);
1093+
10851094
psGetInfo = new PSResourceInfo(
10861095
additionalMetadata: additionalMetadataHashtable,
10871096
author: metadata["Authors"] as String,
@@ -1090,7 +1099,7 @@ public static bool TryConvertFromContainerRegistryJson(
10901099
dependencies: metadata["Dependencies"] as Dependency[],
10911100
description: metadata["Description"] as String,
10921101
iconUri: null,
1093-
includes: null,
1102+
includes: includes,
10941103
installedDate: null,
10951104
installedLocation: null,
10961105
isPrerelease: (bool)metadata["IsPrerelease"],
@@ -1709,6 +1718,12 @@ private static ResourceType ParseHttpMetadataType(
17091718
dscResourceNames = new ArrayList();
17101719

17111720
ResourceType pkgType = ResourceType.Module;
1721+
1722+
if (tags == null)
1723+
{
1724+
return pkgType;
1725+
}
1726+
17121727
foreach (string tag in tags)
17131728
{
17141729
if (String.Equals(tag, "PSScript", StringComparison.InvariantCultureIgnoreCase))

test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
1212
$testModuleParentName = "test_parent_mod"
1313
$testModuleDependencyName = "test_dependency_mod"
1414
$testScriptName = "test-script"
15+
$testModuleWithIncludes = "test-resourcewithincludes"
1516
$ACRRepoName = "ACRRepo"
1617
$ACRRepoUri = "https://psresourcegettest.azurecr.io"
1718
Get-NewPSResourceRepositoryFile
@@ -262,6 +263,14 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
262263
$res.ReleaseNotes.Length | Should -Not -Be 0
263264
$res.Tags.Length | Should -Be 5
264265
}
266+
267+
It "Should find resource and its associated Includes property" {
268+
$res = Find-PSResource $testModuleWithIncludes -Repository $ACRRepoName
269+
$res.Includes | Should -Not -BeNullOrEmpty
270+
$res.Includes.Cmdlet | Should -Be "cmdlet1"
271+
$res.Includes.Command | Should -Be "cmd1"
272+
$res.Includes.DscResource | Should -Be "dsc1"
273+
}
265274
}
266275

267276
Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' {

0 commit comments

Comments
 (0)