Skip to content

Commit

Permalink
Get PSScriptAnalyzer clean again
Browse files Browse the repository at this point in the history
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.

Also, it turns out that `Group-GitHubPullRequest` hadn't actually been
exported, so I fixed that too.
  • Loading branch information
HowardWolosky committed May 26, 2020
1 parent c4c1ec3 commit 1a9b8ca
Show file tree
Hide file tree
Showing 24 changed files with 329 additions and 128 deletions.
164 changes: 110 additions & 54 deletions GitHubAnalytics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function Group-GitHubIssue
SupportsShouldProcess,
DefaultParameterSetName='Weekly')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="DateType due to PowerShell/PSScriptAnalyzer#1472")]
param
(
[Parameter(
Expand All @@ -55,41 +56,68 @@ function Group-GitHubIssue
[string] $DateType = 'Created'
)

Write-InvocationLog

if ($PSCmdlet.ParameterSetName -eq 'Weekly')
begin
{
$totalIssues = 0
$weekDates = Get-WeekDate -Weeks $Weeks
$endOfWeek = Get-Date
Write-InvocationLog

foreach ($week in $weekDates)
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
$filteredIssues = @($Issue | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
})

$endOfWeek = $week
$count = $filteredIssues.Count
$totalIssues += $count

Write-Output -InputObject ([PSCustomObject]([ordered]@{
'WeekStart' = $week
'Count' = $count
'Issues' = $filteredIssues
$weekDates = Get-WeekDate -Weeks $Weeks

$result = [ordered]@{}
foreach ($week in $weekDates)
{
$result[$week] = ([PSCustomObject]([ordered]@{
'WeekStart' = $week
'Count' = 0
'Issues' = @()
}))
}

$result['total'] = ([PSCustomObject]([ordered]@{
'WeekStart' = 'total'
'Count' = 0
'Issues' = @()
}))
}
}

Write-Output -InputObject ([PSCustomObject]([ordered]@{
'WeekStart' = 'total'
'Count' = $totalIssues
'Issues' = $Issue
}))
process
{
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
$endOfWeek = Get-Date
foreach ($week in $weekDates)
{
$filteredIssues = @($Issue | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Closed') -and ($_.closed_at -ge $week) -and ($_.closed_at -le $endOfWeek))
})

$endOfWeek = $week

$result[$week].Issues += $filteredIssues
$result[$week].Count += ($filteredIssues.Count)

$result['total'].Issues += $filteredIssues
$result['total'].Count += ($filteredIssues.Count)
}
}
else
{
Write-Output -InputObject $Issue
}
}
else

end
{
Write-Output -InputObject $Issue
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
foreach ($entry in $result.Values.GetEnumerator())
{
Write-Output -InputObject $entry
}
}
}
}

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

Write-InvocationLog

if ($PSCmdlet.ParameterSetName -eq 'Weekly')
begin
{
$totalPullRequests = 0
$weekDates = Get-WeekDate -Weeks $Weeks
$endOfWeek = Get-Date
Write-InvocationLog

foreach ($week in $weekDates)
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
$filteredPullRequests = @($PullRequest | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
})

$endOfWeek = $week
$count = $filteredPullRequests.Count
$totalPullRequests += $count

Write-Output -InputObject ([PSCustomObject]([ordered]@{
'WeekStart' = $week
'Count' = $count
'PullRequests' = $filteredPullRequests
$weekDates = Get-WeekDate -Weeks $Weeks

$result = [ordered]@{}
foreach ($week in $weekDates)
{
$result[$week] = ([PSCustomObject]([ordered]@{
'WeekStart' = $week
'Count' = 0
'PullRequests' = @()
}))
}

$result['total'] = ([PSCustomObject]([ordered]@{
'WeekStart' = 'total'
'Count' = 0
'PullRequests' = @()
}))
}
}

Write-Output -InputObject ([PSCustomObject]([ordered]@{
'WeekStart' = 'total'
'Count' = $totalPullRequests
'PullRequests' = $PullRequest
}))
process
{
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
$endOfWeek = Get-Date
foreach ($week in $weekDates)
{
$filteredPullRequests = @($PullRequest | Where-Object {
(($DateType -eq 'Created') -and ($_.created_at -ge $week) -and ($_.created_at -le $endOfWeek)) -or
(($DateType -eq 'Merged') -and ($_.merged_at -ge $week) -and ($_.merged_at -le $endOfWeek))
})

$endOfWeek = $week

$result[$week].PullRequests += $filteredPullRequests
$result[$week].Count += ($filteredPullRequests.Count)

$result['total'].PullRequests += $filteredPullRequests
$result['total'].Count += ($filteredPullRequests.Count)
}
}
else
{
Write-Output -InputObject $PullRequest
}
}
else

end
{
Write-Output -InputObject $PullRequest
if ($PSCmdlet.ParameterSetName -eq 'Weekly')
{
foreach ($entry in $result.Values.GetEnumerator())
{
Write-Output -InputObject $entry
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions GitHubAssignees.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function Get-GitHubAssignee
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -128,6 +129,7 @@ function Test-GitHubAssignee
DefaultParameterSetName='Elements')]
[OutputType([bool])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -228,6 +230,7 @@ function New-GithubAssignee
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -330,6 +333,7 @@ function Remove-GithubAssignee
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down
1 change: 1 addition & 0 deletions GitHubBranches.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Get-GitHubRepositoryBranch
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
[Alias('Get-GitHubBranch')]
param(
[Parameter(ParameterSetName='Elements')]
Expand Down
3 changes: 3 additions & 0 deletions GitHubComments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function New-GitHubComment
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -355,6 +356,7 @@ function Set-GitHubComment
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -456,6 +458,7 @@ function Remove-GitHubComment
DefaultParameterSetName='Elements')]
[Alias('Delete-GitHubComment')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down
1 change: 1 addition & 0 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ function Invoke-GHRestMethodMultipleResult
#>
[CmdletBinding(SupportsShouldProcess)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
[OutputType([Object[]])]
param(
[Parameter(Mandatory)]
Expand Down
2 changes: 2 additions & 0 deletions GitHubIssues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ function Get-GitHubIssueTimeline
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -861,6 +862,7 @@ function Unlock-GitHubIssue
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down
5 changes: 5 additions & 0 deletions GitHubLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function New-GitHubLabel
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -320,6 +321,7 @@ function Remove-GitHubLabel
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
[Alias('Delete-GitHubLabel')]
param(
[Parameter(ParameterSetName='Elements')]
Expand Down Expand Up @@ -551,6 +553,7 @@ function Set-GitHubLabel
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -662,6 +665,7 @@ function Add-GitHubIssueLabel
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(Mandatory, ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down Expand Up @@ -763,6 +767,7 @@ function Set-GitHubIssueLabel
SupportsShouldProcess,
DefaultParameterSetName='Elements')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down
1 change: 1 addition & 0 deletions GitHubMilestones.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ function Remove-GitHubMilestone
DefaultParameterSetName='Elements')]
[Alias('Delete-GitHubMilestone')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
[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.")]
param(
[Parameter(Mandatory, ParameterSetName='Elements')]
[string] $OwnerName,
Expand Down
Loading

0 comments on commit 1a9b8ca

Please sign in to comment.