-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Get-Timeline cmdlet * Add Timeline class * Add tests
- Loading branch information
1 parent
f29ae03
commit 4b04ce2
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
Push-Location -Path $PSScriptRoot\..\ | ||
|
||
Describe "Get-Timeline unit tests" -Tag "Unit" { | ||
|
||
. .\gandt-azure-devops-tools\Functions\Private\Invoke-AzDevOpsRestMethod.ps1 | ||
|
||
$SharedParams = @{ | ||
Instance = "notarealinstance" | ||
PatToken = "not-a-real-token" | ||
ProjectId = "notarealproject" | ||
BuildId = "1234" | ||
} | ||
|
||
It "Will return a Timeline object with all types failed" { | ||
$TestJson = @' | ||
{ | ||
"records": [ | ||
{ | ||
"Result": "failed", | ||
"Type": "Stage" | ||
}, | ||
{ | ||
"Result": "failed", | ||
"Type": "Job" | ||
}, | ||
{ | ||
"Result": "succeeded", | ||
"Type": "Task" | ||
}, | ||
{ | ||
"Result": "failed", | ||
"Type": "Task" | ||
} | ||
] | ||
} | ||
'@ | ||
|
||
Mock Invoke-AzDevOpsRestMethod { return ConvertFrom-Json $TestJson } | ||
|
||
. .\gandt-azure-devops-tools\Classes\Timeline.ps1 | ||
. .\gandt-azure-devops-tools\Functions\Public\Build\Get-Timeline.ps1 | ||
|
||
$TestParams = $SharedParams | ||
|
||
$Output = Get-Timeline @TestParams | ||
$Output.GetType().Name | Should Be "Timeline" | ||
$Output.BuildId | Should Be "1234" | ||
$Output.FailedJobs | Should Be $true | ||
$Output.FailedStages | Should Be $true | ||
$Output.FailedTasks | Should Be $true | ||
} | ||
|
||
It "Will return a Timeline object with all types not failed" { | ||
$TestJson = @' | ||
{ | ||
"records": [ | ||
{ | ||
"Result": "succeeded", | ||
"Type": "Stage" | ||
}, | ||
{ | ||
"Result": "succeeded", | ||
"Type": "Job" | ||
}, | ||
{ | ||
"Result": "succeeded", | ||
"Type": "Task" | ||
}, | ||
{ | ||
"Result": "succeeded", | ||
"Type": "Task" | ||
} | ||
] | ||
} | ||
'@ | ||
|
||
Mock Invoke-AzDevOpsRestMethod { return ConvertFrom-Json $TestJson } | ||
|
||
. .\gandt-azure-devops-tools\Classes\Timeline.ps1 | ||
. .\gandt-azure-devops-tools\Functions\Public\Build\Get-Timeline.ps1 | ||
|
||
$TestParams = $SharedParams | ||
|
||
$Output = Get-Timeline @TestParams | ||
$Output.GetType().Name | Should Be "Timeline" | ||
$Output.BuildId | Should Be "1234" | ||
$Output.FailedJobs | Should Be $false | ||
$Output.FailedStages | Should Be $false | ||
$Output.FailedTasks | Should Be $false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Timeline { | ||
[int]$BuildId | ||
[bool]$FailedJobs | ||
[bool]$FailedStages | ||
[bool]$FailedTasks | ||
} |
57 changes: 57 additions & 0 deletions
57
gandt-azure-devops-tools/Functions/Public/Build/Get-Timeline.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<# | ||
.NOTES | ||
API Reference: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/timeline/get?view=azure-devops-rest-7.1 | ||
#> | ||
function Get-Timeline { | ||
[CmdletBinding()] | ||
param ( | ||
#The Visual Studio Team Services account name | ||
[Parameter(Mandatory=$true)] | ||
[string]$Instance, | ||
|
||
#A PAT token with the necessary scope to invoke the requested HttpMethod on the specified Resource | ||
[Parameter(Mandatory=$true)] | ||
[string]$PatToken, | ||
|
||
#Parameter Description | ||
[Parameter(Mandatory=$true)] | ||
[string]$ProjectId, | ||
|
||
#Parameter Description | ||
[Parameter(Mandatory=$true, ParameterSetName="Id")] | ||
[int]$BuildId | ||
) | ||
|
||
process { | ||
|
||
$GetTimelineParams = @{ | ||
Instance = $Instance | ||
PatToken = $PatToken | ||
Collection = $ProjectId | ||
Area = "build" | ||
Resource = "builds" | ||
ResourceId = $BuildId | ||
ResourceComponent = "timeline" | ||
ApiVersion = "7.1-preview.2" | ||
} | ||
|
||
$TimelineJson = Invoke-AzDevOpsRestMethod @GetTimelineParams | ||
|
||
$Timeline = New-TimelineObject -BuildId $BuildId -TimelineJson $TimelineJson | ||
$Timeline | ||
} | ||
} | ||
|
||
function New-TimelineObject { | ||
param ( | ||
$BuildId, | ||
$TimelineJson | ||
) | ||
|
||
$Timeline = New-Object -TypeName Timeline | ||
$Timeline.BuildId = $BuildId | ||
$Timeline.FailedJobs = $null -ne ($TimelineJson.records | Where-Object {$_.Type -eq "Job" -and $_.Result -eq "failed"}) | ||
$Timeline.FailedStages = $null -ne ($TimelineJson.records | Where-Object {$_.Type -eq "Stage" -and $_.Result -eq "failed"}) | ||
$Timeline.FailedTasks = $null -ne ($TimelineJson.records | Where-Object {$_.Type -eq "Task" -and $_.Result -eq "failed"}) | ||
$Timeline | ||
} |