From 89e61fa73519d5d83b2e660d8d238f2b86303056 Mon Sep 17 00:00:00 2001 From: Joel Nolan Date: Fri, 15 Feb 2019 14:10:41 -0800 Subject: [PATCH] ** Modify Get-JiraIssueCreateMetadata and New-JiraIssue to do proper error handling when the input IssueType value is not valid for the input Project value ** Modify Get-JiraIssueCreateMetadata and New-JiraIssue to use data already returned from Get-JiraProject, saving an API call and some filtering work in Get-JiraIssueType --- JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 | 12 +++++++++++- JiraPS/Public/New-JiraIssue.ps1 | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) 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}