Skip to content

Commit

Permalink
Fixed bug in check updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Mar 26, 2024
1 parent df22a92 commit c1a827e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
name wasn't converted properly
- Fixed issue in Convert-M365DSCExportToPowerShellDataFile where multiple versions of
M365DSC.CompositeResources being installed caused errors
- Fixed issue in Set-ADOEnvironment where the checks weren't updating due to missing
check id parameter

## [0.2.5] - 2024-03-19

Expand Down
18 changes: 8 additions & 10 deletions source/Public/Set-ADOEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Set-ADOEnvironment
{
<#
<#
.SYNOPSIS
Checks if specified environments exist in Azure DevOps and creates them if they don't.
Expand Down Expand Up @@ -123,7 +123,7 @@ function Set-ADOEnvironment
{
Write-Log -Object ' Parameter PAT is specified, using that to authenticate'
$authToken = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$headers.Add("Authorization", ("Basic {0}" -f $authToken))
$headers.Add('Authorization', ('Basic {0}' -f $authToken))
}
else
{
Expand Down Expand Up @@ -173,7 +173,7 @@ function Set-ADOEnvironment
}
$requestBody = ConvertTo-Json -InputObject $obj -Depth 10

if ($PSCmdlet.ShouldProcess($environment,'Create Environment'))
if ($PSCmdlet.ShouldProcess($environment, 'Create Environment'))
{
$null = Invoke-APRestApi -Uri $envUrl -Method 'POST' -Headers $headers -Body $requestBody
}
Expand Down Expand Up @@ -284,12 +284,12 @@ function Set-ADOEnvironment
$checkId = $envChecks.value.Id

$checkUrl = "{0}/_apis/pipelines/checks/configurations/{2}?`$expand=settings&{1}" -f $devOpsProjectUrl, $apiVersionString, $checkId
Write-Log -Object " DEBUG: $checkUrl"
$checkInfo = Invoke-APRestApi -Uri $checkUrl -Method 'GET' -Headers $headers
if ($null -ne $checkInfo)
{
$settings = $checkInfo.settings
$obj = @{
id = $checkId
type = @{
id = '8C6F20A7-A545-4486-9777-F762FAFE0D4D'
name = 'Approval'
Expand Down Expand Up @@ -368,11 +368,9 @@ function Set-ADOEnvironment
{
Write-Log -Object ' Updating check configuration'
$requestBody = ConvertTo-Json -InputObject $obj -Depth 10
Write-Log -Object " DEBUG: $requestBody"

$configUrl = '{0}/_apis/pipelines/checks/configurations/{2}?{1}' -f $devOpsProjectUrl, $apiVersionString, $checkId
Write-Log -Object " DEBUG: $configUrl"
if ($PSCmdlet.ShouldProcess('Configurations','Configure approvals'))
if ($PSCmdlet.ShouldProcess('Configurations', 'Configure approvals'))
{
$null = Invoke-APRestApi -Uri $configUrl -Method 'PATCH' -Headers $headers -Body $requestBody
}
Expand Down Expand Up @@ -419,7 +417,7 @@ function Set-ADOEnvironment

Write-Log -Object ' Creating check'
$configUrl = '{0}/_apis/pipelines/checks/configurations?{1}' -f $devOpsProjectUrl, $apiVersionString
if ($PSCmdlet.ShouldProcess('Configurations','Create approvals'))
if ($PSCmdlet.ShouldProcess('Configurations', 'Create approvals'))
{
$null = Invoke-APRestApi -Uri $configUrl -Method 'POST' -Headers $headers -Body $requestBody
}
Expand All @@ -439,7 +437,7 @@ function Set-ADOEnvironment
{
Write-Log -Object ' Permissions not provided. Granting permissions!'
$body = "{ 'pipelines':[{'id': $($pipeline.id), 'authorized': true}] }"
if ($PSCmdlet.ShouldProcess($DeploymentPipeline,'Granting pipeline permissions'))
if ($PSCmdlet.ShouldProcess($DeploymentPipeline, 'Granting pipeline permissions'))
{
$null = Invoke-APRestApi -Uri $permissionsUrl -Method 'PATCH' -Headers $headers -Body $body
}
Expand All @@ -452,7 +450,7 @@ function Set-ADOEnvironment
if ($permission.id -ne $pipeline.id -or $permission.authorized -ne $true)
{
$body = "{ 'pipelines':[{'id': $($pipeline.id), 'authorized': true}] }"
if ($PSCmdlet.ShouldProcess($DeploymentPipeline,'Granting pipeline permissions'))
if ($PSCmdlet.ShouldProcess($DeploymentPipeline, 'Granting pipeline permissions'))
{
$null = Invoke-APRestApi -Uri $permissionsUrl -Method 'PATCH' -Headers $headers -Body $body
}
Expand Down

0 comments on commit c1a827e

Please sign in to comment.