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

Feature/issue history - make retrieval of history dependent on GetHistory argument/parameters switch #441

Open
wants to merge 2 commits into
base: release/2.15-alpha
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion JiraPS/Private/ConvertFrom-Json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if ($PSVersionTable.PSVersion.Major -lt 6) {
$pairObjectValue = ConvertFrom-Collection $pairObjectValue
}

$returnObject | Add-Member Noteproperty $key $pairObjectValue
$returnObject | Add-Member Noteproperty $key $pairObjectValue -ErrorAction Ignore
}

return $returnObject
Expand Down
8 changes: 7 additions & 1 deletion JiraPS/Private/ConvertTo-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ function ConvertTo-JiraIssue {
}

if ($i.fields.project) {
$props.Project = ConvertTo-JiraProject -InputObject $i.fields.project
$props["Project"] = ConvertTo-JiraProject -InputObject $i.fields.project
}

if ($i.changelog) {
$props["History"] = foreach ($entry in $i.changelog.histories) {
ConvertTo-JiraIssueHistoryEntry -InputObject $entry
}
}

foreach ($field in $userFields) {
Expand Down
29 changes: 29 additions & 0 deletions JiraPS/Private/ConvertTo-JiraIssueHistoryEntry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function ConvertTo-JiraIssueHistoryEntry {
[CmdletBinding()]
param(
[Parameter( ValueFromPipeline )]
[PSObject[]]
$InputObject
)

process {
foreach ($i in $InputObject) {
Write-Debug "[$($MyInvocation.MyCommand.Name)] Converting `$InputObject to custom object"

$props = @{
'ID' = $i.id
'Author' = ConvertTo-JiraUser $i.author
'Created' = Get-Date $i.created
'Items' = $i.items
}

$result = New-Object -TypeName PSObject -Property $props
$result.PSObject.TypeNames.Insert(0, 'JiraPS.IssueHistoryEntry')
$result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value {
Write-Output "$($this.Id)"
}

Write-Output $result
}
}
}
15 changes: 11 additions & 4 deletions JiraPS/Public/Get-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ function Get-JiraIssue {
[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty
$Credential = [System.Management.Automation.PSCredential]::Empty,

[Parameter()]
[Switch][Bool]$GetHistory
)

begin {
Expand All @@ -113,6 +116,7 @@ function Get-JiraIssue {
Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$_key [$_key]"

$getParameter = @{ expand = "transitions" }
if ($GetHistory -eq $true) { $getParameter = @{ expand = "transitions,changelog" }}
if ($Fields) {
$getParameter["fields"] = $Fields
}
Expand Down Expand Up @@ -140,13 +144,15 @@ function Get-JiraIssue {
}
}
'ByJQL' {
$expandValue = "transitions"
if ($GetHistory -eq $true) { $expandValue = "transitions,changelog" }
$parameter = @{
URI = $searchURi
Method = "GET"
GetParameter = @{
jql = (ConvertTo-URLEncoded $Query)
validateQuery = $true
expand = "transitions"
expand = $expandValue
maxResults = $PageSize

}
Expand Down Expand Up @@ -181,13 +187,14 @@ function Get-JiraIssue {
#ToDo:CustomClass
Once we have custom classes, this will no longer be necessary
#>

$expandValue = "transitions"
if ($GetHistory -eq $true) { $expandValue = "transitions,changelog" }
$parameter = @{
URI = $filterObj
Method = "GET"
GetParameter = @{
validateQuery = $true
expand = "transitions"
expand = $expandvalue
maxResults = $PageSize
}
OutputType = "JiraIssue"
Expand Down
61 changes: 61 additions & 0 deletions JiraPS/Public/Get-JiraStatus.ps1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing documentation docs/en-US/commands/Get-JiraStatus.md and tests Tests/Functions/Get-JiraStatus.Unit.Tests.ps1.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Get-JiraStatus {
# .ExternalHelp ..\JiraPS-help.xml
[CmdletBinding( DefaultParameterSetName = '_All' )]
param(
[Parameter( Mandatory, ValueFromPipeline, ParameterSetName = '_Search' )]
[String[]]
$IdOrName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename variable to $Status to be analog to similar implementations.
eg JiraPS/Public/Get-JiraField.ps1

The documentations should elaborate on what values are allowed to be used for the parameter.


[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty
)

begin {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started"

$server = Get-JiraConfigServer -ErrorAction Stop

$resourceURi = "$server/rest/api/latest/status{0}"
}

process {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

switch ($PSCmdlet.ParameterSetName) {
'_All' {
$parameter = @{
URI = $resourceURi -f ""
Method = "GET"
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
$result = Invoke-JiraMethod @parameter

Write-Output (ConvertTo-JiraStatus -InputObject $result)
}
'_Search' {
foreach ($item in $IdOrName) {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Processing [$item]"
Write-Debug "[$($MyInvocation.MyCommand.Name)] Processing `$item [$item]"

$parameter = @{
URI = $resourceURi -f "/$item"
Method = "GET"
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
$result = Invoke-JiraMethod @parameter

Write-Output (ConvertTo-JiraStatus -InputObject $result)
}
}
}
}

end {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete"
}
}
Loading