Skip to content

Commit 89e61fa

Browse files
committed
** 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
1 parent 53476e7 commit 89e61fa

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

JiraPS/Public/Get-JiraIssueCreateMetadata.ps1

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ function Get-JiraIssueCreateMetadata {
2929
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"
3030

3131
$projectObj = Get-JiraProject -Project $Project -Credential $Credential -ErrorAction Stop
32-
$issueTypeObj = Get-JiraIssueType -IssueType $IssueType -Credential $Credential -ErrorAction Stop
32+
$issueTypeObj = $projectObj.IssueTypes | Where-Object -FilterScript {$_.Id -eq $IssueType -or $_.Name -eq $IssueType}
33+
34+
if ($null -eq $issueTypeObj.Id)
35+
{
36+
$errorMessage = @{
37+
Category = "InvalidResult"
38+
CategoryActivity = "Validating parameters"
39+
Message = "No issue types were found in the project [$Project] for the given issue type [$IssueType]. Use Get-JiraIssueType for more details."
40+
}
41+
Write-Error @errorMessage
42+
}
3343

3444
$parameter = @{
3545
URI = $resourceURi -f $projectObj.Id, $issueTypeObj.Id

JiraPS/Public/New-JiraIssue.ps1

+15-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ function New-JiraIssue {
6666
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"
6767

6868
$ProjectObj = Get-JiraProject -Project $Project -Credential $Credential -ErrorAction Stop -Debug:$false
69-
$IssueTypeObj = Get-JiraIssueType -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false
69+
$issueTypeObj = $projectObj.IssueTypes | Where-Object -FilterScript {$_.Id -eq $IssueType -or $_.Name -eq $IssueType}
70+
71+
if ($null -eq $issueTypeObj.Id)
72+
{
73+
$errorMessage = @{
74+
Category = "InvalidResult"
75+
CategoryActivity = "Validating parameters"
76+
Message = "No issue types were found in the project [$Project] for the given issue type [$IssueType]. Use Get-JiraIssueType for more details."
77+
}
78+
Write-Error @errorMessage
79+
}
7080

7181
$requestBody = @{
7282
"project" = @{"id" = $ProjectObj.Id}
@@ -85,6 +95,10 @@ function New-JiraIssue {
8595
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Reporter")) {
8696
$requestBody["reporter"] = @{"name" = "$Reporter"}
8797
}
98+
elseif ($ProjectObj.Style -eq "next-gen"){
99+
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding reporter as next-gen projects must have reporter set."
100+
$requestBody["reporter"] = @{"name" = "$((Get-JiraUser -UserName ((Get-JiraSession).UserName)).Name)"}
101+
}
88102

89103
if ($Parent) {
90104
$requestBody["parent"] = @{"key" = $Parent}

0 commit comments

Comments
 (0)