8
8
[string ] $actionsToken = " " ,
9
9
[string ] $appId = " " ,
10
10
[string ] $appInstallationId = " " ,
11
- [string ] $appPrivateKey = " " ,
12
- [bool ] $showVerboseLogging = $false
11
+ [string ] $appPrivateKey = " "
13
12
)
14
13
15
14
# The main function
@@ -21,8 +20,7 @@ function Main ([string] $ownerRepo,
21
20
[string ] $actionsToken = " " ,
22
21
[string ] $appId = " " ,
23
22
[string ] $appInstallationId = " " ,
24
- [string ] $appPrivateKey = " " ,
25
- [bool ] $showVerboseLogging = $false )
23
+ [string ] $appPrivateKey = " " )
26
24
{
27
25
28
26
# ==========================================
@@ -31,19 +29,15 @@ function Main ([string] $ownerRepo,
31
29
$owner = $ownerRepoArray [0 ]
32
30
$repo = $ownerRepoArray [1 ]
33
31
$workflowsArray = $workflows -split ' ,'
34
- $numberOfDays = $numberOfDays
35
- # Write-Output "showVerboseLogging: $showVerboseLogging"
36
- if ($showVerboseLogging -eq $true )
37
- {
38
- Write-Output " Owner/Repo: $owner /$repo "
39
- Write-Output " Workflows: $workflows "
40
- Write-Output " Branch: $branch "
41
- Write-Output " Number of days: $numberOfDays "
42
- }
32
+ $numberOfDays = $numberOfDays
33
+ Write-Host " Owner/Repo: $owner /$repo "
34
+ Write-Host " Workflows: $workflows "
35
+ Write-Host " Branch: $branch "
36
+ Write-Host " Number of days: $numberOfDays "
43
37
44
38
# ==========================================
45
39
# Get authorization headers
46
- $authHeader = GetAuthHeader $patToken $actionsToken $appId $appInstallationId $appPrivateKey $showVerboseLogging
40
+ $authHeader = GetAuthHeader $patToken $actionsToken $appId $appInstallationId $appPrivateKey
47
41
48
42
# ==========================================
49
43
# Get workflow definitions from github
@@ -83,10 +77,6 @@ function Main ([string] $ownerRepo,
83
77
$result = $workflowNames.Add ($workflow.name )
84
78
}
85
79
}
86
- # else
87
- # {
88
- # Write-Output "'$($workflow.name)' DID NOT match with $arrayItem"
89
- # }
90
80
}
91
81
}
92
82
@@ -114,7 +104,7 @@ function Main ([string] $ownerRepo,
114
104
# Count workflows that are completed, on the target branch, and were created within the day range we are looking at
115
105
if ($run.head_branch -eq $branch -and $run.created_at -gt (Get-Date ).AddDays(- $numberOfDays ))
116
106
{
117
- # Write-Output "Adding item with status $($run.status), branch $($run.head_branch), created at $($run.created_at), compared to $((Get-Date).AddDays(-$numberOfDays))"
107
+ # Write-Host "Adding item with status $($run.status), branch $($run.head_branch), created at $($run.created_at), compared to $((Get-Date).AddDays(-$numberOfDays))"
118
108
$buildTotal ++
119
109
# get the workflow start and end time
120
110
$dateList += New-Object PSObject - Property @ {start_datetime = $run.created_at ;end_datetime = $run.updated_at }
@@ -133,11 +123,10 @@ function Main ([string] $ownerRepo,
133
123
$deploymentsPerDay = $dateList.Count / $numberOfDays
134
124
}
135
125
$deploymentsPerDayList += $deploymentsPerDay
136
- # Write-Output "Adding to list, workflow id $workflowId deployments per day of $deploymentsPerDay"
126
+ # Write-Host "Adding to list, workflow id $workflowId deployments per day of $deploymentsPerDay"
137
127
}
138
128
}
139
129
140
- # Write-Output "Total items in list is $($deploymentsPerDayList.Length)"
141
130
$totalDeployments = 0
142
131
Foreach ($deploymentItem in $deploymentsPerDayList ){
143
132
$totalDeployments += $deploymentItem
@@ -146,7 +135,7 @@ function Main ([string] $ownerRepo,
146
135
{
147
136
$deploymentsPerDay = $totalDeployments / $deploymentsPerDayList.Length
148
137
}
149
- # Write-Output "Total deployments $totalDeployments with a final deployments value of $deploymentsPerDay"
138
+ # Write-Host "Total deployments $totalDeployments with a final deployments value of $deploymentsPerDay"
150
139
151
140
# ==========================================
152
141
# Show current rate limit
@@ -159,10 +148,7 @@ function Main ([string] $ownerRepo,
159
148
{
160
149
$rateLimitResponse = Invoke-RestMethod - Uri $uri3 - ContentType application/ json - Method Get - Headers @ {Authorization = ($authHeader [" Authorization" ])} - SkipHttpErrorCheck - StatusCodeVariable " HTTPStatus"
161
150
}
162
- if ($showVerboseLogging -eq $true )
163
- {
164
- Write-Output " Rate limit consumption: $ ( $rateLimitResponse.rate.used ) / $ ( $rateLimitResponse.rate.limit ) "
165
- }
151
+ Write-Host " Rate limit consumption: $ ( $rateLimitResponse.rate.used ) / $ ( $rateLimitResponse.rate.limit ) "
166
152
167
153
# ==========================================
168
154
# Calculate deployments per day
@@ -242,10 +228,7 @@ function Main ([string] $ownerRepo,
242
228
243
229
if ($dateList.Count -gt 0 -and $numberOfDays -gt 0 )
244
230
{
245
- if ($showVerboseLogging -eq $true )
246
- {
247
- Write-Output " Deployment frequency over last $numberOfDays days, is $displayMetric $displayUnit , with a DORA rating of '$rating '"
248
- }
231
+ Write-Host " Deployment frequency over last $numberOfDays days, is $displayMetric $displayUnit , with a DORA rating of '$rating '"
249
232
return Format-OutputMarkdown - workflowNames $workflowNames - displayMetric $displayMetric - displayUnit $displayUnit - repo $ownerRepo - branch $branch - numberOfDays $numberOfDays - numberOfUniqueDates $uniqueDates.Length.ToString () - color $color - rating $rating
250
233
}
251
234
else
@@ -257,7 +240,7 @@ function Main ([string] $ownerRepo,
257
240
# Generate the authorization header for the PowerShell call to the GitHub API
258
241
# warning: PowerShell has really wacky return semantics - all output is captured, and returned
259
242
# reference: https://stackoverflow.com/questions/10286164/function-return-value-in-powershell
260
- function GetAuthHeader ([string ] $patToken , [string ] $actionsToken , [string ] $appId , [string ] $appInstallationId , [string ] $appPrivateKey , [ bool ] $showVerboseLogging = $false )
243
+ function GetAuthHeader ([string ] $patToken , [string ] $actionsToken , [string ] $appId , [string ] $appInstallationId , [string ] $appPrivateKey )
261
244
{
262
245
# Clean the string - without this the PAT TOKEN doesn't process
263
246
$patToken = $patToken.Trim ()
@@ -267,36 +250,24 @@ function GetAuthHeader ([string] $patToken, [string] $actionsToken, [string] $ap
267
250
# Write-Host "patToken is something: $(![string]::IsNullOrEmpty($patToken))"
268
251
if (! [string ]::IsNullOrEmpty($patToken ))
269
252
{
270
- if ($showVerboseLogging -eq $true )
271
- {
272
- Write-Host " Authentication detected: PAT TOKEN"
273
- }
253
+ Write-Host " Authentication detected: PAT TOKEN"
274
254
$base64AuthInfo = [System.Convert ]::ToBase64String([System.Text.Encoding ]::UTF8.GetBytes(" :$patToken " ))
275
255
$authHeader = @ {Authorization = (" Basic {0}" -f $base64AuthInfo )}
276
256
}
277
257
elseif (! [string ]::IsNullOrEmpty($actionsToken ))
278
258
{
279
- if ($showVerboseLogging -eq $true )
280
- {
281
- Write-Host " Authentication detected: GITHUB TOKEN"
282
- }
259
+ Write-Host " Authentication detected: GITHUB TOKEN"
283
260
$authHeader = @ {Authorization = (" Bearer {0}" -f $base64AuthInfo )}
284
261
}
285
262
elseif (! [string ]::IsNullOrEmpty($appId )) # GitHup App auth
286
263
{
287
- if ($showVerboseLogging -eq $true )
288
- {
289
- Write-Host " Authentication detected: GITHUB APP TOKEN"
290
- }
264
+ Write-Host " Authentication detected: GITHUB APP TOKEN"
291
265
$token = Get-JwtToken $appId $appInstallationId $appPrivateKey
292
266
$authHeader = @ {Authorization = (" token {0}" -f $token )}
293
267
}
294
268
else
295
269
{
296
- if ($showVerboseLogging -eq $true )
297
- {
298
- Write-Host " No authentication detected"
299
- }
270
+ Write-Host " No authentication detected"
300
271
$base64AuthInfo = $null
301
272
$authHeader = $null
302
273
}
@@ -367,8 +338,8 @@ function Get-JwtToken([string] $appId, [string] $appInstallationId, [string] $ap
367
338
function Format-OutputMarkdown ([array ] $workflowNames , [string ] $rating , [string ] $displayMetric , [string ] $displayUnit , [string ] $repo , [string ] $branch , [string ] $numberOfDays , [string ] $numberOfUniqueDates , [string ] $color )
368
339
{
369
340
$encodedDeploymentFrequency = [uri ]::EscapeUriString($displayMetric + " " + $displayUnit )
370
-
371
- $markdown = " `r `n" +
341
+ # double newline to start the line helps with formatting in GitHub logs
342
+ $markdown = " `n`n `n " +
372
343
" **Definition:** For the primary application or service, how often is it successfully deployed to production.`n " +
373
344
" **Results:** Deployment frequency is **$displayMetric $displayUnit ** with a **$rating ** rating, over the last **$numberOfDays days**.`n " +
374
345
" **Details**:`n " +
@@ -381,10 +352,11 @@ function Format-OutputMarkdown([array] $workflowNames, [string] $rating, [string
381
352
382
353
function Format-NoOutputMarkdown ([string ] $workflows , [string ] $numberOfDays )
383
354
{
384
- $markdown = " `r`n`n " +
355
+ # double newline to start the line helps with formatting in GitHub logs
356
+ $markdown = " `n`n `n`n " +
385
357
" No data to display for $ownerRepo for workflow(s) $workflows over the last $numberOfDays days`n`n " +
386
358
" ---"
387
359
return $markdown
388
360
}
389
361
390
- main - ownerRepo $ownerRepo - workflows $workflows - branch $branch - numberOfDays $numberOfDays - patToken $patToken - actionsToken $actionsToken - appId $appId - appInstallationId $appInstallationId - appPrivateKey $appPrivateKey - showVerboseLogging $showVerboseLogging
362
+ main - ownerRepo $ownerRepo - workflows $workflows - branch $branch - numberOfDays $numberOfDays - patToken $patToken - actionsToken $actionsToken - appId $appId - appInstallationId $appInstallationId - appPrivateKey $appPrivateKey
0 commit comments