Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions GitHubAnalytics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Group-GitHubIssue
$issues = @()
$issues += Get-GitHubIssue -Uri 'https://github.com/powershell/xpsdesiredstateconfiguration'
$issues += Get-GitHubIssue -Uri 'https://github.com/powershell/xactivedirectory'
$issues | Group-GitHubIssue -Weeks 12 -DateType closed
$issues | Group-GitHubIssue -Weeks 12 -DateType Closed
#>
[CmdletBinding(
SupportsShouldProcess,
Expand All @@ -51,8 +51,8 @@ function Group-GitHubIssue
[int] $Weeks,

[Parameter(ParameterSetName='Weekly')]
[ValidateSet('created', 'closed')]
[string] $DateType = 'created'
[ValidateSet('Created', 'Closed')]
[string] $DateType = 'Created'
)

Write-InvocationLog
Expand All @@ -66,8 +66,8 @@ function Group-GitHubIssue
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))
(($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
Expand Down Expand Up @@ -124,7 +124,7 @@ function Group-GitHubPullRequest
$pullRequests = @()
$pullRequests += Get-GitHubPullRequest -Uri 'https://github.com/powershell/xpsdesiredstateconfiguration'
$pullRequests += Get-GitHubPullRequest -Uri 'https://github.com/powershell/xactivedirectory'
$pullRequests | Group-GitHubPullRequest -Weeks 12 -DateType closed
$pullRequests | Group-GitHubPullRequest -Weeks 12 -DateType Closed
#>
[CmdletBinding(
SupportsShouldProcess,
Expand All @@ -144,8 +144,8 @@ function Group-GitHubPullRequest
[int] $Weeks,

[Parameter(ParameterSetName='Weekly')]
[ValidateSet('created', 'merged')]
[string] $DateType = 'created'
[ValidateSet('Created', 'Merged')]
[string] $DateType = 'Created'
)

Write-InvocationLog
Expand All @@ -159,8 +159,8 @@ function Group-GitHubPullRequest
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))
(($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
Expand Down
40 changes: 23 additions & 17 deletions GitHubComments.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ function Get-GitHubComment

[Parameter(ParameterSetName='RepositoryUri')]
[Parameter(ParameterSetName='RepositoryElements')]
[ValidateSet('created', 'updated')]
[ValidateSet('Created', 'Updated')]
[string] $Sort,

[Parameter(ParameterSetName='RepositoryUri')]
[Parameter(ParameterSetName='RepositoryElements')]
[ValidateSet('asc', 'desc')]
[ValidateSet('Ascending', 'Descending')]
[string] $Direction,

[ValidateSet('raw', 'text', 'html', 'full')]
[string] $MediaType ='raw',
[ValidateSet('Raw', 'Text', 'Html', 'Full')]
[string] $MediaType ='Raw',

[string] $AccessToken,

Expand All @@ -120,9 +120,10 @@ function Get-GitHubComment
$uriFragment = [String]::Empty
$description = [String]::Empty

$sinceFormattedTime = [String]::Empty
if ($null -ne $Since)
{
$SinceFormattedTime = $Since.ToUniversalTime().ToString('o')
$sinceFormattedTime = $Since.ToUniversalTime().ToString('o')
}

$telemetryProperties = @{
Expand All @@ -143,7 +144,7 @@ function Get-GitHubComment

if ($PSBoundParameters.ContainsKey('Since'))
{
$uriFragment += "since=$SinceFormattedTime"
$uriFragment += "since=$sinceFormattedTime"
}

$description = "Getting comments for issue $Issue in $RepositoryName"
Expand All @@ -154,17 +155,22 @@ function Get-GitHubComment

if ($PSBoundParameters.ContainsKey('Sort'))
{
$getParams += "sort=$Sort"
$getParams += "sort=$($Sort.ToLower())"
}

if ($PSBoundParameters.ContainsKey('Direction'))
{
$getParams += "direction=$Direction"
$directionConverter = @{
'Ascending' = 'asc'
'Descending' = 'desc'
}

$getParams += "direction=$($directionConverter[$Direction])"
}

if ($PSBoundParameters.ContainsKey('Since'))
{
$getParams += "since=$SinceFormattedTime"
$getParams += "since=$sinceFormattedTime"
}

$uriFragment = "repos/$OwnerName/$RepositoryName/issues/comments`?" + ($getParams -join '&')
Expand Down Expand Up @@ -256,8 +262,8 @@ function New-GitHubComment
[Parameter(Mandatory)]
[string] $Body,

[ValidateSet('raw', 'text', 'html', 'full')]
[string] $MediaType ='raw',
[ValidateSet('Raw', 'Text', 'Html', 'Full')]
[string] $MediaType ='Raw',

[string] $AccessToken,

Expand Down Expand Up @@ -367,8 +373,8 @@ function Set-GitHubComment
[Parameter(Mandatory)]
[string] $Body,

[ValidateSet('raw', 'text', 'html', 'full')]
[string] $MediaType ='raw',
[ValidateSet('Raw', 'Text', 'Html', 'Full')]
[string] $MediaType ='Raw',

[string] $AccessToken,

Expand Down Expand Up @@ -512,19 +518,19 @@ function Get-CommentAcceptHeader
full - Return raw, text and HTML representations. Response will include body, body_text, and body_html.

.EXAMPLE
Get-CommentAcceptHeader -MediaType raw
Get-CommentAcceptHeader -MediaType Raw

Returns a formatted AcceptHeader for v3 of the response object
#>
[CmdletBinding()]
param(
[ValidateSet('raw', 'text', 'html', 'full')]
[string] $MediaType ='raw'
[ValidateSet('Raw', 'Text', 'Html', 'Full')]
[string] $MediaType ='Raw'
)

$acceptHeaders = @(
'application/vnd.github.squirrel-girl-preview',
"application/vnd.github.$mediaTypeVersion.$MediaType+json")
"application/vnd.github.$mediaTypeVersion.$($MediaType.ToLower())+json")

return ($acceptHeaders -join ',')
}
8 changes: 4 additions & 4 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
}

Set-Variable -Scope Script -Option ReadOnly -Name ValidBodyContainingRequestMethods -Value ('post', 'patch', 'put', 'delete')
Set-Variable -Scope Script -Option ReadOnly -Name ValidBodyContainingRequestMethods -Value ('Post', 'Patch', 'Put', 'Delete')

function Invoke-GHRestMethod
{
Expand Down Expand Up @@ -102,7 +102,7 @@ function Invoke-GHRestMethod
[string] $UriFragment,

[Parameter(Mandatory)]
[ValidateSet('delete', 'get', 'post', 'patch', 'put')]
[ValidateSet('Delete', 'Get', 'Post', 'Patch', 'Put')]
[string] $Method,

[string] $Description,
Expand Down Expand Up @@ -208,7 +208,7 @@ function Invoke-GHRestMethod

[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
$result = Invoke-WebRequest @params
if ($Method -eq 'delete')
if ($Method -eq 'Delete')
{
Write-Log -Message "Successfully removed." -Level Verbose
}
Expand Down Expand Up @@ -306,7 +306,7 @@ function Invoke-GHRestMethod
throw $remoteErrors[0].Exception
}

if ($Method -eq 'delete')
if ($Method -eq 'Delete')
{
Write-Log -Message "Successfully removed." -Level Verbose
}
Expand Down
68 changes: 40 additions & 28 deletions GitHubIssues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ function Get-GitHubIssue
If not supplied here, the DefaultNoStatus configuration property value will be used.

.EXAMPLE
Get-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -State open
Get-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -State Open

Gets all the currently open issues in the PowerShell\PowerShellForGitHub repository.

.EXAMPLE
Get-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -State all -Assignee Octocat
Get-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -State All -Assignee Octocat

Gets every issue in the PowerShell\PowerShellForGitHub repository that is assigned to Octocat.
#>
Expand All @@ -125,35 +125,35 @@ function Get-GitHubIssue

[string] $OrganizationName,

[ValidateSet('all', 'ownedAndMember')]
[string] $RepositoryType = 'all',
[ValidateSet('All', 'OwnedAndMember')]
[string] $RepositoryType = 'All',

[int] $Issue,

[switch] $IgnorePullRequests,

[ValidateSet('assigned', 'created', 'mentioned', 'subscribed', 'all')]
[string] $Filter = 'assigned',
[ValidateSet('Assigned', 'Created', 'Mentioned', 'Subscribed', 'All')]
[string] $Filter = 'Assigned',

[ValidateSet('open', 'closed', 'all')]
[string] $State = 'open',
[ValidateSet('Open', 'Closed', 'All')]
[string] $State = 'Open',

[string[]] $Label,

[ValidateSet('created', 'updated', 'comments')]
[string] $Sort = 'created',
[ValidateSet('Created', 'Updated', 'Comments')]
[string] $Sort = 'Created',

[ValidateSet('asc', 'desc')]
[string] $Direction = 'desc',
[ValidateSet('Ascending', 'Descending')]
[string] $Direction = 'Descending',

[DateTime] $Since,

[ValidateSet('specific', 'all', 'none')]
[ValidateSet('Specific', 'All', 'None')]
[string] $MilestoneType,

[string] $Milestone,

[ValidateSet('specific', 'all', 'none')]
[ValidateSet('Specific', 'All', 'None')]
[string] $AssigneeType,

[string] $Assignee,
Expand Down Expand Up @@ -203,12 +203,12 @@ function Get-GitHubIssue
$uriFragment = "/orgs/$OrganizationName/issues"
$description = "Getting issues for $OrganizationName"
}
elseif ($RepositoryType -eq 'all')
elseif ($RepositoryType -eq 'All')
{
$uriFragment = "/issues"
$description = "Getting issues across owned, member and org repositories"
}
elseif ($RepositoryType -eq 'ownedAndMember')
elseif ($RepositoryType -eq 'OwnedAndMember')
{
$uriFragment = "/user/issues"
$description = "Getting issues across owned and member repositories"
Expand All @@ -218,11 +218,16 @@ function Get-GitHubIssue
throw "Parameter set not supported."
}

$directionConverter = @{
'Ascending' = 'asc'
'Descending' = 'desc'
}

$getParams = @(
"filter=$Filter",
"state=$State",
"sort=$Sort",
"direction=$Direction"
"filter=$($Filter.ToLower())",
"state=$($State.ToLower())",
"sort=$($Sort.ToLower())",
"direction=$($directionConverter[$Direction])"
)

if ($PSBoundParameters.ContainsKey('Label'))
Expand All @@ -242,11 +247,11 @@ function Get-GitHubIssue

if ($PSBoundParameters.ContainsKey('MilestoneType'))
{
if ($MilestoneType -eq 'all')
if ($MilestoneType -eq 'All')
{
$getParams += 'mentioned=*'
}
elseif ($MilestoneType -eq 'none')
elseif ($MilestoneType -eq 'None')
{
$getParams += 'mentioned=none'
}
Expand Down Expand Up @@ -585,7 +590,7 @@ function Update-GitHubIssue
If not supplied here, the DefaultNoStatus configuration property value will be used.

.EXAMPLE
Update-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State closed
Update-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed
#>
[CmdletBinding(
SupportsShouldProcess,
Expand Down Expand Up @@ -616,7 +621,7 @@ function Update-GitHubIssue

[string[]] $Label,

[ValidateSet('open', 'closed')]
[ValidateSet('Open', 'Closed')]
[string] $State,

[string] $AccessToken,
Expand All @@ -641,7 +646,7 @@ function Update-GitHubIssue
if ($PSBoundParameters.ContainsKey('Body')) { $hashBody['body'] = $Body }
if ($PSBoundParameters.ContainsKey('Assignee')) { $hashBody['assignees'] = @($Assignee) }
if ($PSBoundParameters.ContainsKey('Label')) { $hashBody['labels'] = @($Label) }
if ($PSBoundParameters.ContainsKey('State')) { $hashBody['state'] = $State }
if ($PSBoundParameters.ContainsKey('State')) { $hashBody['state'] = $State.ToLower() }
if ($PSBoundParameters.ContainsKey('Milestone'))
{
$hashBody['milestone'] = $Milestone
Expand Down Expand Up @@ -707,7 +712,7 @@ function Lock-GitHubIssue
If not supplied here, the DefaultNoStatus configuration property value will be used.

.EXAMPLE
Lock-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -Reason spam
Lock-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -Reason Spam
#>
[CmdletBinding(
SupportsShouldProcess,
Expand All @@ -728,7 +733,7 @@ function Lock-GitHubIssue
[Parameter(Mandatory)]
[int] $Issue,

[ValidateSet('off-topic', 'too heated', 'resolved', 'spam')]
[ValidateSet('OffTopic', 'TooHeated', 'Resolved', 'Spam')]
[string] $Reason,

[string] $AccessToken,
Expand All @@ -753,8 +758,15 @@ function Lock-GitHubIssue

if ($PSBoundParameters.ContainsKey('Reason'))
{
$reasonConverter = @{
'OffTopic' = 'off-topic'
'TooHeated' = 'too heated'
'Resolved' = 'resolved'
'Spam' = 'spam'
}

$telemetryProperties['Reason'] = $Reason
$hashBody['active_lock_reason'] = $Reason
$hashBody['active_lock_reason'] = $reasonConverter[$Reason]
}

$params = @{
Expand Down
Loading