Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Jira 9+ CreateMeta handling #514

Closed
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
38 changes: 33 additions & 5 deletions JiraPS/Private/ConvertTo-JiraCreateMetaField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,41 @@ 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

$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
Value = $_
}
}
}
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

$fieldList = $fieldNames | ForEach-Object {
@{
Name = $_
Value = $fields.$_
}
}
}
Else {
Write-Error -Exception ([System.ArgumentException]::new("Input data does not match a known CreateMeta payload.", "InputObject"))
}

$FieldList | ForEach-Object {
$item = $_.Value

$props = @{
'Id' = $f
'Id' = $_.Name
'Name' = $item.name
'HasDefaultValue' = [System.Convert]::ToBoolean($item.hasDefaultValue)
'Required' = [System.Convert]::ToBoolean($item.required)
Expand Down
11 changes: 10 additions & 1 deletion JiraPS/Public/Get-JiraIssueCreateMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down