Skip to content
Draft
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
}
}

[string] ToString() {
Expand Down
37 changes: 37 additions & 0 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,43 @@
[CmdletBinding()]
param()

Describe 'GitHubCustomProperty' {
It 'Preserves array value for multi-select properties' {
$obj = [PSCustomObject]@{
property_name = 'SubscribeTo'
value = @('Custom Instructions', 'License', 'Prompts')
}
$prop = [GitHubCustomProperty]::new($obj)
$prop.Name | Should -Be 'SubscribeTo'
$prop.Value | Should -BeOfType [string]
$prop.Value | Should -HaveCount 3
$prop.Value[0] | Should -Be 'Custom Instructions'
$prop.Value[1] | Should -Be 'License'
$prop.Value[2] | Should -Be 'Prompts'
}

It 'Keeps scalar string value as string' {
$obj = [PSCustomObject]@{
property_name = 'Type'
value = 'Module'
}
$prop = [GitHubCustomProperty]::new($obj)
$prop.Name | Should -Be 'Type'
$prop.Value | Should -Be 'Module'
$prop.Value | Should -BeOfType [string]
}

It 'Handles GraphQL-style property names' {
$obj = [PSCustomObject]@{
propertyName = 'Environment'
value = 'production'
}
$prop = [GitHubCustomProperty]::new($obj)
$prop.Name | Should -Be 'Environment'
$prop.Value | Should -Be 'production'
}
}

Describe 'Auth' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Expand Down
Loading