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 compatibility with PS v3 #273

Merged
merged 6 commits into from
May 30, 2018
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
13 changes: 6 additions & 7 deletions JiraPS/JiraPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +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
}
}
Export-ModuleMember -Function $PublicFunctions.BaseName
Export-ModuleMember -Function $PublicFunctions.BaseName -Alias *
#endregion LoadFunctions
6 changes: 3 additions & 3 deletions JiraPS/Private/Invoke-WebRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Invoke-WebRequest {

[pscredential]
[System.Management.Automation.CredentialAttribute()]
${Credential},
${Credential} = [System.Management.Automation.PSCredential]::Empty,

[switch]
${UseDefaultCredentials},
Expand Down Expand Up @@ -68,7 +68,7 @@ function Invoke-WebRequest {

[pscredential]
[System.Management.Automation.CredentialAttribute()]
${ProxyCredential},
${ProxyCredential} = [System.Management.Automation.PSCredential]::Empty,

[switch]
${ProxyUseDefaultCredentials},
Expand All @@ -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)
))
Expand Down
22 changes: 10 additions & 12 deletions JiraPS/Private/Resolve-JiraError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Private/Resolve-JiraIssueObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
33 changes: 15 additions & 18 deletions JiraPS/Public/Add-JiraIssueAttachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Public/Add-JiraIssueComment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand Down
22 changes: 10 additions & 12 deletions JiraPS/Public/Add-JiraIssueLink.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand All @@ -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)
<#
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Public/Add-JiraIssueWatcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Public/Add-JiraIssueWorklog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Public/Get-JiraComponent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand Down
33 changes: 15 additions & 18 deletions JiraPS/Public/Get-JiraConfigServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions JiraPS/Public/Get-JiraFilter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<#
Expand Down
Loading