Skip to content

Commit cd108c8

Browse files
committed
Get PSScriptAnalyzer clean again
Somehow a number of PSScriptAnalyzer issues snuck in. This fixes them. The main PSScriptAnalyzer issues needing to be fixed were: * `PSReviewUnusedParameter` - This one came up a lot due to our heavy usage of `Resolve-RepositoryElements` and `Resolve-ParameterWithDefaultConfigurationValue` which both end up referencing their parameters by grabbing them off the stack. That means that `NoStatus` and `Uri` are frequently never directly referenced. So, exceptions were added. There were two cases (in GitHubAnalytics) where there was a false positive due to PowerShell/PSScriptAnalyzer#1472 * `PSUseProcessBlockForPipelineCommand` - We had a number of functions that took pipeline input, but didn't actuall use the `process` block. This actually caught a bug with `Group-GitHubIssue` and `Group-GitHubPullRequest`. Added correct `process` block usage for most of the functions, but removed pipeline support for those where it didn't actually make sense anymore. * `PSUseDeclaredVarsMoreThanAssignments` - These are false positives in the Pester tests due to the usage of `BeforeAll`. There wasn't an obvious way to use `SuppressMessageAttribute` in the Pester test, so I used a hacky workaround to "use" the variable in the `BeforeAll` block. I could have added the suppression to the top of the file, but I still want to catch real issues in those files later. * `PSAvoidOverwritingBuiltInCmdlets` - It turns out that there's a bug with PSDesiredStateConfiguration in PS Core 6.1.0 where it was exporting internal functions. This was thus a false-postive flag for Write-Log. See PowerShell/PowerShell#7209 for more info. Also, it turns out that `Group-GitHubPullRequest` hadn't actually been exported, so I fixed that too.
1 parent c4c1ec3 commit cd108c8

24 files changed

+330
-128
lines changed

GitHubAnalytics.ps1

+110-54
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function Group-GitHubIssue
3737
SupportsShouldProcess,
3838
DefaultParameterSetName='Weekly')]
3939
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
40+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")]
4041
param
4142
(
4243
[Parameter(
@@ -55,41 +56,68 @@ function Group-GitHubIssue
5556
[string] $DateType = 'Created'
5657
)
5758

58-
Write-InvocationLog
59-
60-
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
59+
begin
6160
{
62-
$totalIssues = 0
63-
$weekDates = Get-WeekDate -Weeks $Weeks
64-
$endOfWeek = Get-Date
61+
Write-InvocationLog
6562

66-
foreach ($week in $weekDates)
63+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
6764
{
68-
$filteredIssues = @($Issue | Where-Object {
69-
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
70-
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
71-
})
72-
73-
$endOfWeek = $week
74-
$count = $filteredIssues.Count
75-
$totalIssues += $count
76-
77-
Write-Output -InputObject ([PSCustomObject]([ordered]@{
78-
'WeekStart' = $week
79-
'Count' = $count
80-
'Issues' = $filteredIssues
65+
$weekDates = Get-WeekDate -Weeks $Weeks
66+
67+
$result = [ordered]@{}
68+
foreach ($week in $weekDates)
69+
{
70+
$result[$week] = ([PSCustomObject]([ordered]@{
71+
'WeekStart' = $week
72+
'Count' = 0
73+
'Issues' = @()
74+
}))
75+
}
76+
77+
$result['total'] = ([PSCustomObject]([ordered]@{
78+
'WeekStart' = 'total'
79+
'Count' = 0
80+
'Issues' = @()
8181
}))
8282
}
83+
}
8384

84-
Write-Output -InputObject ([PSCustomObject]([ordered]@{
85-
'WeekStart' = 'total'
86-
'Count' = $totalIssues
87-
'Issues' = $Issue
88-
}))
85+
process
86+
{
87+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
88+
{
89+
$endOfWeek = Get-Date
90+
foreach ($week in $weekDates)
91+
{
92+
$filteredIssues = @($Issue | Where-Object {
93+
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
94+
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
95+
})
96+
97+
$endOfWeek = $week
98+
99+
$result[$week].Issues += $filteredIssues
100+
$result[$week].Count += ($filteredIssues.Count)
101+
102+
$result['total'].Issues += $filteredIssues
103+
$result['total'].Count += ($filteredIssues.Count)
104+
}
105+
}
106+
else
107+
{
108+
Write-Output -InputObject $Issue
109+
}
89110
}
90-
else
111+
112+
end
91113
{
92-
Write-Output -InputObject $Issue
114+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
115+
{
116+
foreach ($entry in $result.Values.GetEnumerator())
117+
{
118+
Write-Output -InputObject $entry
119+
}
120+
}
93121
}
94122
}
95123

@@ -130,6 +158,7 @@ function Group-GitHubPullRequest
130158
SupportsShouldProcess,
131159
DefaultParameterSetName='Weekly')]
132160
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
161+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")]
133162
param
134163
(
135164
[Parameter(
@@ -148,41 +177,68 @@ function Group-GitHubPullRequest
148177
[string] $DateType = 'Created'
149178
)
150179

151-
Write-InvocationLog
152-
153-
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
180+
begin
154181
{
155-
$totalPullRequests = 0
156-
$weekDates = Get-WeekDate -Weeks $Weeks
157-
$endOfWeek = Get-Date
182+
Write-InvocationLog
158183

159-
foreach ($week in $weekDates)
184+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
160185
{
161-
$filteredPullRequests = @($PullRequest | Where-Object {
162-
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
163-
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
164-
})
165-
166-
$endOfWeek = $week
167-
$count = $filteredPullRequests.Count
168-
$totalPullRequests += $count
169-
170-
Write-Output -InputObject ([PSCustomObject]([ordered]@{
171-
'WeekStart' = $week
172-
'Count' = $count
173-
'PullRequests' = $filteredPullRequests
186+
$weekDates = Get-WeekDate -Weeks $Weeks
187+
188+
$result = [ordered]@{}
189+
foreach ($week in $weekDates)
190+
{
191+
$result[$week] = ([PSCustomObject]([ordered]@{
192+
'WeekStart' = $week
193+
'Count' = 0
194+
'PullRequests' = @()
195+
}))
196+
}
197+
198+
$result['total'] = ([PSCustomObject]([ordered]@{
199+
'WeekStart' = 'total'
200+
'Count' = 0
201+
'PullRequests' = @()
174202
}))
175203
}
204+
}
176205

177-
Write-Output -InputObject ([PSCustomObject]([ordered]@{
178-
'WeekStart' = 'total'
179-
'Count' = $totalPullRequests
180-
'PullRequests' = $PullRequest
181-
}))
206+
process
207+
{
208+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
209+
{
210+
$endOfWeek = Get-Date
211+
foreach ($week in $weekDates)
212+
{
213+
$filteredPullRequests = @($PullRequest | Where-Object {
214+
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
215+
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
216+
})
217+
218+
$endOfWeek = $week
219+
220+
$result[$week].PullRequests += $filteredPullRequests
221+
$result[$week].Count += ($filteredPullRequests.Count)
222+
223+
$result['total'].PullRequests += $filteredPullRequests
224+
$result['total'].Count += ($filteredPullRequests.Count)
225+
}
226+
}
227+
else
228+
{
229+
Write-Output -InputObject $PullRequest
230+
}
182231
}
183-
else
232+
233+
end
184234
{
185-
Write-Output -InputObject $PullRequest
235+
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
236+
{
237+
foreach ($entry in $result.Values.GetEnumerator())
238+
{
239+
Write-Output -InputObject $entry
240+
}
241+
}
186242
}
187243
}
188244

GitHubAssignees.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Get-GitHubAssignee
4141
SupportsShouldProcess,
4242
DefaultParameterSetName='Elements')]
4343
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
44+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
4445
param(
4546
[Parameter(ParameterSetName='Elements')]
4647
[string] $OwnerName,
@@ -128,6 +129,7 @@ function Test-GitHubAssignee
128129
DefaultParameterSetName='Elements')]
129130
[OutputType([bool])]
130131
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
132+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
131133
param(
132134
[Parameter(ParameterSetName='Elements')]
133135
[string] $OwnerName,
@@ -228,6 +230,7 @@ function New-GithubAssignee
228230
SupportsShouldProcess,
229231
DefaultParameterSetName='Elements')]
230232
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
233+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
231234
param(
232235
[Parameter(ParameterSetName='Elements')]
233236
[string] $OwnerName,
@@ -330,6 +333,7 @@ function Remove-GithubAssignee
330333
SupportsShouldProcess,
331334
DefaultParameterSetName='Elements')]
332335
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
336+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
333337
param(
334338
[Parameter(ParameterSetName='Elements')]
335339
[string] $OwnerName,

GitHubBranches.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function Get-GitHubRepositoryBranch
5555
SupportsShouldProcess,
5656
DefaultParameterSetName='Elements')]
5757
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
58+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
5859
[Alias('Get-GitHubBranch')]
5960
param(
6061
[Parameter(ParameterSetName='Elements')]

GitHubComments.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function New-GitHubComment
244244
SupportsShouldProcess,
245245
DefaultParameterSetName='Elements')]
246246
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
247+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
247248
param(
248249
[Parameter(ParameterSetName='Elements')]
249250
[string] $OwnerName,
@@ -355,6 +356,7 @@ function Set-GitHubComment
355356
SupportsShouldProcess,
356357
DefaultParameterSetName='Elements')]
357358
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
359+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
358360
param(
359361
[Parameter(ParameterSetName='Elements')]
360362
[string] $OwnerName,
@@ -456,6 +458,7 @@ function Remove-GitHubComment
456458
DefaultParameterSetName='Elements')]
457459
[Alias('Delete-GitHubComment')]
458460
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
461+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
459462
param(
460463
[Parameter(ParameterSetName='Elements')]
461464
[string] $OwnerName,

GitHubCore.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ function Invoke-GHRestMethodMultipleResult
612612
#>
613613
[CmdletBinding(SupportsShouldProcess)]
614614
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
615+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
615616
[OutputType([Object[]])]
616617
param(
617618
[Parameter(Mandatory)]

GitHubIssues.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ function Get-GitHubIssueTimeline
378378
SupportsShouldProcess,
379379
DefaultParameterSetName='Elements')]
380380
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
381+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
381382
param(
382383
[Parameter(ParameterSetName='Elements')]
383384
[string] $OwnerName,
@@ -861,6 +862,7 @@ function Unlock-GitHubIssue
861862
SupportsShouldProcess,
862863
DefaultParameterSetName='Elements')]
863864
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
865+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
864866
param(
865867
[Parameter(ParameterSetName='Elements')]
866868
[string] $OwnerName,

GitHubLabels.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ function New-GitHubLabel
206206
SupportsShouldProcess,
207207
DefaultParameterSetName='Elements')]
208208
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
209+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
209210
param(
210211
[Parameter(ParameterSetName='Elements')]
211212
[string] $OwnerName,
@@ -320,6 +321,7 @@ function Remove-GitHubLabel
320321
SupportsShouldProcess,
321322
DefaultParameterSetName='Elements')]
322323
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
324+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
323325
[Alias('Delete-GitHubLabel')]
324326
param(
325327
[Parameter(ParameterSetName='Elements')]
@@ -551,6 +553,7 @@ function Set-GitHubLabel
551553
SupportsShouldProcess,
552554
DefaultParameterSetName='Elements')]
553555
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
556+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
554557
param(
555558
[Parameter(ParameterSetName='Elements')]
556559
[string] $OwnerName,
@@ -662,6 +665,7 @@ function Add-GitHubIssueLabel
662665
SupportsShouldProcess,
663666
DefaultParameterSetName='Elements')]
664667
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
668+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
665669
param(
666670
[Parameter(Mandatory, ParameterSetName='Elements')]
667671
[string] $OwnerName,
@@ -763,6 +767,7 @@ function Set-GitHubIssueLabel
763767
SupportsShouldProcess,
764768
DefaultParameterSetName='Elements')]
765769
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
770+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
766771
param(
767772
[Parameter(ParameterSetName='Elements')]
768773
[string] $OwnerName,

GitHubMilestones.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ function Remove-GitHubMilestone
506506
DefaultParameterSetName='Elements')]
507507
[Alias('Delete-GitHubMilestone')]
508508
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
509+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")]
509510
param(
510511
[Parameter(Mandatory, ParameterSetName='Elements')]
511512
[string] $OwnerName,

0 commit comments

Comments
 (0)