Skip to content

Commit

Permalink
Merge pull request #1 from arcadech/fix-newissuecreatemetadatabug
Browse files Browse the repository at this point in the history
Fix newissuecreatemetadatabug
  • Loading branch information
FlavorFlav authored Feb 14, 2024
2 parents 59c35df + 6afcf8a commit e86c7ad
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions JiraPS/Public/Get-JiraIssueCreateMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 {
Expand Down Expand Up @@ -50,38 +50,35 @@ function Get-JiraIssueCreateMetadata {
$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) {
if (@($result.values).Count -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."
Message = "No fields were found for the given project [$Project] and issue type [$IssueType]."
}
Write-Error @errorMessage
}
elseif (@($result.projects.issuetypes).Count -gt 1) {
$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."
}
Write-Error @errorMessage

# Before Jira v9 there was a /createmetadata endpoint that returned
# an object containing projects, their issue types and their fields.
# Since then, only a list of fields is returned. To keep the old
# format, fake the old result by creating such an object. This is a
# workaround until the official JiraPS project fixed the issue.
# Check the following release notes:
# https://confluence.atlassian.com/jiracore/createmeta-rest-endpoint-to-be-removed-975040986.html
$resultFields = @{}
$result.values | ForEach-Object { $resultFields[$_.fieldid] = $_ }
$result = [PSCustomObject] @{
projects = @(
[PSCustomObject] @{
issuetypes = @(
[PSCustomObject] @{
fields = [PSCustomObject] $resultFields
}
)
}
)
}

Write-Output (ConvertTo-JiraCreateMetaField -InputObject $result)
Expand Down

0 comments on commit e86c7ad

Please sign in to comment.