Skip to content

Commit

Permalink
Release v2.7
Browse files Browse the repository at this point in the history
Merge pull request #258 from AtlassianPS/develop
  • Loading branch information
lipkau committed May 13, 2018
2 parents 30ec214 + d01aff4 commit 3a3a811
Show file tree
Hide file tree
Showing 19 changed files with 279 additions and 58 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Change Log

## 2.7 - 2018-05-13

More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.7.html).

### IMPROVEMENTS

- Writing and throwing of errors show better context (#199, [@lipkau][])
- Improved validation of parameters in `Add-JiraGroupMember` (#250, [@WindowsAdmin92][])
- Improved casting to `-Fields` by defining it's type as `[PSCustomObject]` (#255, [@lipkau][])
- Several improvements to the CI pipeline (#252, #257, [@lipkau][])

### BUG FIXES

- Build script was not publishing to the PSGallery (#252, [@lipkau][])
- Build script was publishing a new tag to repository even in case the build failed (#252, [@lipkau][])
- Fixed the adding multiple labels and the removal of those in `Set-JiraIssueLabel` (#244, [@lipkau][])
- Fixed CI icon in README (#245, [@lipkau][])
- Allow `Get-JiraUser` to return more than 1 result (#246, [@lipkau][])

## 2.6 - 2018-05-02

More detailed description about the changes can be found on [Our Website](https://atlassianps.org/article/announcement/JiraPS-v2.6.html).
Expand Down Expand Up @@ -246,3 +265,4 @@ which is in turn inspired by the [Vagrant](https://github.com/mitchellh/vagrant/
[@lukhase]: https://github.com/lukhase
[@padgers]: https://github.com/padgers
[@ThePSAdmin]: https://github.com/ThePSAdmin
[@WindowsAdmin92]: https://github.com/WindowsAdmin92
36 changes: 35 additions & 1 deletion JiraPS.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ task Test Init, {
OutputFormat = "NUnitXml"
CodeCoverage = $codeCoverageFiles
}
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$parameter["Show"] = "Fails"
}
$testResults = Invoke-Pester @parameter

If ('AppVeyor' -eq $env:BHBuildSystem) {
Expand All @@ -217,7 +220,7 @@ task Test Init, {

#region Publish
# Synopsis: Publish a new release on github and the PSGallery
task Deploy -If { Test-ShouldDeploy } Init, PublishToGallery, TagReplository
task Deploy -If { Test-ShouldDeploy } Init, PublishToGallery, TagReplository, UpdateHomepage

# Synipsis: Publish the $release to the PSGallery
task PublishToGallery {
Expand Down Expand Up @@ -249,6 +252,37 @@ task TagReplository GetNextVersion, {
$uploadURI = $releaseResponse.upload_url -replace "\{\?name,label\}", "?name=$($packageFile.Name)"
$null = Publish-GithubReleaseArtifact -Uri $uploadURI -Path $packageFile
}

# Synopsis: Update the version of this module that the homepage uses
task UpdateHomepage {
try {
Write-Build Gray "git close .../AtlassianPS.github.io --recursive"
cmd /c "git clone https://github.com/AtlassianPS/AtlassianPS.github.io --recursive 2>&1"

Push-Location "AtlassianPS.github.io/"

Write-Build Gray "git submodule foreach git pull origin master"
cmd /c "git submodule foreach git pull origin master 2>&1"

Write-Build Gray "git status -s"
$status = cmd /c "git status -s 2>&1"

Write-Build Gray $status
if ($status -contains " M modules/$env:BHProjectName") {
Write-Build Gray "git add modules/$env:BHProjectName"
cmd /c "git add modules/$env:BHProjectName 2>&1"

Write-Build Gray "git commit -m `"Update module $PROJECT_NAME`""
cmd /c "git commit -m `"Update module $PROJECT_NAME`" 2>&1"

Write-Build Gray "git push"
cmd /c "git push 2>&1"
}

Pop-Location
}
catch {}
}
#endregion Publish

#region Cleaning tasks
Expand Down
2 changes: 1 addition & 1 deletion JiraPS/JiraPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'JiraPS.psm1'

# Version number of this module.
ModuleVersion = '2.6'
ModuleVersion = '2.7'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
8 changes: 5 additions & 3 deletions JiraPS/Private/Resolve-JiraError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
[Switch]
$WriteError,

$Caller = $PSCmdlet
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$Cmdlet = $PSCmdlet
)

process {
Expand All @@ -26,7 +28,7 @@
$i
)
$errorItem.ErrorDetails = "Jira encountered an error: [$e]"
$Caller.WriteError($errorItem)
$Cmdlet.WriteError($errorItem)
}
else {
$obj = [PSCustomObject] @{
Expand All @@ -53,7 +55,7 @@
$i
)
$errorItem.ErrorDetails = "Jira encountered an error: [$k] - $($i.errors.$k)"
$Caller.WriteError($errorItem)
$Cmdlet.WriteError($errorItem)
}
else {
$obj = [PSCustomObject] @{
Expand Down
34 changes: 0 additions & 34 deletions JiraPS/Private/Test-Captcha.ps1

This file was deleted.

69 changes: 69 additions & 0 deletions JiraPS/Private/Test-ServerResponse.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function Test-ServerResponse {
[CmdletBinding()]
<#
.SYNOPSIS
Evauluate the response of the API call
.LINK
https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/bc/security/login/LoginReason.html
#>
param (
# Response of Invoke-WebRequest
[Parameter( ValueFromPipeline )]
[PSObject]$InputObject,

[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$Cmdlet = $PSCmdlet
)

begin {
$loginReasonKey = "X-Seraph-LoginReason"
}

process {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Checking response headers for authentication errors"
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] Investigating `$InputObject.Headers['$loginReasonKey']"

if ($InputObject.Headers -and $InputObject.Headers[$loginReasonKey]) {
$loginReason = $InputObject.Headers[$loginReasonKey] -split ","

switch ($true) {
{$loginReason -contains "AUTHENTICATED_FAILED"} {
$errorParameter = @{
ExceptionType = "System.Net.Http.HttpRequestException"
Message = "The user could not be authenticated."
ErrorId = "AuthenticationFailed"
Category = "AuthenticationError"
Cmdlet = $Cmdlet
}
ThrowError @errorParameter
}
{$loginReason -contains "AUTHENTICATION_DENIED"} {
$errorParameter = @{
ExceptionType = "System.Net.Http.HttpRequestException"
Message = "For security reasons Jira requires you to log on to the website before continuing."
ErrorId = "AuthenticaionDenied"
Category = "AuthenticationError"
Cmdlet = $Cmdlet
}
ThrowError @errorParameter
}
{$loginReason -contains "AUTHORISATION_FAILED"} {
$errorParameter = @{
ExceptionType = "System.Net.Http.HttpRequestException"
Message = "The user could not be authorised."
ErrorId = "AuthorisationFailed"
Category = "AuthenticationError"
Cmdlet = $Cmdlet
}
ThrowError @errorParameter
}
{$loginReason -contains "OK"} {} # The login was OK
{$loginReason -contains "OUT"} {} # This indicates that person has in fact logged "out"
}
}
}

end {
}
}
65 changes: 65 additions & 0 deletions JiraPS/Private/ThrowError.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function ThrowError {
<#
.SYNOPSIS
Utility to throw a terminating errorrecord
.NOTES
Thanks to Jaykul:
https://github.com/PoshCode/Configuration/blob/master/Source/Metadata.psm1
#>
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$Cmdlet = $((Get-Variable -Scope 1 PSCmdlet).Value),

[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = "NewException")]
[ValidateNotNullOrEmpty()]
[System.Exception]
$Exception,

[Parameter(ParameterSetName = "NewException", Position = 2)]
[ValidateNotNullOrEmpty()]
[System.String]
$ExceptionType = "System.Management.Automation.RuntimeException",

[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 3)]
[ValidateNotNullOrEmpty()]
[System.String]
$Message,

[Parameter(Mandatory = $false)]
[System.Object]
$TargetObject,

[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 10)]
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 10)]
[ValidateNotNullOrEmpty()]
[System.String]
$ErrorId,

[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 11)]
[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 11)]
[ValidateNotNull()]
[System.Management.Automation.ErrorCategory]
$Category,

[Parameter(Mandatory = $true, ParameterSetName = "Rethrow", Position = 1)]
[System.Management.Automation.ErrorRecord]$ErrorRecord
)
process {
if (!$ErrorRecord) {
if ($PSCmdlet.ParameterSetName -eq "NewException") {
if ($Exception) {
$Exception = New-Object $ExceptionType $Message, $Exception
}
else {
$Exception = New-Object $ExceptionType $Message
}
}
$errorRecord = New-Object System.Management.Automation.ErrorRecord $Exception, $ErrorId, $Category, $TargetObject
}
$Cmdlet.ThrowTerminatingError($errorRecord)
}
}
63 changes: 63 additions & 0 deletions JiraPS/Private/WriteError.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
function WriteError {
<#
.SYNOPSIS
Utility to write an errorrecord to the errstd
.NOTES
Thanks to Jaykul:
https://github.com/PoshCode/Configuration/blob/master/Source/Metadata.psm1
#>
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$Cmdlet = $((Get-Variable -Scope 1 PSCmdlet).Value),

[Parameter(Mandatory = $true, ParameterSetName = "ExistingException", Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = "NewException")]
[ValidateNotNullOrEmpty()]
[System.Exception]
$Exception,

[Parameter(ParameterSetName = "NewException", Position = 2)]
[ValidateNotNullOrEmpty()]
[System.String]
$ExceptionType = "System.Management.Automation.RuntimeException",

[Parameter(Mandatory = $true, ParameterSetName = "NewException", Position = 3)]
[ValidateNotNullOrEmpty()]
[System.String]
$Message,

[Parameter(Mandatory = $false)]
[System.Object]
$TargetObject,

[Parameter(Mandatory = $true, Position = 10)]
[ValidateNotNullOrEmpty()]
[System.String]
$ErrorId,

[Parameter(Mandatory = $true, Position = 11)]
[ValidateNotNull()]
[System.Management.Automation.ErrorCategory]
$Category,

[Parameter(Mandatory = $true, ParameterSetName = "Rethrow", Position = 1)]
[System.Management.Automation.ErrorRecord]$ErrorRecord
)
process {
if (!$ErrorRecord) {
if ($PSCmdlet.ParameterSetName -eq "NewException") {
if ($Exception) {
$Exception = New-Object $ExceptionType $Message, $Exception
}
else {
$Exception = New-Object $ExceptionType $Message
}
}
$errorRecord = New-Object System.Management.Automation.ErrorRecord $Exception, $ErrorId, $Category, $TargetObject
}
$Cmdlet.WriteError($errorRecord)
}
}
2 changes: 1 addition & 1 deletion JiraPS/Public/Invoke-JiraIssueTransition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Invoke-JiraIssueTransition {
[Object]
$Transition,

[System.Collections.Hashtable]
[PSCustomObject]
$Fields,

[Object]
Expand Down
9 changes: 5 additions & 4 deletions JiraPS/Public/Invoke-JiraMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function Invoke-JiraMethod {
[PSCredential]
$Credential,

$Caller = $PSCmdlet
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCmdlet]
$Cmdlet = $PSCmdlet
)

begin {
Expand Down Expand Up @@ -121,8 +123,7 @@ function Invoke-JiraMethod {
}
}

# Test response Headers if Confluence requires a CAPTCHA
Test-Captcha -InputObject $webResponse -Caller $Caller
Test-ServerResponse -InputObject $webResponse -Cmdlet $Cmdlet

Write-Debug "[$($MyInvocation.MyCommand.Name)] Executed WebRequest. Access `$webResponse to see details"

Expand Down Expand Up @@ -172,7 +173,7 @@ function Invoke-JiraMethod {

if ($result) {
if (Get-Member -Name "Errors" -InputObject $result -ErrorAction SilentlyContinue) {
Resolve-JiraError $result -WriteError -Caller $Caller
Resolve-JiraError $result -WriteError -Cmdlet $Cmdlet
}
else {
Write-Output $result
Expand Down
Loading

0 comments on commit 3a3a811

Please sign in to comment.