Skip to content

Commit

Permalink
Fix pipelining for Get-MantisIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Nov 23, 2017
1 parent ba797e5 commit 04d131b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
45 changes: 26 additions & 19 deletions mantis.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ using namespace System.Web.Http;
.Example
# Get second page of issues with custom page size
Get-MantisIssue -page 2 -pageSize 50
.Example
# Get multiple issues
@(1, 2, 3) | Get-MantisIssue
#>
function Get-MantisIssue {
param(
Expand All @@ -39,29 +43,32 @@ param(
[int] $page,
[int] $pageSize
)
Begin {
$instance = getInstance
$headers = getCommonHeaders

# Handle getting a batch of issues
if( -not $PSBoundParameters.ContainsKey( "page" ) ) {
$page = 1
}

$instance = getInstance
$headers = getCommonHeaders

# Handle getting a single issue
if( $id -ne 0 ) {
$uri = $instance.uri + "issues/" + $id
$result = Invoke-RestMethod -Uri $uri -Headers $headers
return $result.issues[0]
}

# Handle getting a batch of issues
if( -not $PSBoundParameters.ContainsKey( "page" ) ) {
$page = 1
if( -not $PSBoundParameters.ContainsKey( "pageSize" ) ) {
$pageSize = 25
}
}

if( -not $PSBoundParameters.ContainsKey( "pageSize" ) ) {
$pageSize = 25
Process {
# Handle getting a single issue
if( $id -ne 0 ) {
$uri = $instance.uri + "issues/" + $id
$result = Invoke-RestMethod -Uri $uri -Headers $headers
Write-Output $result.issues[0]
} else {
$uri = $instance.uri + "issues/?page=" + $page + "&page_size=" + $pageSize
$result = Invoke-RestMethod -Uri $uri -Headers $headers
$result.issues | Write-Output
}
}

$uri = $instance.uri + "issues/?page=" + $page + "&page_size=" + $pageSize
$result = Invoke-RestMethod -Uri $uri -Headers $headers
return $result.issues
}

<#
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Importing the file

Get-MantisIssue 1

## Getting multiple issues by id

@(1, 2, 3) | Get-MantisIssue

## Get issue history by id

$issue = Get-MantisIssue 1
Expand Down

0 comments on commit 04d131b

Please sign in to comment.