Skip to content

Commit

Permalink
Update ConvertTo-JiraCreateMetaField.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmbaker authored Oct 9, 2023
1 parent 25713a0 commit 873c3a7
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,41 @@ function ConvertTo-JiraCreateMetaField {
)

process {
foreach ($i in $InputObject) {
foreach ($i in $InputObject.values) {
Write-Debug "[$($MyInvocation.MyCommand.Name)] Converting `$InputObject to custom object"

$fields = $i.projects.issuetypes.fields
$fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name
foreach ($f in $fieldNames) {
$item = $fields.$f

$props = @{
'Id' = $f
'Name' = $item.name
'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue)
'Required' = [System.Convert]::ToBoolean($item.required)
'Schema' = $item.schema
'Operations' = $item.operations
}
$item = $i

if ($item.allowedValues) {
$props.AllowedValues = $item.allowedValues
}
$props = @{
'Id' = $item.fieldId
'Name' = $item.name
'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue)
'Required' = [System.Convert]::ToBoolean($item.required)
'Schema' = $item.schema
'Operations' = $item.operations
}

if ($item.autoCompleteUrl) {
$props.AutoCompleteUrl = $item.autoCompleteUrl
}
if ($item.allowedValues) {
$props.AllowedValues = $item.allowedValues
}

foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) {
if ($null -eq $props.$extraProperty) {
$props.$extraProperty = $item.$extraProperty
}
}
if ($item.autoCompleteUrl) {
$props.AutoCompleteUrl = $item.autoCompleteUrl
}

$result = New-Object -TypeName PSObject -Property $props
$result.PSObject.TypeNames.Insert(0, 'JiraPS.CreateMetaField')
$result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value {
Write-Output "$($this.Name)"
foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) {
if ($null -eq $props.$extraProperty) {
$props.$extraProperty = $item.$extraProperty
}
}

Write-Output $result
$result = New-Object -TypeName PSObject -Property $props
$result.PSObject.TypeNames.Insert(0, 'JiraPS.CreateMetaField')
$result | Add-Member -MemberType ScriptMethod -Name "ToString" -Force -Value {
Write-Output "$($this.Name)"
}

Write-Output $result
}
}
}

0 comments on commit 873c3a7

Please sign in to comment.