Skip to content

Commit

Permalink
** Modify Get-JiraIssueCreateMetadata and New-JiraIssue to do proper …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
pdx-nojp committed Feb 15, 2019
1 parent 53476e7 commit 89e61fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion JiraPS/Public/Get-JiraIssueCreateMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion JiraPS/Public/New-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -85,6 +95,10 @@ function New-JiraIssue {
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Reporter")) {
$requestBody["reporter"] = @{"name" = "$Reporter"}
}
elseif ($ProjectObj.Style -eq "next-gen"){

This comment has been minimized.

Copy link
@LaurentGoderre

LaurentGoderre Feb 24, 2020

This doesn't seem to be needed anymore? Trying to set the current user as a reporter gives an error:

Field 'reporter' cannot be set. It is not on the appropriate screen, or unknown.
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}
Expand Down

0 comments on commit 89e61fa

Please sign in to comment.