Skip to content

Commit b5e41af

Browse files
Merge pull request #1 from PowershellFrameworkCollective/development
fixed repository handling
2 parents d3c7dd5 + 763281d commit b5e41af

4 files changed

Lines changed: 83 additions & 71 deletions

File tree

PSFramework.NuGet/PSFramework.NuGet.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'PSFramework.NuGet.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '0.9.0'
6+
ModuleVersion = '0.9.2'
77

88
# ID used to uniquely identify this module
99
GUID = 'ad0f2a25-552f-4dd6-bd8e-5ddced2a5d88'

PSFramework.NuGet/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.9.2 (2025-01-17)
4+
5+
+ Fix: Get-PSFRepository - writes error when searching for a specific repository that only exists in one PSGet version
6+
+ Fix: Update-PSFRepository - will update the "Trusted" status of a configured repository, even if the base properties have not yet been configured
7+
38
## 0.9.0 (2025-01-03)
49

510
+ Initial Preview Release

PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
}
4545
process {
4646
if ($script:psget.V3 -and $Type -in 'All','V3') {
47-
foreach ($repository in Get-PSResourceRepository -Name $Name) {
47+
foreach ($repository in Get-PSResourceRepository -Name $Name -ErrorAction Ignore) {
48+
if (-not $repository) { continue }
4849
[PSCustomObject]@{
4950
PSTypeName = 'PSFramework.NuGet.Repository'
5051
Name = $repository.Name
@@ -63,7 +64,8 @@
6364
if (-not $script:psget.v2CanPublish) { $status = 'NoPublish' }
6465
if (-not $script:psget.v2CanInstall) { $status = 'NoInstall' }
6566

66-
foreach ($repository in Get-PSRepository -Name $Name) {
67+
foreach ($repository in Get-PSRepository -Name $Name -ErrorAction Ignore) {
68+
if (-not $repository) { continue }
6769
[PSCustomObject]@{
6870
PSTypeName = 'PSFramework.NuGet.Repository'
6971
Name = $repository.Name

PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -54,88 +54,93 @@
5454
$supportedTypes = 'Any', 'Update', 'All', 'V2', 'V2Preferred', 'V3'
5555

5656
foreach ($configuredRepo in $Configured) {
57-
# Incomplete configurations are ignored (e.g. just storing credentials)
58-
if (-not $configuredRepo.Type -or -not $configuredRepo.Uri) { continue }
57+
# Incomplete configurations are processed in a limited manner, as not enough information is present to create or delete
58+
$isIncomplete = -not $configuredRepo.Type -or -not $configuredRepo.Uri
5959

60-
if ($configuredRepo.Type -notin $supportedTypes) {
60+
if (-not $isIncomplete -and $configuredRepo.Type -notin $supportedTypes) {
6161
Write-PSFMessage -Level Warning -String 'Update-PSFRepository.Error.InvalidType' -StringValues $configuredRepo.Type, ($supportedTypes -join ', ')
6262
continue
6363
}
6464

6565
$matching = $Actual | Where-Object Name -EQ $configuredRepo._Name
66-
$shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present)
66+
# An incomplete configuration can only be used to modify an existing repository, so skip if nothing matches
67+
if ($isIncomplete -and -not $matching) { continue }
6768

68-
$mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred'
69-
if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false }
70-
$mustBeV2 = $configuredRepo.Type -in 'All', 'V2'
71-
$mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred'
72-
if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false }
73-
$mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3'
69+
if (-not $isIncomplete) {
70+
$shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present)
7471

75-
# Case: Should not exist and does not
76-
if (-not $shouldExist -and -not $matching) {
77-
continue
78-
}
72+
$mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred'
73+
if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false }
74+
$mustBeV2 = $configuredRepo.Type -in 'All', 'V2'
75+
$mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred'
76+
if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false }
77+
$mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3'
7978

80-
#region Deletion
81-
foreach ($matchingRepo in $matching) {
82-
if (
83-
# Should exist
84-
$shouldExist -and
85-
(
86-
$matchingRepo.Type -eq 'V2' -and $mayBeV2 -or
87-
$matchingRepo.Type -eq 'V3' -and $mayBeV3
88-
)
89-
) {
79+
# Case: Should not exist and does not
80+
if (-not $shouldExist -and -not $matching) {
9081
continue
9182
}
9283

93-
[PSCustomObject]@{
94-
Type = 'Delete'
95-
Configured = $configuredRepo
96-
Actual = $matchingRepo
97-
Changes = @{ }
84+
#region Deletion
85+
foreach ($matchingRepo in $matching) {
86+
if (
87+
# Should exist
88+
$shouldExist -and
89+
(
90+
$matchingRepo.Type -eq 'V2' -and $mayBeV2 -or
91+
$matchingRepo.Type -eq 'V3' -and $mayBeV3
92+
)
93+
) {
94+
continue
95+
}
96+
97+
[PSCustomObject]@{
98+
Type = 'Delete'
99+
Configured = $configuredRepo
100+
Actual = $matchingRepo
101+
Changes = @{ }
102+
}
98103
}
99-
}
100-
if (-not $shouldExist) { continue }
101-
#endregion Deletion
104+
if (-not $shouldExist) { continue }
105+
#endregion Deletion
102106

103-
#region Creation
104-
# Case: Should exist but does not
105-
if ($shouldExist -and -not $matching) {
106-
[PSCustomObject]@{
107-
Type = 'Create'
108-
Configured = $configuredRepo
109-
Actual = $null
110-
Changes = @{ }
107+
#region Creation
108+
# Case: Should exist but does not
109+
if ($shouldExist -and -not $matching) {
110+
[PSCustomObject]@{
111+
Type = 'Create'
112+
Configured = $configuredRepo
113+
Actual = $null
114+
Changes = @{ }
115+
}
116+
continue
111117
}
112-
continue
113-
}
114118

115-
# Case: Must exist on V2 but does not
116-
if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) {
117-
[PSCustomObject]@{
118-
Type = 'Create'
119-
Configured = $configuredRepo
120-
Actual = $matching
121-
Changes = @{ }
119+
# Case: Must exist on V2 but does not
120+
if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) {
121+
[PSCustomObject]@{
122+
Type = 'Create'
123+
Configured = $configuredRepo
124+
Actual = $matching
125+
Changes = @{ }
126+
}
122127
}
123-
}
124128

125-
# Case: Must exist on V3 but does not
126-
if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) {
127-
[PSCustomObject]@{
128-
Type = 'Create'
129-
Configured = $configuredRepo
130-
Actual = $matching
131-
Changes = @{ }
129+
# Case: Must exist on V3 but does not
130+
if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) {
131+
[PSCustomObject]@{
132+
Type = 'Create'
133+
Configured = $configuredRepo
134+
Actual = $matching
135+
Changes = @{ }
136+
}
132137
}
138+
139+
# If there is no matching, existing repository, there is no need to update
140+
if (-not $matching) { continue }
141+
#endregion Creation
133142
}
134143

135-
# If there is no matching, existing repository, there is no need to update
136-
if (-not $matching) { continue }
137-
#endregion Creation
138-
139144
#region Update
140145
foreach ($matchingRepo in $matching) {
141146
$intendedUri = $configuredRepo.Uri
@@ -147,7 +152,7 @@
147152
if ($null -eq $trusted) { $trusted = $true }
148153

149154
$changes = @{ }
150-
if ($matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri }
155+
if (-not $isIncomplete -and $matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri }
151156
if ($matchingRepo.Trusted -ne $trusted) { $changes.Trusted = $trusted -as [bool] }
152157
if (
153158
$configuredRepo.Priority -and
@@ -208,10 +213,10 @@
208213
$uri = $Change.Configured.Uri -replace 'v3/index.json$', 'v2'
209214

210215
$param = @{
211-
Name = $Change.Configured._Name
212-
SourceLocation = $uri
216+
Name = $Change.Configured._Name
217+
SourceLocation = $uri
213218
PublishLocation = $uri
214-
ErrorAction = 'Stop'
219+
ErrorAction = 'Stop'
215220
}
216221
if ($trusted) { $param.InstallationPolicy = 'Trusted' }
217222
if ($Change.Configured.Proxy) { $param.Proxy = $Change.Configured.Proxy }
@@ -222,9 +227,9 @@
222227
}
223228
if ($registerV3) {
224229
$param = @{
225-
Name = $Change.Configured._Name
226-
Uri = $Change.Configured.Uri
227-
Trusted = $trusted
230+
Name = $Change.Configured._Name
231+
Uri = $Change.Configured.Uri
232+
Trusted = $trusted
228233
ErrorAction = 'Stop'
229234
}
230235
if ($null -ne $Change.Configured.Priority) {

0 commit comments

Comments
 (0)