diff --git a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 index f1a03ab0..8e1b05c8 100644 --- a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 @@ -29,7 +29,17 @@ function Get-JiraIssueCreateMetadata { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $projectObj = Get-JiraProject -Project $Project -Credential $Credential -ErrorAction Stop - $issueTypeObj = Get-JiraIssueType -IssueType $IssueType -Credential $Credential -ErrorAction Stop + $issueTypeObj = $projectObj.IssueTypes | Where-Object -FilterScript {$_.Id -eq $IssueType -or $_.Name -eq $IssueType} + + if ($null -eq $issueTypeObj.Id) + { + $errorMessage = @{ + Category = "InvalidResult" + CategoryActivity = "Validating parameters" + Message = "No issue types were found in the project [$Project] for the given issue type [$IssueType]. Use Get-JiraIssueType for more details." + } + Write-Error @errorMessage + } $parameter = @{ URI = $resourceURi -f $projectObj.Id, $issueTypeObj.Id diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1 index 53751b6d..8bf18f57 100644 --- a/JiraPS/Public/New-JiraIssue.ps1 +++ b/JiraPS/Public/New-JiraIssue.ps1 @@ -66,7 +66,17 @@ function New-JiraIssue { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $ProjectObj = Get-JiraProject -Project $Project -Credential $Credential -ErrorAction Stop -Debug:$false - $IssueTypeObj = Get-JiraIssueType -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false + $issueTypeObj = $projectObj.IssueTypes | Where-Object -FilterScript {$_.Id -eq $IssueType -or $_.Name -eq $IssueType} + + if ($null -eq $issueTypeObj.Id) + { + $errorMessage = @{ + Category = "InvalidResult" + CategoryActivity = "Validating parameters" + Message = "No issue types were found in the project [$Project] for the given issue type [$IssueType]. Use Get-JiraIssueType for more details." + } + Write-Error @errorMessage + } $requestBody = @{ "project" = @{"id" = $ProjectObj.Id} @@ -85,6 +95,10 @@ function New-JiraIssue { if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Reporter")) { $requestBody["reporter"] = @{"name" = "$Reporter"} } + elseif ($ProjectObj.Style -eq "next-gen"){ + Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding reporter as next-gen projects must have reporter set." + $requestBody["reporter"] = @{"name" = "$((Get-JiraUser -UserName ((Get-JiraSession).UserName)).Name)"} + } if ($Parent) { $requestBody["parent"] = @{"key" = $Parent}