Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/classes/public/Repositories/GitHubCustomProperty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ class GitHubCustomProperty {
# The name of the custom property.
[string] $Name

# The value of the custom property.
[string] $Value
# The value of the custom property. Can be a string or an array of strings for multi-select properties.
[object] $Value

GitHubCustomProperty() {}

GitHubCustomProperty([PSCustomObject] $Object) {
$this.Name = $Object.property_name ?? $Object.propertyName ?? $Object.Name
$this.Value = $Object.value ?? $Object.Value
$rawValue = $Object.value ?? $Object.Value
if ($rawValue -is [System.Collections.IEnumerable] -and $rawValue -isnot [string]) {
$this.Value = [string[]]$rawValue
} else {
$this.Value = $rawValue
}
Comment thread
MariusStorhaug marked this conversation as resolved.
Comment on lines 10 to +17
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor now branches on whether value is an IEnumerable (excluding string) to preserve multi-select values as arrays, but this behavior isn't covered by a deterministic unit test in tests/. Add a small Pester test that constructs GitHubCustomProperty from a [pscustomobject]@{ property_name = 'X'; value = @('a','b') } and from a scalar string, and asserts the resulting .Value type (and propertyName alias resolution).

Copilot uses AI. Check for mistakes.
}

[string] ToString() {
Expand Down
2 changes: 1 addition & 1 deletion tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Describe 'GitHub' {
$stamps.Count | Should -BeGreaterThan 0
}
It 'Get-GitHubStamp - Each stamp has Name and BaseUrl properties' {
LogGroup "Stamps - Details" {
LogGroup 'Stamps - Details' {
Comment on lines 295 to +296
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description (and prior review thread) mention adding focused unit tests for GitHubCustomProperty array vs scalar handling (and GraphQL-style propertyName), but there are no such tests in the current tests/ tree. Please add the mentioned unit tests (or update the PR description to match what actually changed) so this behavior is covered deterministically.

Copilot uses AI. Check for mistakes.
Get-GitHubStamp | ForEach-Object {
Write-Host ($_ | Format-List | Out-String)
$_.Name | Should -Not -BeNullOrEmpty
Expand Down
16 changes: 16 additions & 0 deletions tests/Repositories.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,22 @@ Describe 'Repositories' {
}
$repos.Count | Should -BeGreaterThan 0
}
It 'Get-GitHubRepositoryCustomProperty - Gets custom properties and preserves value types' -Skip:($OwnerType -ne 'organization') {
LogGroup 'Custom Properties' {
$properties = Get-GitHubRepositoryCustomProperty -Owner $owner -Repository $repoName
Write-Host ($properties | Format-List | Out-String)
}
if ($properties) {
foreach ($prop in $properties) {
$prop.Name | Should -Not -BeNullOrEmpty
if ($prop.Value -is [System.Collections.IEnumerable] -and $prop.Value -isnot [string]) {
$prop.Value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($prop.Value.GetType().FullName)"
} else {
$prop.Value | Should -BeOfType [string]
Comment on lines +528 to +532
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get-GitHubRepositoryCustomProperty returns raw REST objects (from ConvertFrom-Json) with fields like property_name and value. This test asserts $prop.Name, which likely doesn't exist (and will be $null), causing a false failure. Consider asserting $prop.property_name instead, or explicitly converting each item to [GitHubCustomProperty] before validating Name/Value.

Suggested change
$prop.Name | Should -Not -BeNullOrEmpty
if ($prop.Value -is [System.Collections.IEnumerable] -and $prop.Value -isnot [string]) {
$prop.Value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($prop.Value.GetType().FullName)"
} else {
$prop.Value | Should -BeOfType [string]
$prop.property_name | Should -Not -BeNullOrEmpty
if ($prop.value -is [System.Collections.IEnumerable] -and $prop.value -isnot [string]) {
$prop.value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($prop.value.GetType().FullName)"
} else {
$prop.value | Should -BeOfType [string]

Copilot uses AI. Check for mistakes.
}
Comment on lines +521 to +533
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can pass without validating the new behavior: if $properties is empty, there are no assertions, and if all values are scalar strings the array-preservation path is never exercised. To reliably catch regressions, add a deterministic unit test around GitHubCustomProperty([PSCustomObject]) (mocking an array vs scalar value) or otherwise ensure the test repo contains at least one multi-select property and assert it is a [string[]].

Suggested change
It 'Get-GitHubRepositoryCustomProperty - Gets custom properties and preserves value types' -Skip:($OwnerType -ne 'organization') {
LogGroup 'Custom Properties' {
$properties = Get-GitHubRepositoryCustomProperty -Owner $owner -Repository $repoName
Write-Host ($properties | Format-List | Out-String)
}
if ($properties) {
foreach ($prop in $properties) {
$prop.Name | Should -Not -BeNullOrEmpty
if ($prop.Value -is [System.Collections.IEnumerable] -and $prop.Value -isnot [string]) {
$prop.Value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($prop.Value.GetType().FullName)"
} else {
$prop.Value | Should -BeOfType [string]
}
It 'GitHubCustomProperty - Preserves scalar and multi-select value types' {
$scalarProperty = [GitHubCustomProperty]::new([PSCustomObject]@{
name = 'Environment'
value = 'Production'
})
$arrayProperty = [GitHubCustomProperty]::new([PSCustomObject]@{
name = 'Regions'
value = @('eu-west-1', 'us-east-1')
})
$scalarProperty.Name | Should -Be 'Environment'
$scalarProperty.Value | Should -BeOfType [string]
$scalarProperty.Value | Should -Be 'Production'
$arrayProperty.Name | Should -Be 'Regions'
$arrayProperty.Value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($arrayProperty.Value.GetType().FullName)"
$arrayProperty.Value | Should -Be @('eu-west-1', 'us-east-1')
}
It 'Get-GitHubRepositoryCustomProperty - Gets custom properties and preserves value types' -Skip:($OwnerType -ne 'organization') {
LogGroup 'Custom Properties' {
$properties = Get-GitHubRepositoryCustomProperty -Owner $owner -Repository $repoName
Write-Host ($properties | Format-List | Out-String)
}
$properties | Should -Not -BeNullOrEmpty
foreach ($prop in $properties) {
$prop.Name | Should -Not -BeNullOrEmpty
if ($prop.Value -is [System.Collections.IEnumerable] -and $prop.Value -isnot [string]) {
$prop.Value -is [string[]] | Should -BeTrue -Because "multi-select values must be preserved as string arrays, got: $($prop.Value.GetType().FullName)"
} else {
$prop.Value | Should -BeOfType [string]

Copilot uses AI. Check for mistakes.
}
}
}
It 'Set-GitHubRepository - Updates an existing repository' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$description = 'Updated description'
LogGroup 'Repository - Set update' {
Expand Down
Loading