Skip to content

Commit 04d131b

Browse files
committed
Fix pipelining for Get-MantisIssue
1 parent ba797e5 commit 04d131b

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

mantis.psm1

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ using namespace System.Web.Http;
3131
.Example
3232
# Get second page of issues with custom page size
3333
Get-MantisIssue -page 2 -pageSize 50
34+
35+
.Example
36+
# Get multiple issues
37+
@(1, 2, 3) | Get-MantisIssue
3438
#>
3539
function Get-MantisIssue {
3640
param(
@@ -39,29 +43,32 @@ param(
3943
[int] $page,
4044
[int] $pageSize
4145
)
46+
Begin {
47+
$instance = getInstance
48+
$headers = getCommonHeaders
49+
50+
# Handle getting a batch of issues
51+
if( -not $PSBoundParameters.ContainsKey( "page" ) ) {
52+
$page = 1
53+
}
4254

43-
$instance = getInstance
44-
$headers = getCommonHeaders
45-
46-
# Handle getting a single issue
47-
if( $id -ne 0 ) {
48-
$uri = $instance.uri + "issues/" + $id
49-
$result = Invoke-RestMethod -Uri $uri -Headers $headers
50-
return $result.issues[0]
51-
}
52-
53-
# Handle getting a batch of issues
54-
if( -not $PSBoundParameters.ContainsKey( "page" ) ) {
55-
$page = 1
55+
if( -not $PSBoundParameters.ContainsKey( "pageSize" ) ) {
56+
$pageSize = 25
57+
}
5658
}
5759

58-
if( -not $PSBoundParameters.ContainsKey( "pageSize" ) ) {
59-
$pageSize = 25
60+
Process {
61+
# Handle getting a single issue
62+
if( $id -ne 0 ) {
63+
$uri = $instance.uri + "issues/" + $id
64+
$result = Invoke-RestMethod -Uri $uri -Headers $headers
65+
Write-Output $result.issues[0]
66+
} else {
67+
$uri = $instance.uri + "issues/?page=" + $page + "&page_size=" + $pageSize
68+
$result = Invoke-RestMethod -Uri $uri -Headers $headers
69+
$result.issues | Write-Output
70+
}
6071
}
61-
62-
$uri = $instance.uri + "issues/?page=" + $page + "&page_size=" + $pageSize
63-
$result = Invoke-RestMethod -Uri $uri -Headers $headers
64-
return $result.issues
6572
}
6673

6774
<#

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Importing the file
9898

9999
Get-MantisIssue 1
100100

101+
## Getting multiple issues by id
102+
103+
@(1, 2, 3) | Get-MantisIssue
104+
101105
## Get issue history by id
102106

103107
$issue = Get-MantisIssue 1

0 commit comments

Comments
 (0)