Skip to content

Commit 5171568

Browse files
Merge pull request #112 from StartAutomating/Invoke-ADORestAPI-Fix
Invoke-ADORestAPI: Fixing #111
2 parents a8ba573 + 92002ea commit 5171568

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

Invoke-ADORestAPI.ps1

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,28 @@ Specifies the method used for the web request. The acceptable values for this pa
157157
)
158158

159159
begin {
160+
# From [Irregular](https://github.com/StartAutomating/Irregular):
161+
# ?<REST_Variable> -VariableFormat Braces
160162
$RestVariable = [Regex]::new(@'
161-
# Matches URL segments and query strings containing variables.
162-
# Variables can be enclosed in brackets or curly braces, or preceeded by a $ or :
163163
(?> # A variable can be in a URL segment or subdomain
164164
(?<Start>[/\.]) # Match the <Start>ing slash|dot ...
165165
(?<IsOptional>\?)? # ... an optional ? (to indicate optional) ...
166166
(?:
167-
\{(?<Variable>\w+)\}| # ... A <Variable> name in {} OR
168-
\[(?<Variable>\w+)\]| # A <Variable> name in [] OR
169-
`\$(?<Variable>\w+) | # A `$ followed by a <Variable> OR
170-
\:(?<Variable>\w+) # A : followed by a <Variable>
167+
\{(?<Variable>\w+)\} # ... A <Variable> name in {} OR
171168
)
172169
|
173-
(?<IsOptional> # If it's optional it can also be
170+
(?<IsOptional> # If it's optional it can also be
174171
[{\[](?<Start>/) # a bracket or brace, followed by a slash
175172
)
176173
(?<Variable>\w+)[}\]] # then a <Variable> name followed by } or ]
174+
177175
| # OR it can be in a query parameter:
178-
(?<Start>[?&]) # Match The <Start>ing ? or & ...
179-
(?<Query>[\w\-]+) # ... the <Query> parameter name ...
176+
(?<Start>[\?\&]) # Match The <Start>ing ? or & ...
177+
(?<Query>[\$\w\-]+) # ... the <Query> parameter name ...
180178
= # ... an equals ...
181179
(?<IsOptional>\?)? # ... an optional ? (to indicate optional) ...
182180
(?:
183-
\{(?<Variable>\w+)\}| # ... A <Variable> name in {} OR
184-
\[(?<Variable>\w+)\]| # A <Variable> name in [] OR
185-
\`$(?<Variable>\w+) | # A $ followed by a <Variable> OR
186-
\:(?<Variable>\w+) # A : followed by a <Variable>
181+
\{(?<Variable>\w+)\} # ... A <Variable> name in {} OR
187182
)
188183
)
189184
'@, 'IgnoreCase,IgnorePatternWhitespace')
@@ -377,7 +372,7 @@ $($MyInvocation.MyCommand.Name) @parameter
377372
$streamIn.Dispose()
378373
$PSCmdlet.WriteError(
379374
[Management.Automation.ErrorRecord]::new(
380-
[Exception]::new($strResponse, $ex.Exception.InnerException
375+
[Exception]::new("$($ex.Exception.InnerException.Response.StatusCode, $ex.Exception.InnerException.Response.StatusDescription)$strResponse ", $ex.Exception.InnerException
381376
), $ex.Exception.HResult, 'NotSpecified', $webRequest)
382377
)
383378
return
@@ -402,7 +397,7 @@ $($MyInvocation.MyCommand.Name) @parameter
402397
if ($AsByte) {
403398
$ms = [IO.MemoryStream]::new()
404399
$rs.CopyTo($ms)
405-
$ms.ToArray()
400+
,$ms.ToArray()
406401
$ms.Dispose()
407402
return
408403
}
@@ -424,6 +419,9 @@ $($MyInvocation.MyCommand.Name) @parameter
424419
$null = $null
425420
# We call Invoke-RestMethod with the parameters we've passed in.
426421
# It will take care of converting the results from JSON.
422+
if ($response -is [byte[]]) {
423+
return $response
424+
}
427425

428426
$apiOutput =
429427
$response |
@@ -434,7 +432,7 @@ $($MyInvocation.MyCommand.Name) @parameter
434432
# A lot of things in the Azure DevOps REST apis come back as a count/value pair
435433
if ($in -eq 'null') {
436434
return
437-
}
435+
}
438436
if ($ExpandProperty) {
439437
if ($in.$ExpandProperty) {
440438
return $in.$ExpandProperty
@@ -456,7 +454,7 @@ $($MyInvocation.MyCommand.Name) @parameter
456454

457455

458456
$in = $_
459-
if ($in -is [string]) { return $in }
457+
if ($in -is [string]) { return $in }
460458
if ($null -ne $in.Count -and $in.Count -eq 0) {
461459
return
462460
}

PSDevOps.psd1

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.5.4'
2+
ModuleVersion = '0.5.4.1'
33
RootModule = 'PSDevOps.psm1'
44
Description = 'PowerShell Tools for DevOps'
55
Guid = 'e6b56c5f-41ac-4ba4-8b88-2c063f683176'
@@ -9,6 +9,11 @@
99
ProjectURI = 'https://github.com/StartAutomating/PSDevOps'
1010
LicenseURI = 'https://github.com/StartAutomating/PSDevOps/blob/master/LICENSE'
1111
ReleaseNotes = @'
12+
0.5.4.1:
13+
---
14+
* Fixing Invoke-ADORestApi issues: #111,#114,#115
15+
* Attaching .BuildID and .DefinitionID properties to Get-ADOBuild where appropriate.
16+
1217
0.5.4:
1318
---
1419
* Formatting Improvments:
@@ -96,14 +101,6 @@
96101
** Get-ADOProject now has -TestRun, -TestPlan, -Release, and -PendingApproval (and better progress bars)
97102
** Get-ADOWorkItemType now has -Field
98103
** Commands for Picklists: Add/Get/Remove/Update-ADOPicklist
99-
0.4.7
100-
----
101-
* New Commands:
102-
** Add/Get/Remove-ADOWiki
103-
** Get-ADOPermission
104-
* Bugfixes:
105-
** Honoring Get-ADOBuild -DefinitionName
106-
* Disconnect-ADO is now run prior at the start of Connect-ADO, and on module unload.
107104
'@
108105
}
109106
Colors = @{

0 commit comments

Comments
 (0)