-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjira_sprint_query.ps1
More file actions
122 lines (104 loc) · 3.16 KB
/
jira_sprint_query.ps1
File metadata and controls
122 lines (104 loc) · 3.16 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#
# Author: Corelli
# Date: 23AUG2022
# Version: 0.1
<#
.SYNOPSIS
Queries the Jira board for sprint numbers
.DESCRIPTION
Tool for querying the Jira Board to feed the number into other scripts
.PARAMETER Help
Show the help documentation
.PARAMETER LastClosed
Query the sprint number of the most recently closed sprint
.PARAMETER FirstActive
Query the sprint number of the oldest active sprint
.PARAMETER LastActive
Query the sprint number of the newest active sprint
.INPUTS
BearerToken the Jira Personal Access Token (Bearer Token) used to authenticate to the server. Default will be read from file at: `~/.jiratoken/token`
.OUTPUTS
The requested sprint number value
.EXAMPLE
PS> jira_sprint_query.ps1 # Default
.EXAMPLE
PS> jira_sprint_query.ps1 -lc # Get the last completed sprint
.EXAMPLE
PS> jira_sprint_query.ps1 -fa # Get the first active sprint (oldest active)
.EXAMPLE
PS> jira_sprint_query.ps1 -la # Get the last active sprint (newest active)
#>
[CmdletBinding(DefaultParametersetName="LastClosed")]
param(
[switch][Alias("h")] $Help, # include to display the help message and then exit
[Parameter(ParameterSetName="LastClosed")]
[switch][Alias("lc")] $LastClosed,
[Parameter(ParameterSetName="FirstActive")]
[switch][Alias("fa")] $FirstActive,
[Parameter(ParameterSetName="LastActive")]
[switch][Alias("la")] $LastActive,
[Parameter(ValueFromPipeline = $true)]
[string] $BearerToken
)
if(!$FirstActive -and !$LastActive){
$LastClosed = $true
}
if($Help){
# call the Get-Help
Get-Help $MyInvocation.MyCommand.Path
exit 0
}
if(!$BearerToken){
$BearerToken = (Get-Content -Path '~/.jiratoken/token')
}
$Text = "jira@acorelli.com:$BearerToken"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
$EncodedText = [Convert]::ToBase64String($Bytes)
$Headers = @{
"Authorization" = "Basic $EncodedText"
"Content-Type"="application/json"
}
$offset = 0
if(Test-Path variable:\response){
Clear-Variable response
}
$foundFirstActive = $false
while($response.isLast -ne "True"){
$response = Invoke-RestMethod -Method GET -Headers $Headers -Uri "https://acorelli.atlassian.net/rest/agile/1.0/board/15/sprint" #?startAt=$offset"
$response | Write-Host -ForegroundColor Gray
$values = $response.values
$values | Write-Host -ForegroundColor Gray
$offset = $offset + $values.length
for($i = 0; $i -lt $values.length; $i++){
$value = $values[$i]
$value.name | Write-Debug
": " | Write-Debug
$status = $value.state
if($status -eq "active"){
[console]::ForegroundColor = "green"
$latestActiveNum = ($value.name | Select-String -Pattern "\d+" | %{$_.matches.value})
if(!$foundFirstActive){
$foundFirstActive = $true
$firstActiveNum = $latestActiveNum
}
}
if($status -eq "future"){
[console]::ForegroundColor = "yellow"
}
if($status -eq "closed"){
$latestClosedNum = ($value.name | Select-String -Pattern "\d+" | %{$_.matches.value})
[console]::ForegroundColor = "red"
}
$status | write-Debug
[console]::ResetColor()
}
}
if($LastClosed){
$latestClosedNum | Write-Output
}
if($FirstActive){
$firstActiveNum | Write-Output
}
if($LastActive){
$latestActiveNum | Write-Output
}