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

Fix issue with /createmetadata endpoint deprecation #489

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
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