Modules/Get-OctoReleases.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Get-OctoReleases ([int]$recent = 4, [string]$projectName) { 
    
    $repository = Get-OctoRepository
    $project = $repository.Projects.FindByName($projectName)
    if ($project -eq $null) { throw "No project found named '$projectName'" }

    $all = $repository.Releases.FindMany({ param($r) $r.ProjectId -eq $project.Id}) 
    $rt =  [Octopus.Client.Model.TaskResource]

    for ($i = 0; $i -lt $recent; $i++) {
        $at = $all[$i]
        "$($at.Id) $($at.Version)"
        $deployments = $repository.Deployments.FindMany({ param($r) $r.ReleaseId -eq $at.Id })
        foreach ($d in $deployments) {
            "`t$($d.Name) $($d.Created) $($d.Comments) $($d.Task)"
            $taskUrl = $d.Links['Task']
            $rt =  [Octopus.Client.Model.TaskResource]
            $task = [Getter]::Get($repository.Client, $taskUrl, $null, $rt ) 
            $color = [Console]::ForegroundColor
            if ($task.IsCompleted) {
                if ($task.FinishedSuccessfully) {
                    [Console]::ForegroundColor = "Green"
                } else {
                    [Console]::ForegroundColor = "Red"
                }
            } else {
                [Console]::ForegroundColor = "Yellow"
            }
            "`t`t$($task.Name) $($task.State) $($task.StartTime) $($task.Duration)"
            [Console]::ForegroundColor = $color
        }
    }
}