From 16c5c131d684fb2351f0e728ff33bb79d620b78e Mon Sep 17 00:00:00 2001 From: James Brundage Date: Thu, 1 Jul 2021 14:25:50 -0700 Subject: [PATCH 1/5] Invoke-ADORestAPI: Fixing #111. No longer treating brackets in REST variables. --- Invoke-ADORestAPI.ps1 | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Invoke-ADORestAPI.ps1 b/Invoke-ADORestAPI.ps1 index 81f03f65..c46cd342 100644 --- a/Invoke-ADORestAPI.ps1 +++ b/Invoke-ADORestAPI.ps1 @@ -157,33 +157,28 @@ Specifies the method used for the web request. The acceptable values for this pa ) begin { + # From [Irregular](https://github.com/StartAutomating/Irregular): + # ? -VariableFormat Braces $RestVariable = [Regex]::new(@' -# Matches URL segments and query strings containing variables. -# Variables can be enclosed in brackets or curly braces, or preceeded by a $ or : (?> # A variable can be in a URL segment or subdomain (?[/\.]) # Match the ing slash|dot ... (?\?)? # ... an optional ? (to indicate optional) ... (?: \{(?\w+)\}| # ... A name in {} OR - \[(?\w+)\]| # A name in [] OR - `\$(?\w+) | # A `$ followed by a OR - \:(?\w+) # A : followed by a ) | (? # If it's optional it can also be [{\[](?/) # a bracket or brace, followed by a slash ) (?\w+)[}\]] # then a name followed by } or ] + | # OR it can be in a query parameter: - (?[?&]) # Match The ing ? or & ... - (?[\w\-]+) # ... the parameter name ... + (?[\?\&]) # Match The ing ? or & ... + (?[\$\w\-]+) # ... the parameter name ... = # ... an equals ... (?\?)? # ... an optional ? (to indicate optional) ... (?: \{(?\w+)\}| # ... A name in {} OR - \[(?\w+)\]| # A name in [] OR - \`$(?\w+) | # A $ followed by a OR - \:(?\w+) # A : followed by a ) ) '@, 'IgnoreCase,IgnorePatternWhitespace') From fd32436cab12e6d79083358a295eb5d9f7304289 Mon Sep 17 00:00:00 2001 From: James Brundage Date: Thu, 1 Jul 2021 15:41:51 -0700 Subject: [PATCH 2/5] Invoke-ADORestAPI: Fixing #111. No longer treating brackets in REST variables. --- Invoke-ADORestAPI.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Invoke-ADORestAPI.ps1 b/Invoke-ADORestAPI.ps1 index c46cd342..3f35e1d3 100644 --- a/Invoke-ADORestAPI.ps1 +++ b/Invoke-ADORestAPI.ps1 @@ -164,21 +164,21 @@ Specifies the method used for the web request. The acceptable values for this pa (?[/\.]) # Match the ing slash|dot ... (?\?)? # ... an optional ? (to indicate optional) ... (?: - \{(?\w+)\}| # ... A name in {} OR + \{(?\w+)\} # ... A name in {} OR ) | - (? # If it's optional it can also be + (? # If it's optional it can also be [{\[](?/) # a bracket or brace, followed by a slash ) (?\w+)[}\]] # then a name followed by } or ] | # OR it can be in a query parameter: (?[\?\&]) # Match The ing ? or & ... - (?[\$\w\-]+) # ... the parameter name ... + (?[\$\w\-]+) # ... the parameter name ... = # ... an equals ... (?\?)? # ... an optional ? (to indicate optional) ... (?: - \{(?\w+)\}| # ... A name in {} OR + \{(?\w+)\} # ... A name in {} OR ) ) '@, 'IgnoreCase,IgnorePatternWhitespace') From 5e21f0b6a0ec1d5b7e06e0cef38fc95a103ff048 Mon Sep 17 00:00:00 2001 From: James Brundage Date: Thu, 1 Jul 2021 16:47:44 -0700 Subject: [PATCH 3/5] Invoke-ADORestAPI: Improving performance of -AsByte (fixes #114) --- Invoke-ADORestAPI.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Invoke-ADORestAPI.ps1 b/Invoke-ADORestAPI.ps1 index 3f35e1d3..4b881d1b 100644 --- a/Invoke-ADORestAPI.ps1 +++ b/Invoke-ADORestAPI.ps1 @@ -397,7 +397,7 @@ $($MyInvocation.MyCommand.Name) @parameter if ($AsByte) { $ms = [IO.MemoryStream]::new() $rs.CopyTo($ms) - $ms.ToArray() + ,$ms.ToArray() $ms.Dispose() return } @@ -419,6 +419,9 @@ $($MyInvocation.MyCommand.Name) @parameter $null = $null # We call Invoke-RestMethod with the parameters we've passed in. # It will take care of converting the results from JSON. + if ($response -is [byte[]]) { + return $response + } $apiOutput = $response | @@ -429,7 +432,7 @@ $($MyInvocation.MyCommand.Name) @parameter # A lot of things in the Azure DevOps REST apis come back as a count/value pair if ($in -eq 'null') { return - } + } if ($ExpandProperty) { if ($in.$ExpandProperty) { return $in.$ExpandProperty @@ -451,7 +454,7 @@ $($MyInvocation.MyCommand.Name) @parameter $in = $_ - if ($in -is [string]) { return $in } + if ($in -is [string]) { return $in } if ($null -ne $in.Count -and $in.Count -eq 0) { return } From 70e9edc821579be93702db9357f6b89a2ec64d59 Mon Sep 17 00:00:00 2001 From: James Brundage Date: Thu, 1 Jul 2021 16:55:22 -0700 Subject: [PATCH 4/5] Invoke-ADORestAPI: Including StatusCode and StatusDescription in error message (fixes #115) --- Invoke-ADORestAPI.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Invoke-ADORestAPI.ps1 b/Invoke-ADORestAPI.ps1 index 4b881d1b..36c15068 100644 --- a/Invoke-ADORestAPI.ps1 +++ b/Invoke-ADORestAPI.ps1 @@ -372,7 +372,7 @@ $($MyInvocation.MyCommand.Name) @parameter $streamIn.Dispose() $PSCmdlet.WriteError( [Management.Automation.ErrorRecord]::new( - [Exception]::new($strResponse, $ex.Exception.InnerException + [Exception]::new("$($ex.Exception.InnerException.Response.StatusCode, $ex.Exception.InnerException.Response.StatusDescription)$strResponse ", $ex.Exception.InnerException ), $ex.Exception.HResult, 'NotSpecified', $webRequest) ) return From 92002eaf636d2e0a894236afbad66a03cd9c335f Mon Sep 17 00:00:00 2001 From: James Brundage Date: Fri, 2 Jul 2021 02:36:40 -0700 Subject: [PATCH 5/5] Updating Module Version [0.5.4.1] and release notes --- PSDevOps.psd1 | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/PSDevOps.psd1 b/PSDevOps.psd1 index 4c69a604..0e19afd6 100644 --- a/PSDevOps.psd1 +++ b/PSDevOps.psd1 @@ -1,5 +1,5 @@ @{ - ModuleVersion = '0.5.4' + ModuleVersion = '0.5.4.1' RootModule = 'PSDevOps.psm1' Description = 'PowerShell Tools for DevOps' Guid = 'e6b56c5f-41ac-4ba4-8b88-2c063f683176' @@ -9,6 +9,11 @@ ProjectURI = 'https://github.com/StartAutomating/PSDevOps' LicenseURI = 'https://github.com/StartAutomating/PSDevOps/blob/master/LICENSE' ReleaseNotes = @' +0.5.4.1: +--- +* Fixing Invoke-ADORestApi issues: #111,#114,#115 +* Attaching .BuildID and .DefinitionID properties to Get-ADOBuild where appropriate. + 0.5.4: --- * Formatting Improvments: @@ -96,14 +101,6 @@ ** Get-ADOProject now has -TestRun, -TestPlan, -Release, and -PendingApproval (and better progress bars) ** Get-ADOWorkItemType now has -Field ** Commands for Picklists: Add/Get/Remove/Update-ADOPicklist -0.4.7 ----- -* New Commands: -** Add/Get/Remove-ADOWiki -** Get-ADOPermission -* Bugfixes: -** Honoring Get-ADOBuild -DefinitionName -* Disconnect-ADO is now run prior at the start of Connect-ADO, and on module unload. '@ } Colors = @{