From eb3314c32a6bed7fe03f4d5fbe3c7e8bc2f01777 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Mon, 28 May 2018 21:01:20 +0200 Subject: [PATCH 1/6] Fixed Credential pop up --- JiraPS/Private/Invoke-WebRequest.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JiraPS/Private/Invoke-WebRequest.ps1 b/JiraPS/Private/Invoke-WebRequest.ps1 index be45751c..9393d2f9 100644 --- a/JiraPS/Private/Invoke-WebRequest.ps1 +++ b/JiraPS/Private/Invoke-WebRequest.ps1 @@ -30,7 +30,7 @@ function Invoke-WebRequest { [pscredential] [System.Management.Automation.CredentialAttribute()] - ${Credential}, + ${Credential} = [System.Management.Automation.PSCredential]::Empty, [switch] ${UseDefaultCredentials}, @@ -68,7 +68,7 @@ function Invoke-WebRequest { [pscredential] [System.Management.Automation.CredentialAttribute()] - ${ProxyCredential}, + ${ProxyCredential} = [System.Management.Automation.PSCredential]::Empty, [switch] ${ProxyUseDefaultCredentials}, @@ -94,7 +94,7 @@ function Invoke-WebRequest { ${PassThru}) begin { - if ($Credential) { + if ($Credential -and ($Credential -ne [System.Management.Automation.PSCredential]::Empty)) { $SecureCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( $('{0}:{1}' -f $Credential.UserName, $Credential.GetNetworkCredential().Password) )) From f1a6daaa94aa0aa1b551f9cbc296e00521edf370 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Tue, 29 May 2018 20:38:58 +0200 Subject: [PATCH 2/6] Fixed header entry which is no supported in PSv3 --- JiraPS/Public/Invoke-JiraMethod.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/JiraPS/Public/Invoke-JiraMethod.ps1 b/JiraPS/Public/Invoke-JiraMethod.ps1 index d3a0123c..4312fa0f 100644 --- a/JiraPS/Public/Invoke-JiraMethod.ps1 +++ b/JiraPS/Public/Invoke-JiraMethod.ps1 @@ -44,9 +44,13 @@ function Invoke-JiraMethod { # pass input to local variable # this allows to use the PSBoundParameters for recursion $_headers = @{ # Set any default headers - "Accept" = "application/json" + # "Accept" = "application/json" "Accept-Charset" = "utf-8" } + # Bug in PSv3's .Net API + if ($PSVersionTable.PSVersion.Major -eq 3) { + $_headers["Accept"] = "application/json" + } foreach ($item in $Headers.Key) { $_headers[$item] = $Headers[$item] } } From 803e0d8dcbd81d784fb8a16afe0197a13480f4f6 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Tue, 29 May 2018 21:42:02 +0200 Subject: [PATCH 3/6] Updated constructor of exceptions to be PSv3 compliant --- JiraPS/JiraPS.psm1 | 14 ++--- JiraPS/Private/Resolve-JiraError.ps1 | 22 ++++---- JiraPS/Private/Resolve-JiraIssueObject.ps1 | 11 ++-- JiraPS/Public/Add-JiraIssueAttachment.ps1 | 33 +++++------ JiraPS/Public/Add-JiraIssueComment.ps1 | 11 ++-- JiraPS/Public/Add-JiraIssueLink.ps1 | 22 ++++---- JiraPS/Public/Add-JiraIssueWatcher.ps1 | 11 ++-- JiraPS/Public/Add-JiraIssueWorklog.ps1 | 11 ++-- JiraPS/Public/Get-JiraComponent.ps1 | 11 ++-- JiraPS/Public/Get-JiraConfigServer.ps1 | 33 +++++------ JiraPS/Public/Get-JiraFilter.ps1 | 11 ++-- JiraPS/Public/Get-JiraGroupMember.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssue.ps1 | 22 ++++---- JiraPS/Public/Get-JiraIssueAttachment.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueComment.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueEditMetadata.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueLink.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueLinkType.ps1 | 11 ++-- JiraPS/Public/Get-JiraIssueWatcher.ps1 | 11 ++-- JiraPS/Public/Get-JiraRemoteLink.ps1 | 11 ++-- JiraPS/Public/Invoke-JiraIssueTransition.ps1 | 55 +++++++++---------- JiraPS/Public/New-JiraIssue.ps1 | 22 ++++---- JiraPS/Public/New-JiraVersion.ps1 | 22 ++++---- JiraPS/Public/Remove-JiraGroup.ps1 | 11 ++-- JiraPS/Public/Remove-JiraGroupMember.ps1 | 22 ++++---- JiraPS/Public/Remove-JiraIssueAttachment.ps1 | 22 ++++---- JiraPS/Public/Remove-JiraIssueLink.ps1 | 11 ++-- JiraPS/Public/Remove-JiraIssueWatcher.ps1 | 11 ++-- JiraPS/Public/Remove-JiraRemoteLink.ps1 | 11 ++-- JiraPS/Public/Remove-JiraUser.ps1 | 11 ++-- JiraPS/Public/Remove-JiraVersion.ps1 | 11 ++-- JiraPS/Public/Set-JiraConfigServer.ps1 | 11 ++-- JiraPS/Public/Set-JiraIssue.ps1 | 22 ++++---- JiraPS/Public/Set-JiraIssueLabel.ps1 | 11 ++-- JiraPS/Public/Set-JiraUser.ps1 | 22 ++++---- JiraPS/Public/Set-JiraVersion.ps1 | 22 ++++---- 37 files changed, 277 insertions(+), 331 deletions(-) diff --git a/JiraPS/JiraPS.psm1 b/JiraPS/JiraPS.psm1 index 383636c1..c4cac996 100644 --- a/JiraPS/JiraPS.psm1 +++ b/JiraPS/JiraPS.psm1 @@ -24,14 +24,14 @@ foreach ($file in @($PublicFunctions + $PrivateFunctions)) { . $file.FullName } catch { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Function not found"), - 'Load.Function', - [System.Management.Automation.ErrorCategory]::ObjectNotFound, - $file - ) + $exception = ([System.ArgumentException]"Function not found") + $errorId = "Load.Function" + $errorCategory = 'ObjectNotFound' + $errorTarget = $file + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Failed to import function $($file.BaseName)" - throw $errorItem + # throw $errorItem + throw $_ } } Export-ModuleMember -Function $PublicFunctions.BaseName diff --git a/JiraPS/Private/Resolve-JiraError.ps1 b/JiraPS/Private/Resolve-JiraError.ps1 index a13111b3..b87bfda2 100644 --- a/JiraPS/Private/Resolve-JiraError.ps1 +++ b/JiraPS/Private/Resolve-JiraError.ps1 @@ -21,12 +21,11 @@ if ($i.errorMessages) { foreach ($e in $i.errorMessages) { if ($WriteError) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Server responded with Error"), - "ServerResponse", - [System.Management.Automation.ErrorCategory]::NotSpecified, - $i - ) + $exception = ([System.ArgumentException]"Server responded with Error") + $errorId = "ServerResponse" + $errorCategory = 'NotSpecified' + $errorTarget = $i + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Jira encountered an error: [$e]" $Cmdlet.WriteError($errorItem) } @@ -48,12 +47,11 @@ $keys = (Get-Member -InputObject $i.errors | Where-Object -FilterScript {$_.MemberType -eq 'NoteProperty'}).Name foreach ($k in $keys) { if ($WriteError) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Server responded with Error"), - "ServerResponse.$k", - [System.Management.Automation.ErrorCategory]::NotSpecified, - $i - ) + $exception = ([System.ArgumentException]"Server responded with Error") + $errorId = "ServerResponse.$k" + $errorCategory = 'NotSpecified' + $errorTarget = $i + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Jira encountered an error: [$k] - $($i.errors.$k)" $Cmdlet.WriteError($errorItem) } diff --git a/JiraPS/Private/Resolve-JiraIssueObject.ps1 b/JiraPS/Private/Resolve-JiraIssueObject.ps1 index 3277c889..12afb5d3 100644 --- a/JiraPS/Private/Resolve-JiraIssueObject.ps1 +++ b/JiraPS/Private/Resolve-JiraIssueObject.ps1 @@ -10,12 +10,11 @@ function Resolve-JiraIssueObject { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Add-JiraIssueAttachment.ps1 b/JiraPS/Public/Add-JiraIssueAttachment.ps1 index 1c098d50..a298b39f 100644 --- a/JiraPS/Public/Add-JiraIssueAttachment.ps1 +++ b/JiraPS/Public/Add-JiraIssueAttachment.ps1 @@ -6,12 +6,11 @@ function Add-JiraIssueAttachment { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -36,12 +35,11 @@ function Add-JiraIssueAttachment { [ValidateScript( { if (-not (Test-Path $_ -PathType Leaf)) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"File not found"), - 'ParameterValue.FileNotFound', - [System.Management.Automation.ErrorCategory]::ObjectNotFound, - $_ - ) + $exception = ([System.ArgumentException]"File not found") #fix code highlighting] + $errorId = 'ParameterValue.FileNotFound' + $errorCategory = 'ObjectNotFound' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "No file could be found with the provided path '$_'." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -74,12 +72,11 @@ function Add-JiraIssueAttachment { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" if (@($Issue).Count -ne 1) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"invalid Issue provided"), - 'ParameterValue.JiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"invalid Issue provided") + $errorId = 'ParameterValue.JiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Only one Issue can be provided at a time." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Add-JiraIssueComment.ps1 b/JiraPS/Public/Add-JiraIssueComment.ps1 index 651d0881..50032816 100644 --- a/JiraPS/Public/Add-JiraIssueComment.ps1 +++ b/JiraPS/Public/Add-JiraIssueComment.ps1 @@ -11,12 +11,11 @@ function Add-JiraIssueComment { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Add-JiraIssueLink.ps1 b/JiraPS/Public/Add-JiraIssueLink.ps1 index f8a2f867..c5770ef9 100644 --- a/JiraPS/Public/Add-JiraIssueLink.ps1 +++ b/JiraPS/Public/Add-JiraIssueLink.ps1 @@ -6,12 +6,11 @@ function Add-JiraIssueLink { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -36,12 +35,11 @@ function Add-JiraIssueLink { ($objectProperties.Name -contains "type") -and (($objectProperties.Name -contains "outwardIssue") -or ($objectProperties.Name -contains "inwardIssue")) )) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Parameter"), - 'ParameterProperties.Incomplete', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Parameter") #fix code highlighting] + $errorId = 'ParameterProperties.Incomplete' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "The IssueLink provided does not contain the information needed." $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Add-JiraIssueWatcher.ps1 b/JiraPS/Public/Add-JiraIssueWatcher.ps1 index ac9282ea..323eb526 100644 --- a/JiraPS/Public/Add-JiraIssueWatcher.ps1 +++ b/JiraPS/Public/Add-JiraIssueWatcher.ps1 @@ -14,12 +14,11 @@ [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Add-JiraIssueWorklog.ps1 b/JiraPS/Public/Add-JiraIssueWorklog.ps1 index 7c164be3..c8ee9b28 100644 --- a/JiraPS/Public/Add-JiraIssueWorklog.ps1 +++ b/JiraPS/Public/Add-JiraIssueWorklog.ps1 @@ -11,12 +11,11 @@ function Add-JiraIssueWorklog { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraComponent.ps1 b/JiraPS/Public/Get-JiraComponent.ps1 index 2ad92467..7b58099a 100644 --- a/JiraPS/Public/Get-JiraComponent.ps1 +++ b/JiraPS/Public/Get-JiraComponent.ps1 @@ -6,12 +6,11 @@ function Get-JiraComponent { [ValidateScript( { if (("JiraPS.Project" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraProject', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraProject' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Project] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraConfigServer.ps1 b/JiraPS/Public/Get-JiraConfigServer.ps1 index 63caef8d..297a114f 100644 --- a/JiraPS/Public/Get-JiraConfigServer.ps1 +++ b/JiraPS/Public/Get-JiraConfigServer.ps1 @@ -26,12 +26,11 @@ function Get-JiraConfigServer { } if (-not (Test-Path -Path $ConfigFile)) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.IO.FileNotFoundException]"Could not find $ConfigFile"), - 'ConfigFile.NotFound', - [System.Management.Automation.ErrorCategory]::ObjectNotFound, - $ConfigFile - ) + $exception = ([System.IO.FileNotFoundException]"Could not find $ConfigFile") + $errorId = 'ConfigFile.NotFound' + $errorCategory = 'ObjectNotFound' + $errorTarget = $ConfigFile + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Config file [$ConfigFile] does not exist. Use Set-JiraConfigServer first to define the configuration file." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -41,12 +40,11 @@ function Get-JiraConfigServer { $xmlConfig = $xml.DocumentElement if ($xmlConfig.LocalName -ne 'Config') { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.IO.FileFormatException]"XML had not the expected format"), - 'ConfigFile.UnexpectedElement', - [System.Management.Automation.ErrorCategory]::ParserError, - $ConfigFile - ) + $exception = ([System.IO.FileFormatException]"XML had not the expected format") + $errorId = 'ConfigFile.UnexpectedElement' + $errorCategory = ParserError + $errorTarget = $ConfigFile + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unexpected document element [$($xmlConfig.LocalName)] in configuration file [$ConfigFile]. You may need to delete the config file and recreate it using Set-JiraConfigServer." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -55,12 +53,11 @@ function Get-JiraConfigServer { Write-Output $xmlConfig.Server } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.UriFormatException]"Could not find URI"), - 'ConfigFile.EmptyElement', - [System.Management.Automation.ErrorCategory]::OpenError, - $ConfigFile - ) + $exception = ([System.UriFormatException]"Could not find URI") + $errorId = 'ConfigFile.EmptyElement' + $errorCategory = OpenError + $errorTarget = $ConfigFile + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "No Server element is defined in the config file. Use Set-JiraConfigServer to define one." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Get-JiraFilter.ps1 b/JiraPS/Public/Get-JiraFilter.ps1 index 4d1b25de..2a7789b4 100644 --- a/JiraPS/Public/Get-JiraFilter.ps1 +++ b/JiraPS/Public/Get-JiraFilter.ps1 @@ -16,12 +16,11 @@ [ValidateScript( { if (("JiraPS.Filter" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraFilter', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraFilter' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Filter. Expected [JiraPS.Filter] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraGroupMember.ps1 b/JiraPS/Public/Get-JiraGroupMember.ps1 index d204889a..8d1d7a7f 100644 --- a/JiraPS/Public/Get-JiraGroupMember.ps1 +++ b/JiraPS/Public/Get-JiraGroupMember.ps1 @@ -6,12 +6,11 @@ function Get-JiraGroupMember { [ValidateScript( { if (("JiraPS.Group" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraGroup', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraGroup' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Group. Expected [JiraPS.Group] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraIssue.ps1 b/JiraPS/Public/Get-JiraIssue.ps1 index 62ffc564..7bcd3c0b 100644 --- a/JiraPS/Public/Get-JiraIssue.ps1 +++ b/JiraPS/Public/Get-JiraIssue.ps1 @@ -12,12 +12,11 @@ function Get-JiraIssue { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -45,12 +44,11 @@ function Get-JiraIssue { [ValidateScript( { if (("JiraPS.Filter" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraFilter', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraFilter' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Filter. Expected [JiraPS.Filter] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraIssueAttachment.ps1 b/JiraPS/Public/Get-JiraIssueAttachment.ps1 index d093f11d..b766a7d9 100644 --- a/JiraPS/Public/Get-JiraIssueAttachment.ps1 +++ b/JiraPS/Public/Get-JiraIssueAttachment.ps1 @@ -6,12 +6,11 @@ function Get-JiraIssueAttachment { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraIssueComment.ps1 b/JiraPS/Public/Get-JiraIssueComment.ps1 index b61b3824..34e74445 100644 --- a/JiraPS/Public/Get-JiraIssueComment.ps1 +++ b/JiraPS/Public/Get-JiraIssueComment.ps1 @@ -6,12 +6,11 @@ function Get-JiraIssueComment { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 index d0241adb..38bd086e 100644 --- a/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueCreateMetadata.ps1 @@ -76,12 +76,11 @@ function Get-JiraIssueCreateMetadata { Write-Output (ConvertTo-JiraCreateMetaField -InputObject $result) } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"No results"), - 'IssueMetadata.ObjectNotFound', - [System.Management.Automation.ErrorCategory]::ObjectNotFound, - $Project - ) + $exception = ([System.ArgumentException]"No results") + $errorId = 'IssueMetadata.ObjectNotFound' + $errorCategory = 'ObjectNotFound' + $errorTarget = $Project + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "No metadata found for project $Project and issueType $IssueType." Throw $errorItem } diff --git a/JiraPS/Public/Get-JiraIssueEditMetadata.ps1 b/JiraPS/Public/Get-JiraIssueEditMetadata.ps1 index 2013156d..7bbfac7a 100644 --- a/JiraPS/Public/Get-JiraIssueEditMetadata.ps1 +++ b/JiraPS/Public/Get-JiraIssueEditMetadata.ps1 @@ -79,12 +79,11 @@ function Get-JiraIssueEditMetadata { Write-Output (ConvertTo-JiraEditMetaField -InputObject $result) } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"No results"), - 'IssueMetadata.ObjectNotFound', - [System.Management.Automation.ErrorCategory]::ObjectNotFound, - $Project - ) + $exception = ([System.ArgumentException]"No results") + $errorId = 'IssueMetadata.ObjectNotFound' + $errorCategory = 'ObjectNotFound' + $errorTarget = $Project + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "No metadata found for project $Project and issueType $IssueType." Throw $errorItem } diff --git a/JiraPS/Public/Get-JiraIssueLink.ps1 b/JiraPS/Public/Get-JiraIssueLink.ps1 index 99b00204..dbe9eb5c 100644 --- a/JiraPS/Public/Get-JiraIssueLink.ps1 +++ b/JiraPS/Public/Get-JiraIssueLink.ps1 @@ -25,12 +25,11 @@ function Get-JiraIssueLink { # Validate input object from Pipeline if (($_) -and ("JiraPS.IssueLink" -notin $_.PSObject.TypeNames)) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Parameter"), - 'ParameterProperties.WrongObjectType', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Id - ) + $exception = ([System.ArgumentException]"Invalid Parameter") + $errorId = 'ParameterProperties.WrongObjectType' + $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument + $errorTarget = $Id + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "The IssueLink provided did not match the constraints." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Get-JiraIssueLinkType.ps1 b/JiraPS/Public/Get-JiraIssueLinkType.ps1 index 0496b427..c6205061 100644 --- a/JiraPS/Public/Get-JiraIssueLinkType.ps1 +++ b/JiraPS/Public/Get-JiraIssueLinkType.ps1 @@ -6,12 +6,11 @@ function Get-JiraIssueLinkType { [ValidateScript( { if (("JiraPS.IssueLinkType" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String])) -and (($_ -isnot [Int]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssueLinkType', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssueLinkType' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for IssueLinkType. Expected [JiraPS.IssueLinkType], [String] or [Int], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraIssueWatcher.ps1 b/JiraPS/Public/Get-JiraIssueWatcher.ps1 index fdd9294c..d8ca1ab4 100644 --- a/JiraPS/Public/Get-JiraIssueWatcher.ps1 +++ b/JiraPS/Public/Get-JiraIssueWatcher.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlight] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Get-JiraRemoteLink.ps1 b/JiraPS/Public/Get-JiraRemoteLink.ps1 index daf3d3fc..9761cd95 100644 --- a/JiraPS/Public/Get-JiraRemoteLink.ps1 +++ b/JiraPS/Public/Get-JiraRemoteLink.ps1 @@ -6,12 +6,11 @@ function Get-JiraRemoteLink { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Invoke-JiraIssueTransition.ps1 b/JiraPS/Public/Invoke-JiraIssueTransition.ps1 index 34800310..3b7db630 100644 --- a/JiraPS/Public/Invoke-JiraIssueTransition.ps1 +++ b/JiraPS/Public/Invoke-JiraIssueTransition.ps1 @@ -6,12 +6,11 @@ function Invoke-JiraIssueTransition { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -71,12 +70,11 @@ function Invoke-JiraIssueTransition { $transitionId = [Int]"$Transition" } catch { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraTransition', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Transition - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") + $errorId = 'ParameterType.NotJiraTransition' + $errorCategory = 'InvalidArgumenty' + $errorTarget = $Transition + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTargetError $errorItem.ErrorDetails = "Wrong object type provided for Transition. Expected [JiraPS.Transition] or [Int], but was $($Transition.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -84,12 +82,11 @@ function Invoke-JiraIssueTransition { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Checking that the issue can perform the given transition" if (($issueObj.Transition.Id) -notcontains $transitionId) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid value for Parameter"), - 'ParameterValue.InvalidTransition', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Issue - ) + $exception = ([System.ArgumentException]"Invalid value for Parameter") + $errorId = 'ParameterValue.InvalidTransition' + $errorCategory = 'InvalidArgument' + $errorTarget = $Issue + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "The specified Jira issue cannot perform transition [$transitionId]. Check the issue's Transition property and provide a transition valid for its current state." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -117,12 +114,11 @@ function Invoke-JiraIssueTransition { $validAssignee = $true } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid value for Parameter"), - 'ParameterValue.InvalidAssignee', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Assignee - ) + $exception = ([System.ArgumentException]"Invalid value for Parameter") + $errorId = 'ParameterValue.InvalidAssignee' + $errorCategory = 'InvalidArgument' + $errorTarget = $Assignee + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unable to validate Jira user [$Assignee]. Use Get-JiraUser for more details." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -162,12 +158,11 @@ function Invoke-JiraIssueTransition { }) } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid value for Parameter"), - 'ParameterValue.InvalidFields', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Fields - ) + $exception = ([System.ArgumentException]"Invalid value for Parameter") + $errorId = 'ParameterValue.InvalidFields' + $errorCategory = 'InvalidArgument' + $errorTarget = $Fields + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unable to identify field [$name] from -Fields hashtable. Use Get-JiraField for more information." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/New-JiraIssue.ps1 b/JiraPS/Public/New-JiraIssue.ps1 index 57eae3b9..ab8917f1 100644 --- a/JiraPS/Public/New-JiraIssue.ps1 +++ b/JiraPS/Public/New-JiraIssue.ps1 @@ -109,12 +109,11 @@ function New-JiraIssue { $requestBody["$id"] = $value } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid value for Parameter"), - 'ParameterValue.InvalidFields', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Fields - ) + $exception = ([System.ArgumentException]"Invalid value for Parameter") + $errorId = 'ParameterValue.InvalidFields' + $errorCategory = 'InvalidArgument' + $errorTarget = $Fields + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unable to identify field [$name] from -Fields hashtable. Use Get-JiraField for more information." $PSCmdlet.ThrowTerminatingError($errorItem) } @@ -128,12 +127,11 @@ function New-JiraIssue { Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Required field (id=[$($c.Id)], name=[$($c.Name)]) was provided (value=[$($requestBody.$($c.Id))])" } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid or missing value Parameter"), - 'ParameterValue.CreateMetaFailure', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Fields - ) + $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) } diff --git a/JiraPS/Public/New-JiraVersion.ps1 b/JiraPS/Public/New-JiraVersion.ps1 index 2fceb764..7d6b19c2 100644 --- a/JiraPS/Public/New-JiraVersion.ps1 +++ b/JiraPS/Public/New-JiraVersion.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Version" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraVersion', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraVersion' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Version. Expected [JiraPS.Version] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -41,12 +40,11 @@ {"JiraPS.Project" -in $Input.PSObject.TypeNames} { return $true } {$Input -is [String]} { return $true} Default { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraProject', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Input - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraProject' + $errorCategory = 'InvalidArgument' + $errorTarget = $Input + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Project. Expected [JiraPS.Project] or [String], but was $($Input.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraGroup.ps1 b/JiraPS/Public/Remove-JiraGroup.ps1 index 5616c8a8..d4744652 100644 --- a/JiraPS/Public/Remove-JiraGroup.ps1 +++ b/JiraPS/Public/Remove-JiraGroup.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Group" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraGroup', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraGroup' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Group. Expected [JiraPS.Group] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraGroupMember.ps1 b/JiraPS/Public/Remove-JiraGroupMember.ps1 index 0adaea50..9a6c22fa 100644 --- a/JiraPS/Public/Remove-JiraGroupMember.ps1 +++ b/JiraPS/Public/Remove-JiraGroupMember.ps1 @@ -6,12 +6,11 @@ function Remove-JiraGroupMember { [ValidateScript( { if (("JiraPS.Group" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraGroup', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraGroup' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Group. Expected [JiraPS.Group] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -33,12 +32,11 @@ function Remove-JiraGroupMember { [ValidateScript( { if (("JiraPS.User" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.UotJirauser', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.UotJirauser' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for User. Expected [JiraPS.User] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraIssueAttachment.ps1 b/JiraPS/Public/Remove-JiraIssueAttachment.ps1 index 873c2b57..3586f94b 100644 --- a/JiraPS/Public/Remove-JiraIssueAttachment.ps1 +++ b/JiraPS/Public/Remove-JiraIssueAttachment.ps1 @@ -12,12 +12,11 @@ function Remove-JiraIssueAttachment { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -87,12 +86,11 @@ function Remove-JiraIssueAttachment { Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$Issue [$Issue]" if (@($Issue).Count -ne 1) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"invalid Issue provided"), - 'ParameterValue.JiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"invalid Issue provided") + $errorId = 'ParameterValue.JiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Only one Issue can be provided at a time." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Remove-JiraIssueLink.ps1 b/JiraPS/Public/Remove-JiraIssueLink.ps1 index 8b9db97f..17921300 100644 --- a/JiraPS/Public/Remove-JiraIssueLink.ps1 +++ b/JiraPS/Public/Remove-JiraIssueLink.ps1 @@ -11,12 +11,11 @@ function Remove-JiraIssueLink { {("JiraPS.Issue" -in $Input.PSObject.TypeNames) -and ("issueLinks" -in $objectProperties.Name)} { return $true } {("JiraPS.IssueLink" -in $Input.PSObject.TypeNames) -and ("Id" -in $objectProperties.Name)} { return $true } default { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Input - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $Input + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue], [JiraPS.IssueLink] or [String], but was $($Input.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraIssueWatcher.ps1 b/JiraPS/Public/Remove-JiraIssueWatcher.ps1 index cdd8492f..18ea4798 100644 --- a/JiraPS/Public/Remove-JiraIssueWatcher.ps1 +++ b/JiraPS/Public/Remove-JiraIssueWatcher.ps1 @@ -10,12 +10,11 @@ [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraRemoteLink.ps1 b/JiraPS/Public/Remove-JiraRemoteLink.ps1 index d773affe..59de01a8 100644 --- a/JiraPS/Public/Remove-JiraRemoteLink.ps1 +++ b/JiraPS/Public/Remove-JiraRemoteLink.ps1 @@ -6,12 +6,11 @@ function Remove-JiraRemoteLink { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraUser.ps1 b/JiraPS/Public/Remove-JiraUser.ps1 index 2ad6533c..121c956f 100644 --- a/JiraPS/Public/Remove-JiraUser.ps1 +++ b/JiraPS/Public/Remove-JiraUser.ps1 @@ -6,12 +6,11 @@ function Remove-JiraUser { [ValidateScript( { if (("JiraPS.User" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraUser', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraUser' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for User. Expected [JiraPS.User] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Remove-JiraVersion.ps1 b/JiraPS/Public/Remove-JiraVersion.ps1 index 3b20dc14..fac3aaf8 100644 --- a/JiraPS/Public/Remove-JiraVersion.ps1 +++ b/JiraPS/Public/Remove-JiraVersion.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Version" -notin $_.PSObject.TypeNames) -and (($_ -isnot [Int]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraVersion', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraVersion' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Version. Expected [JiraPS.Version] or [Int], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Set-JiraConfigServer.ps1 b/JiraPS/Public/Set-JiraConfigServer.ps1 index 7fad90cf..a95d7ebb 100644 --- a/JiraPS/Public/Set-JiraConfigServer.ps1 +++ b/JiraPS/Public/Set-JiraConfigServer.ps1 @@ -44,12 +44,11 @@ function Set-JiraConfigServer { $xmlConfig = $xml.DocumentElement if ($xmlConfig.LocalName -ne 'Config') { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Document"), - 'InvalidObject.InvalidDocument', - [System.Management.Automation.ErrorCategory]::InvalidData, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Document") + $errorId = 'InvalidObject.InvalidDocument' + $errorCategory = 'InvalidData' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unexpected document element [$($xmlConfig.LocalName)] in configuration file. You may need to delete the config file and recreate it using this function." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Set-JiraIssue.ps1 b/JiraPS/Public/Set-JiraIssue.ps1 index 81c03511..337c0132 100644 --- a/JiraPS/Public/Set-JiraIssue.ps1 +++ b/JiraPS/Public/Set-JiraIssue.ps1 @@ -6,12 +6,11 @@ function Set-JiraIssue { [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -90,12 +89,11 @@ function Set-JiraIssue { $validAssignee = $true } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid value for Parameter"), - 'ParameterValue.InvalidAssignee', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Assignee - ) + $exception = ([System.ArgumentException]"Invalid value for Parameter") + $errorId = 'ParameterValue.InvalidAssignee' + $errorCategory = 'InvalidArgument' + $errorTarget = $Assignee + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Unable to validate Jira user [$Assignee]. Use Get-JiraUser for more details." $PSCmdlet.ThrowTerminatingError($errorItem) } diff --git a/JiraPS/Public/Set-JiraIssueLabel.ps1 b/JiraPS/Public/Set-JiraIssueLabel.ps1 index 11b8a7b4..8fde41fa 100644 --- a/JiraPS/Public/Set-JiraIssueLabel.ps1 +++ b/JiraPS/Public/Set-JiraIssueLabel.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Issue" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraIssue', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraIssue' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Issue. Expected [JiraPS.Issue] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# diff --git a/JiraPS/Public/Set-JiraUser.ps1 b/JiraPS/Public/Set-JiraUser.ps1 index 69029ff4..93ef46ff 100644 --- a/JiraPS/Public/Set-JiraUser.ps1 +++ b/JiraPS/Public/Set-JiraUser.ps1 @@ -6,12 +6,11 @@ function Set-JiraUser { [ValidateScript( { if (("JiraPS.User" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraUser', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraUser' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for User. Expected [JiraPS.User] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -41,12 +40,11 @@ function Set-JiraUser { return $true } else { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Argument"), - 'ParameterValue.NotEmail', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $Issue - ) + $exception = ([System.ArgumentException]"Invalid Argument") #fix code highlighting] + $errorId = 'ParameterValue.NotEmail' + $errorCategory = 'InvalidArgument' + $errorTarget = $Issue + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "The value provided does not look like an email address." $PSCmdlet.ThrowTerminatingError($errorItem) return $false diff --git a/JiraPS/Public/Set-JiraVersion.ps1 b/JiraPS/Public/Set-JiraVersion.ps1 index 4c74e244..3a96f82d 100644 --- a/JiraPS/Public/Set-JiraVersion.ps1 +++ b/JiraPS/Public/Set-JiraVersion.ps1 @@ -6,12 +6,11 @@ [ValidateScript( { if (("JiraPS.Version" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraVersion', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraVersion' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Version. Expected [JiraPS.Version] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# @@ -48,12 +47,11 @@ [ValidateScript( { if (("JiraPS.Project" -notin $_.PSObject.TypeNames) -and (($_ -isnot [String]))) { - $errorItem = [System.Management.Automation.ErrorRecord]::new( - ([System.ArgumentException]"Invalid Type for Parameter"), - 'ParameterType.NotJiraProject', - [System.Management.Automation.ErrorCategory]::InvalidArgument, - $_ - ) + $exception = ([System.ArgumentException]"Invalid Type for Parameter") #fix code highlighting] + $errorId = 'ParameterType.NotJiraProject' + $errorCategory = 'InvalidArgument' + $errorTarget = $_ + $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Wrong object type provided for Project. Expected [JiraPS.Project] or [String], but was $($_.GetType().Name)" $PSCmdlet.ThrowTerminatingError($errorItem) <# From cb4c8080500cd5c4d9de11bf3fe42644c4ead621 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Wed, 30 May 2018 09:03:22 +0200 Subject: [PATCH 4/6] Fixed exporting of function alias in dev environment --- JiraPS/JiraPS.psm1 | 2 +- Tests/Get-JiraServerInformation.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/JiraPS/JiraPS.psm1 b/JiraPS/JiraPS.psm1 index c4cac996..0a4d6fa4 100644 --- a/JiraPS/JiraPS.psm1 +++ b/JiraPS/JiraPS.psm1 @@ -34,5 +34,5 @@ foreach ($file in @($PublicFunctions + $PrivateFunctions)) { throw $_ } } -Export-ModuleMember -Function $PublicFunctions.BaseName +Export-ModuleMember -Function $PublicFunctions.BaseName -Alias * #endregion LoadFunctions diff --git a/Tests/Get-JiraServerInformation.Tests.ps1 b/Tests/Get-JiraServerInformation.Tests.ps1 index cddd5c1d..55bdfe0c 100644 --- a/Tests/Get-JiraServerInformation.Tests.ps1 +++ b/Tests/Get-JiraServerInformation.Tests.ps1 @@ -49,7 +49,7 @@ Describe "Get-JiraServerInformation" { It "Answers to the alias 'Get-JiraServerInfo'" { $thisAlias = (Get-Alias -Name "Get-JiraServerInfo") $thisAlias.ResolvedCommandName | Should Be "Get-JiraServerInformation" - $thisAlias.Source | Should Be "JiraPS" + $thisAlias.ModuleName | Should Be "JiraPS" } } } From b19123c337dd7ebe4d0f3534a35cdfe6054f1628 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Wed, 30 May 2018 10:55:57 +0200 Subject: [PATCH 5/6] Skip PSSciptAnalyzer, as it is not working in PSv3 --- Tests/JiraPS.Tests.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Tests/JiraPS.Tests.ps1 b/Tests/JiraPS.Tests.ps1 index 4a8ed5bd..635e734e 100644 --- a/Tests/JiraPS.Tests.ps1 +++ b/Tests/JiraPS.Tests.ps1 @@ -183,16 +183,18 @@ Describe "JiraPS" { } Context 'PSScriptAnalyzer Rules' { - Import-Module $manifestFile -Force -ErrorAction Stop + if ($PSVersionTable.PSVersion.Major -gt 3) { + Import-Module $manifestFile -Force -ErrorAction Stop - $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse -Settings "$projectRoot/PSScriptAnalyzerSettings.psd1" - $scriptAnalyzerRules = Get-ScriptAnalyzerRule + $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse -Settings "$projectRoot/PSScriptAnalyzerSettings.psd1" + $scriptAnalyzerRules = Get-ScriptAnalyzerRule - forEach ($rule in $scriptAnalyzerRules) { - It "Should pass $rule" { - if (($analysis) -and ($analysis.RuleName -contains $rule)) { - $analysis | Where-Object RuleName -eq $rule -OutVariable failures | Out-Default - $failures.Count | Should Be 0 + forEach ($rule in $scriptAnalyzerRules) { + It "Should pass $rule" { + if (($analysis) -and ($analysis.RuleName -contains $rule)) { + $analysis | Where-Object RuleName -eq $rule -OutVariable failures | Out-Default + $failures.Count | Should Be 0 + } } } } From 5677a3b584a100062cf8267c7b02520f82344585 Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Wed, 30 May 2018 12:45:10 +0200 Subject: [PATCH 6/6] Removed debugging code --- JiraPS/JiraPS.psm1 | 3 +-- JiraPS/Public/Invoke-JiraMethod.ps1 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/JiraPS/JiraPS.psm1 b/JiraPS/JiraPS.psm1 index 0a4d6fa4..c251e311 100644 --- a/JiraPS/JiraPS.psm1 +++ b/JiraPS/JiraPS.psm1 @@ -30,8 +30,7 @@ foreach ($file in @($PublicFunctions + $PrivateFunctions)) { $errorTarget = $file $errorItem = New-Object -TypeName System.Management.Automation.ErrorRecord $exception, $errorId, $errorCategory, $errorTarget $errorItem.ErrorDetails = "Failed to import function $($file.BaseName)" - # throw $errorItem - throw $_ + throw $errorItem } } Export-ModuleMember -Function $PublicFunctions.BaseName -Alias * diff --git a/JiraPS/Public/Invoke-JiraMethod.ps1 b/JiraPS/Public/Invoke-JiraMethod.ps1 index 4312fa0f..2cecd952 100644 --- a/JiraPS/Public/Invoke-JiraMethod.ps1 +++ b/JiraPS/Public/Invoke-JiraMethod.ps1 @@ -48,7 +48,7 @@ function Invoke-JiraMethod { "Accept-Charset" = "utf-8" } # Bug in PSv3's .Net API - if ($PSVersionTable.PSVersion.Major -eq 3) { + if ($PSVersionTable.PSVersion.Major -gt 3) { $_headers["Accept"] = "application/json" } foreach ($item in $Headers.Key) { $_headers[$item] = $Headers[$item] }