From 74859f1f50cf74fb0a470e9f3e0fb00d443f86aa Mon Sep 17 00:00:00 2001 From: Grady Duncan Date: Thu, 11 Jun 2020 11:26:15 -0400 Subject: [PATCH 1/2] Adding ability to support true required fields and not UI required (attachments). --- JiraPS/Private/Resolve-ErrorWebResponse.ps1 | 22 +++++++++++++++++++ JiraPS/Public/New-JiraIssue.ps1 | 24 +-------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/JiraPS/Private/Resolve-ErrorWebResponse.ps1 b/JiraPS/Private/Resolve-ErrorWebResponse.ps1 index 2c207e35..62833602 100644 --- a/JiraPS/Private/Resolve-ErrorWebResponse.ps1 +++ b/JiraPS/Private/Resolve-ErrorWebResponse.ps1 @@ -44,7 +44,29 @@ function Resolve-ErrorWebResponse { try { $responseObject = ConvertFrom-Json -InputObject $responseBody -ErrorAction Stop + $errorArray = @() foreach ($_error in ($responseObject.errorMessages + $responseObject.errors)) { + + foreach ($_err in $_error.PSObject.Properties.Value) { + if ($_err -like "*You must specify a summary of the issue." -Or $_err -like "*is required.") { + Write-Debug $_err + $errorArray += $_err + } else { + # unhandled value + } + } + + if ($errorArray.count -gt 0) { + $errorParameter = @{ + ExceptionType = "System.Net.Http.HttpRequestException" + Message = "Missing Required Fields: $errorArray" + ErrorId = "AuthenticationFailed" + Category = "AuthenticationError" + Cmdlet = $Cmdlet + } + ThrowError @errorParameter + } + # $_error is a PSCustomObject - therefore can't be $false if ($_error -is [PSCustomObject]) { [String]$_error = ($_error | Out-String) diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1 index 9f3eca6a..69d501e8 100644 --- a/JiraPS/Public/New-JiraIssue.ps1 +++ b/JiraPS/Public/New-JiraIssue.ps1 @@ -58,7 +58,7 @@ function New-JiraIssue { process { $server = Get-JiraConfigServer -ErrorAction Stop -Debug:$false - $createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false + # $createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false $resourceURi = "$server/rest/api/2/issue" @@ -141,28 +141,6 @@ function New-JiraIssue { } } - Write-Verbose "[$($MyInvocation.MyCommand.Name)] Validating fields with metadata" - foreach ($c in $createmeta) { - Write-Debug "[$($MyInvocation.MyCommand.Name)] Checking metadata for `$c [$c]" - if ($c.Required) { - if ($requestBody.ContainsKey($c.Id)) { - Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Required field (id=[$($c.Id)], name=[$($c.Name)]) was provided (value=[$($requestBody.$($c.Id))])" - } - else { - $exception = ([System.ArgumentException]"Invalid or missing value Parameter") - $errorId = 'ParameterValue.CreateMetaFailure' - $errorCategory = 'InvalidArgument' - $errorTarget = $Fields - $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget - $errorItem.ErrorDetails = "Jira's metadata for project [$Project] and issue type [$IssueType] specifies that a field is required that was not provided (name=[$($c.Name)], id=[$($c.Id)]). Use Get-JiraIssueCreateMetadata for more information." - $PSCmdlet.ThrowTerminatingError($errorItem) - } - } - else { - Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Non-required field (id=[$($c.Id)], name=[$($c.Name)])" - } - } - $hashtable = @{ 'fields' = ([PSCustomObject]$requestBody) } From 850dd4c7408f570b48b7c2e354e73ee86ca5a0a1 Mon Sep 17 00:00:00 2001 From: Grady Duncan Date: Thu, 11 Jun 2020 11:28:06 -0400 Subject: [PATCH 2/2] Cleaning up comments --- JiraPS/Public/New-JiraIssue.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1 index 69d501e8..4dfd5293 100644 --- a/JiraPS/Public/New-JiraIssue.ps1 +++ b/JiraPS/Public/New-JiraIssue.ps1 @@ -58,8 +58,6 @@ function New-JiraIssue { process { $server = Get-JiraConfigServer -ErrorAction Stop -Debug:$false - # $createmeta = Get-JiraIssueCreateMetadata -Project $Project -IssueType $IssueType -Credential $Credential -ErrorAction Stop -Debug:$false - $resourceURi = "$server/rest/api/2/issue" Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"