Skip to content

Commit

Permalink
Merge pull request #225 from lipkau/fix/#224-BadBody
Browse files Browse the repository at this point in the history
Fixed how the Body of `New-JiraIssue` is created
  • Loading branch information
lipkau authored Mar 23, 2018
2 parents 24c3439 + 2aa9063 commit 5a76ffd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions JiraPS/Public/Get-JiraField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@

$allFields = Get-JiraField -Credential $Credential

Write-Output ($allFields | Where-Object -FilterScript {$_.Id -eq $_field})
Write-Output ($allFields | Where-Object -FilterScript {$_.Name -like $_field})
Write-Output ($allFields | Where-Object -FilterScript {($_.Id -eq $_field) -or ($_.Name -like $_field)})
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions JiraPS/Public/New-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ function New-JiraIssue {
begin {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

$server = Get-JiraConfigServer -ErrorAction Stop
$server = Get-JiraConfigServer -ErrorAction Stop -Debug:$false

$createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop
$createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false

$resourceURi = "$server/rest/api/latest/issue"
}
Expand All @@ -95,8 +95,8 @@ function New-JiraIssue {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
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
$ProjectObj = Get-JiraProject -Project $Project -Credential $Credential -ErrorAction Stop -Debug:$false
$IssueTypeObj = Get-JiraIssueType -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false

$requestBody = @{
"project" = @{"id" = $ProjectObj.Id}
Expand All @@ -105,19 +105,19 @@ function New-JiraIssue {
}

if ($Priority) {
$requestBody.priority = @{"id" = [String] $Priority}
$requestBody["priority"] = @{"id" = [String] $Priority}
}

if ($Description) {
$requestBody.description = $Description
$requestBody["description"] = $Description
}

if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey("Reporter")) {
$requestBody.reporter = @{"name" = "$Reporter"}
$requestBody["reporter"] = @{"name" = "$Reporter"}
}

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

if ($Labels) {
Expand All @@ -139,12 +139,12 @@ function New-JiraIssue {
$name = $_key
$value = $Fields.$_key

if ($field = Get-JiraField -Field $name -Credential $Credential) {
if ($field = Get-JiraField -Field $name -Credential $Credential -Debug:$false) {
# For some reason, this was coming through as a hashtable instead of a String,
# which was causing ConvertTo-Json to crash later.
# Not sure why, but this forces $id to be a String and not a hashtable.
$id = $field.Id
$requestBody.$id = $value
$requestBody["$id"] = $value
}
else {
$errorItem = [System.Management.Automation.ErrorRecord]::new(
Expand Down Expand Up @@ -182,13 +182,13 @@ function New-JiraIssue {
}

$hashtable = @{
'fields' = $requestBody
'fields' = ([PSCustomObject]$requestBody)
}

$parameter = @{
URI = $resourceURi
Method = "POST"
Body = (ConvertTo-Json -InputObject $hashtable -Depth 7)
Body = (ConvertTo-Json -InputObject ([PSCustomObject]$hashtable) -Depth 7)
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
Expand Down

0 comments on commit 5a76ffd

Please sign in to comment.