diff --git a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 index 4db39833..444d4592 100644 --- a/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 +++ b/JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1 @@ -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 } } } diff --git a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 index 54e9c82e..8d8b42af 100644 --- a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 @@ -22,7 +22,7 @@ function Get-JiraIssueCreateMetadata { $server = Get-JiraConfigServer -ErrorAction Stop - $resourceURi = "$server/rest/api/2/issue/createmeta?projectIds={0}&issuetypeIds={1}&expand=projects.issuetypes.fields" + $resourceURi = "$server/rest/api/2/issue/createmeta/{0}/issuetypes/{1}" } process { @@ -47,40 +47,16 @@ function Get-JiraIssueCreateMetadata { Method = "GET" Credential = $Credential } + Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter" $result = Invoke-JiraMethod @parameter if ($result) { - if (@($result.projects).Count -eq 0) { - $errorMessage = @{ - Category = "InvalidResult" - CategoryActivity = "Validating response" - Message = "No projects were found for the given project [$Project]. Use Get-JiraProject for more details." - } - Write-Error @errorMessage - } - elseif (@($result.projects).Count -gt 1) { - $errorMessage = @{ - Category = "InvalidResult" - CategoryActivity = "Validating response" - Message = "Multiple projects were found for the given project [$Project]. Refine the parameters to return only one project." - } - Write-Error @errorMessage - } - - if (@($result.projects.issuetypes) -eq 0) { - $errorMessage = @{ - Category = "InvalidResult" - CategoryActivity = "Validating response" - Message = "No issue types were found for the given issue type [$IssueType]. Use Get-JiraIssueType for more details." - } - Write-Error @errorMessage - } - elseif (@($result.projects.issuetypes).Count -gt 1) { + if (@($result.values).Count -eq 0) { $errorMessage = @{ Category = "InvalidResult" CategoryActivity = "Validating response" - Message = "Multiple issue types were found for the given issue type [$IssueType]. Refine the parameters to return only one issue type." + Message = "No values were found for the given project [$Project]. Use Get-JiraProject for more details." } Write-Error @errorMessage } diff --git a/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 b/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 index d2e79995..3b8b431b 100644 --- a/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 +++ b/Tests/Functions/ConvertTo-JiraCreateMetaField.Unit.Tests.ps1 @@ -39,71 +39,62 @@ Describe "ConvertTo-JiraCreateMetaField" -Tag 'Unit' { $sampleJson = @' { - "expand": "projects", - "projects": [ + "values": [ { - "expand": "issuetypes", - "issuetypes": [ + "required": true, + "schema": { + "type": "string", + "system": "summary" + }, + "name": "Summary", + "fieldId": "summary", + "hasDefaultValue": false, + "operations": [ + "set" + ] + }, + { + "required": false, + "schema": { + "type": "priority", + "system": "priority" + }, + "name": "Priority", + "fieldId": "priority", + "hasDefaultValue": true, + "operations": [ + "set" + ], + "allowedValues": [ + { + "self": "http://jiraserver.example.com/rest/api/2/priority/1", + "iconUrl": "http://jiraserver.example.com/images/icons/priorities/blocker.png", + "name": "Block", + "id": "1" + }, + { + "self": "http://jiraserver.example.com/rest/api/2/priority/2", + "iconUrl": "http://jiraserver.example.com/images/icons/priorities/critical.png", + "name": "Critical", + "id": "2" + }, + { + "self": "http://jiraserver.example.com/rest/api/2/priority/3", + "iconUrl": "http://jiraserver.example.com/images/icons/priorities/major.png", + "name": "Major", + "id": "3" + }, + { + "self": "http://jiraserver.example.com/rest/api/2/priority/4", + "iconUrl": "http://jiraserver.example.com/images/icons/priorities/minor.png", + "name": "Minor", + "id": "4" + }, { - "expand": "fields", - "fields": { - "summary": { - "required": true, - "schema": { - "type": "string", - "system": "summary" - }, - "name": "Summary", - "hasDefaultValue": false, - "operations": [ - "set" - ] - }, - "priority": { - "required": false, - "schema": { - "type": "priority", - "system": "priority" - }, - "name": "Priority", - "hasDefaultValue": true, - "operations": [ - "set" - ], - "allowedValues": [ - { - "self": "http://jiraserver.example.com/rest/api/2/priority/1", - "iconUrl": "http://jiraserver.example.com/images/icons/priorities/blocker.png", - "name": "Block", - "id": "1" - }, - { - "self": "http://jiraserver.example.com/rest/api/2/priority/2", - "iconUrl": "http://jiraserver.example.com/images/icons/priorities/critical.png", - "name": "Critical", - "id": "2" - }, - { - "self": "http://jiraserver.example.com/rest/api/2/priority/3", - "iconUrl": "http://jiraserver.example.com/images/icons/priorities/major.png", - "name": "Major", - "id": "3" - }, - { - "self": "http://jiraserver.example.com/rest/api/2/priority/4", - "iconUrl": "http://jiraserver.example.com/images/icons/priorities/minor.png", - "name": "Minor", - "id": "4" - }, - { - "self": "http://jiraserver.example.com/rest/api/2/priority/5", - "iconUrl": "http://jiraserver.example.com/images/icons/priorities/trivial.png", - "name": "Trivial", - "id": "5" - } - ] - } - } + "self": "http://jiraserver.example.com/rest/api/2/priority/5", + "iconUrl": "http://jiraserver.example.com/images/icons/priorities/trivial.png", + "name": "Trivial", + "id": "5" } ] }