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 usage of New-JiraIssue in Jira Environment with mixed classic and "next gen" projects #337

Merged
merged 4 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions JiraPS/Private/ConvertTo-JiraProject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function ConvertTo-JiraProject {
'Roles' = $i.roles
'RestUrl' = $i.self
'Components' = $i.components
'Style' = $i.style
}

if ($i.projectCategory) {
Expand Down
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"){
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Adding reporter as next-gen projects must have reporter set."
$requestBody["reporter"] = @{"name" = "$((Get-JiraUser -Credential $Credential).Name)"}
}

if ($Parent) {
$requestBody["parent"] = @{"key" = $Parent}
Expand Down
15 changes: 6 additions & 9 deletions Tests/Functions/Get-JiraIssueCreateMetadata.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,20 @@ Describe "Get-JiraIssueCreateMetadata" -Tag 'Unit' {
}

Mock Get-JiraProject -ModuleName JiraPS {
$issueObject = [PSCustomObject] @{
ID = 2
Name = 'Test Issue Type'
}
$issueObject.PSObject.TypeNames.Insert(0, 'JiraPS.IssueType')
$object = [PSCustomObject] @{
ID = 10003
Name = 'Test Project'
}
Add-Member -InputObject $object -MemberType NoteProperty -Name "IssueTypes" -Value $issueObject
$object.PSObject.TypeNames.Insert(0, 'JiraPS.Project')
return $object
}

Mock Get-JiraIssueType -ModuleName JiraPS {
$object = [PSCustomObject] @{
ID = 2
Name = 'Test Issue Type'
}
$object.PSObject.TypeNames.Insert(0, 'JiraPS.IssueType')
return $object
}

Mock ConvertTo-JiraCreateMetaField -ModuleName JiraPS {
$InputObject
}
Expand Down
15 changes: 7 additions & 8 deletions Tests/Functions/New-JiraIssue.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Describe "New-JiraIssue" -Tag 'Unit' {


$jiraServer = 'https://jira.example.com'
$issueTypeTest = 1

Mock Get-JiraConfigServer {
$jiraServer
Expand All @@ -56,22 +57,20 @@ Describe "New-JiraIssue" -Tag 'Unit' {
}

Mock Get-JiraProject {
$issueObject = [PSCustomObject] @{
ID = $issueTypeTest
Name = 'Test Issue Type'
}
$issueObject.PSObject.TypeNames.Insert(0, 'JiraPS.IssueType')
$object = [PSCustomObject] @{
'ID' = $Project
'Key' = "TEST"
}
Add-Member -InputObject $object -MemberType NoteProperty -Name "IssueTypes" -Value $issueObject
$object.PSObject.TypeNames.Insert(0, 'JiraPS.Project')
return $object
}

Mock Get-JiraIssueType {
$object = [PSCustomObject] @{
'ID' = $IssueType;
}
$object.PSObject.TypeNames.Insert(0, 'JiraPS.IssueType')
return $object
}

Mock Get-JiraUser {
$object = [PSCustomObject] @{
'Name' = $UserName;
Expand Down