From bd533518c97b5c7fb0a5ad6057a6df1a28751f48 Mon Sep 17 00:00:00 2001 From: hmmwhatsthisdo <2093321+hmmwhatsthisdo@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:02:27 -0700 Subject: [PATCH 1/4] Conditionalize CreateMeta URL by Jira version --- JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 index 54e9c82e..84e7b01d 100644 --- a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 @@ -22,7 +22,16 @@ function Get-JiraIssueCreateMetadata { $server = Get-JiraConfigServer -ErrorAction Stop - $resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields" + $JiraVersion = Get-JiraServerInfo -ErrorAction Stop + + # Beginning with Jira 9, the old instance-level CreateMeta endpoint is no longer available. + # Instead, CreateMeta is inherently scoped to project and issue type. + If ($JiraVersion.Version -gt [System.version](9.0.0)) { + $resourceURi = "$server/rest/api/2/issue/createmeta/{0}/issuetypes/{1}" + } Else { + $resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields" + } + } process { From b0593a368aeb62e4aefe375656edff82af73c72b Mon Sep 17 00:00:00 2001 From: hmmwhatsthisdo <2093321+hmmwhatsthisdo@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:09:22 -0700 Subject: [PATCH 2/4] Initial pass at Jira 9 createmeta output handling --- .../Private/ConvertTo-JiraCreateMetaField.ps1 | 113 +++++++++++++----- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 index 4db39833..b8fa7a0c 100644 --- a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 +++ b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 @@ -10,42 +10,99 @@ function ConvertTo-JiraCreateMetaField { foreach ($i in $InputObject) { 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 - } - if ($item.allowedValues) { - $props.AllowedValues = $item.allowedValues - } + $fieldList = $null - if ($item.autoCompleteUrl) { - $props.AutoCompleteUrl = $item.autoCompleteUrl - } + If ($null -ne $i.values) { + $fieldList = $i.values + } + Elseif ($null -ne $i.projects.issuetypes.fields) { + + } + Else { + Write-Error -Exception ([System.ArgumentException]::new("Input data does not match a known CreateMeta payload.", "InputObject")) + } + + if ($null -ne $i.values) { + + $i.values | ForEach-Object { + $item = $_ - foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) { - if ($null -eq $props.$extraProperty) { - $props.$extraProperty = $item.$extraProperty + $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.allowedValues) { + $props.AllowedValues = $item.allowedValues + } + + if ($item.autoCompleteUrl) { + $props.AutoCompleteUrl = $item.autoCompleteUrl + } + + foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) { + if ($null -eq $props.$extraProperty) { + $props.$extraProperty = $item.$extraProperty + } + } + + $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)" } - } - $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 } - Write-Output $result } + else { + + $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 + } + + if ($item.allowedValues) { + $props.AllowedValues = $item.allowedValues + } + + if ($item.autoCompleteUrl) { + $props.AutoCompleteUrl = $item.autoCompleteUrl + } + + foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) { + if ($null -eq $props.$extraProperty) { + $props.$extraProperty = $item.$extraProperty + } + } + + $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 + } + } + } } } From 824eb043b6dc42caea0002ad4e8c409586dede36 Mon Sep 17 00:00:00 2001 From: hmmwhatsthisdo <2093321+hmmwhatsthisdo@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:27:08 -0700 Subject: [PATCH 3/4] Refactor to unify v8/v9+ CreateMeta response rehydration --- .../Private/ConvertTo-JiraCreateMetaField.ps1 | 112 +++++++----------- 1 file changed, 40 insertions(+), 72 deletions(-) diff --git a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 index b8fa7a0c..a0b01f33 100644 --- a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 +++ b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 @@ -14,95 +14,63 @@ function ConvertTo-JiraCreateMetaField { $fieldList = $null If ($null -ne $i.values) { - $fieldList = $i.values + $fieldList = $i.values | ForEach-Object { + @{ + Name = $_.fieldId + Value = $_ + } + } } Elseif ($null -ne $i.projects.issuetypes.fields) { + $fields = $i.projects.issuetypes.fields + $fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name + + $fieldList = $fieldNames | ForEach-Object { + @{ + Name = $_ + Value = $fields.$_ + } + } } Else { Write-Error -Exception ([System.ArgumentException]::new("Input data does not match a known CreateMeta payload.", "InputObject")) } - if ($null -ne $i.values) { - - $i.values | ForEach-Object { - $item = $_ - - $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.allowedValues) { - $props.AllowedValues = $item.allowedValues - } - - if ($item.autoCompleteUrl) { - $props.AutoCompleteUrl = $item.autoCompleteUrl - } - - foreach ($extraProperty in (Get-Member -InputObject $item -MemberType NoteProperty).Name) { - if ($null -eq $props.$extraProperty) { - $props.$extraProperty = $item.$extraProperty - } - } - - $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)" - } + $FieldList | ForEach-Object { + $item = $_.Value - Write-Output $result + $props = @{ + 'Id' = $_.Name + 'Name' = $item.name + 'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue) + 'Required' = [System.Convert]::ToBoolean($item.required) + 'Schema' = $item.schema + 'Operations' = $item.operations } - } - else { - - $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 - } - - if ($item.allowedValues) { - $props.AllowedValues = $item.allowedValues - } - - 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 + } } } } From 046df7f0b806ece3bfa83f503dfa20e15ca42b3a Mon Sep 17 00:00:00 2001 From: hmmwhatsthisdo <2093321+hmmwhatsthisdo@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:10:47 -0700 Subject: [PATCH 4/4] Add debug statements for Jira 8/9 CreateMeta --- JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 index a0b01f33..139c4cc9 100644 --- a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 +++ b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 @@ -14,6 +14,8 @@ function ConvertTo-JiraCreateMetaField { $fieldList = $null If ($null -ne $i.values) { + Write-Debug "[$($MyInvocation.MyCommand.Name)] Input appears to be from Jira 9+ CreateMeta" + $fieldList = $i.values | ForEach-Object { @{ Name = $_.fieldId @@ -22,6 +24,7 @@ function ConvertTo-JiraCreateMetaField { } } Elseif ($null -ne $i.projects.issuetypes.fields) { + Write-Debug "[$($MyInvocation.MyCommand.Name)] Input appears to be from Jira 8 (or below) CreateMeta" $fields = $i.projects.issuetypes.fields $fieldNames = (Get-Member -InputObject $fields -MemberType '*Property').Name