-
Notifications
You must be signed in to change notification settings - Fork 189
Add Support for the Github Traffic APIs #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HowardWolosky
merged 8 commits into
microsoft:master
from
joseartrivera:joriv/TrafficSupport
Nov 16, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
390f28f
Add traffic support
joseartrivera 16b617a
Use regular get
joseartrivera 8f71142
Fix duplicate comment
joseartrivera 5698435
rename files
joseartrivera d383c18
Delete repros
joseartrivera 9ab5b62
Move deletion into curly brace
joseartrivera 9af7dc2
Delete renamed file that was added
joseartrivera c283c9c
Add per param
joseartrivera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,362 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| function Get-GitHubReferrerTraffic | ||
| { | ||
| <# | ||
| .SYNOPSIS | ||
| Get the top 10 referrers over the last 14 days for a given GitHub repository. | ||
|
|
||
| .DESCRIPTION | ||
| Get the top 10 referrers over the last 14 days for a given GitHub repository. | ||
|
|
||
| The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub | ||
|
|
||
| .PARAMETER OwnerName | ||
| Owner of the repository. | ||
| If not supplied here, the DefaultOwnerName configuration property value will be used. | ||
|
|
||
| .PARAMETER RepositoryName | ||
| Name of the repository. | ||
| If not supplied here, the DefaultRepositoryName configuration property value will be used. | ||
|
|
||
| .PARAMETER Uri | ||
| Uri for the repository. | ||
| The OwnerName and RepositoryName will be extracted from here instead of needing to provide | ||
| them individually. | ||
|
|
||
| .PARAMETER AccessToken | ||
| If provided, this will be used as the AccessToken for authentication with the | ||
| REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. | ||
|
|
||
| .PARAMETER NoStatus | ||
| If this switch is specified, long-running commands will run on the main thread | ||
| with no commandline status update. When not specified, those commands run in | ||
| the background, enabling the command prompt to provide status information. | ||
| If not supplied here, the DefaultNoStatus configuration property value will be used. | ||
|
|
||
| .EXAMPLE | ||
| Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub | ||
|
|
||
| Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project. | ||
| #> | ||
| [CmdletBinding( | ||
| 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.")] | ||
| param( | ||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $OwnerName, | ||
|
|
||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $RepositoryName, | ||
|
|
||
| [Parameter( | ||
| Mandatory, | ||
| ParameterSetName='Uri')] | ||
| [string] $Uri, | ||
|
|
||
| [string] $AccessToken, | ||
|
|
||
| [switch] $NoStatus | ||
| ) | ||
|
|
||
| Write-InvocationLog -Invocation $MyInvocation | ||
|
|
||
| $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters | ||
| $OwnerName = $elements.ownerName | ||
| $RepositoryName = $elements.repositoryName | ||
|
|
||
| $telemetryProperties = @{ | ||
| 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) | ||
| 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) | ||
| } | ||
|
|
||
| $params = @{ | ||
| 'UriFragment' = "repos/$OwnerName/$RepositoryName/traffic/popular/referrers" | ||
| 'Method' = 'Get' | ||
| 'Description' = "Getting referrers for $RepositoryName" | ||
| 'AccessToken' = $AccessToken | ||
| 'TelemetryEventName' = $MyInvocation.MyCommand.Name | ||
| 'TelemetryProperties' = $telemetryProperties | ||
| 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) | ||
| } | ||
|
|
||
| return Invoke-GHRestMethod @params | ||
| } | ||
|
|
||
| function Get-GitHubPathTraffic | ||
| { | ||
| <# | ||
| .SYNOPSIS | ||
| Get the top 10 popular contents over the last 14 days for a given Github repository. | ||
|
|
||
| .DESCRIPTION | ||
| Get the top 10 popular contents over the last 14 days for a given GitHub repository. | ||
|
|
||
| The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub | ||
|
|
||
| .PARAMETER OwnerName | ||
| Owner of the repository. | ||
| If not supplied here, the DefaultOwnerName configuration property value will be used. | ||
|
|
||
| .PARAMETER RepositoryName | ||
| Name of the repository. | ||
| If not supplied here, the DefaultRepositoryName configuration property value will be used. | ||
|
|
||
| .PARAMETER Uri | ||
| Uri for the repository. | ||
| The OwnerName and RepositoryName will be extracted from here instead of needing to provide | ||
| them individually. | ||
|
|
||
| .PARAMETER AccessToken | ||
| If provided, this will be used as the AccessToken for authentication with the | ||
| REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. | ||
|
|
||
| .PARAMETER NoStatus | ||
| If this switch is specified, long-running commands will run on the main thread | ||
| with no commandline status update. When not specified, those commands run in | ||
| the background, enabling the command prompt to provide status information. | ||
| If not supplied here, the DefaultNoStatus configuration property value will be used. | ||
|
|
||
| .EXAMPLE | ||
| Get-GitHubPathTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub | ||
|
|
||
| Get the top 10 popular contents over the last 14 days from the PowerShell\PowerShellForGitHub project. | ||
| #> | ||
| [CmdletBinding( | ||
| 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.")] | ||
| param( | ||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $OwnerName, | ||
|
|
||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $RepositoryName, | ||
|
|
||
| [Parameter( | ||
| Mandatory, | ||
| ParameterSetName='Uri')] | ||
| [string] $Uri, | ||
|
|
||
| [string] $AccessToken, | ||
|
|
||
| [switch] $NoStatus | ||
| ) | ||
|
|
||
| Write-InvocationLog -Invocation $MyInvocation | ||
|
|
||
| $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters | ||
| $OwnerName = $elements.ownerName | ||
| $RepositoryName = $elements.repositoryName | ||
|
|
||
| $telemetryProperties = @{ | ||
| 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) | ||
| 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) | ||
| } | ||
|
|
||
| $params = @{ | ||
| 'UriFragment' = "repos/$OwnerName/$RepositoryName/traffic/popular/paths" | ||
| 'Method' = 'Get' | ||
| 'Description' = "Getting popular contents for $RepositoryName" | ||
| 'AccessToken' = $AccessToken | ||
| 'TelemetryEventName' = $MyInvocation.MyCommand.Name | ||
| 'TelemetryProperties' = $telemetryProperties | ||
| 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) | ||
| } | ||
|
|
||
| return Invoke-GHRestMethod @params | ||
| } | ||
|
|
||
| function Get-GitHubViewTraffic | ||
| { | ||
| <# | ||
| .SYNOPSIS | ||
| Get the total number of views and breakdown per day or week for the last 14 days for the given Github Repository. | ||
|
|
||
| .DESCRIPTION | ||
| Get the total number of views and breakdown per day or week for the last 14 days. | ||
| Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday. | ||
|
|
||
| The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub | ||
|
|
||
| .PARAMETER OwnerName | ||
| Owner of the repository. | ||
| If not supplied here, the DefaultOwnerName configuration property value will be used. | ||
|
|
||
| .PARAMETER RepositoryName | ||
| Name of the repository. | ||
| If not supplied here, the DefaultRepositoryName configuration property value will be used. | ||
|
|
||
| .PARAMETER Uri | ||
| Uri for the repository. | ||
| The OwnerName and RepositoryName will be extracted from here instead of needing to provide | ||
| them individually. | ||
|
|
||
| .PARAMETER Per | ||
| The interval at which return to return the view counts. | ||
|
|
||
| .PARAMETER AccessToken | ||
| If provided, this will be used as the AccessToken for authentication with the | ||
| REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. | ||
|
|
||
| .PARAMETER NoStatus | ||
| If this switch is specified, long-running commands will run on the main thread | ||
| with no commandline status update. When not specified, those commands run in | ||
| the background, enabling the command prompt to provide status information. | ||
| If not supplied here, the DefaultNoStatus configuration property value will be used. | ||
|
|
||
| .EXAMPLE | ||
| Get-GitHubViewTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub | ||
|
|
||
| Get the total number of views and breakdown per day or week for the last 14 days from the PowerShell\PowerShellForGitHub project. | ||
| #> | ||
| [CmdletBinding( | ||
| 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.")] | ||
| param( | ||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $OwnerName, | ||
|
|
||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $RepositoryName, | ||
|
|
||
| [Parameter( | ||
| Mandatory, | ||
| ParameterSetName='Uri')] | ||
| [string] $Uri, | ||
|
|
||
| [ValidateSet('day', 'week')] | ||
| [string] $Per = 'day', | ||
|
|
||
| [string] $AccessToken, | ||
|
|
||
| [switch] $NoStatus | ||
| ) | ||
|
|
||
| Write-InvocationLog -Invocation $MyInvocation | ||
|
|
||
| $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters | ||
| $OwnerName = $elements.ownerName | ||
| $RepositoryName = $elements.repositoryName | ||
|
|
||
| $telemetryProperties = @{ | ||
| 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) | ||
| 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) | ||
| 'Per' = $Per | ||
| } | ||
|
|
||
| $getParams = @( | ||
| "per=$Per" | ||
| ) | ||
|
|
||
| $params = @{ | ||
| 'UriFragment' = "repos/$OwnerName/$RepositoryName/traffic/views`?" + ($getParams -join '&') | ||
| 'Method' = 'Get' | ||
| 'Description' = "Getting views for $RepositoryName" | ||
| 'AccessToken' = $AccessToken | ||
| 'TelemetryEventName' = $MyInvocation.MyCommand.Name | ||
| 'TelemetryProperties' = $telemetryProperties | ||
| 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) | ||
| } | ||
|
|
||
| return Invoke-GHRestMethod @params | ||
| } | ||
|
|
||
| function Get-GitHubCloneTraffic | ||
| { | ||
| <# | ||
| .SYNOPSIS | ||
| Get the total number of clones and breakdown per day or week for the last 14 days for the given Github Repository. | ||
|
|
||
| .DESCRIPTION | ||
| Get the total number of clones and breakdown per day or week for the last 14 days. | ||
| Timestamps are aligned to UTC midnight of the beginning of the day or week. Week begins on Monday. | ||
|
|
||
| The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub | ||
|
|
||
| .PARAMETER OwnerName | ||
| Owner of the repository. | ||
| If not supplied here, the DefaultOwnerName configuration property value will be used. | ||
|
|
||
| .PARAMETER RepositoryName | ||
| Name of the repository. | ||
| If not supplied here, the DefaultRepositoryName configuration property value will be used. | ||
|
|
||
| .PARAMETER Uri | ||
| Uri for the repository. | ||
| The OwnerName and RepositoryName will be extracted from here instead of needing to provide | ||
| them individually. | ||
|
|
||
| .PARAMETER Per | ||
| The interval at which return to return the view counts. | ||
|
|
||
| .PARAMETER AccessToken | ||
| If provided, this will be used as the AccessToken for authentication with the | ||
| REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated. | ||
|
|
||
| .PARAMETER NoStatus | ||
| If this switch is specified, long-running commands will run on the main thread | ||
| with no commandline status update. When not specified, those commands run in | ||
| the background, enabling the command prompt to provide status information. | ||
| If not supplied here, the DefaultNoStatus configuration property value will be used. | ||
|
|
||
| .EXAMPLE | ||
| Get-GitHubCloneTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub | ||
|
|
||
| Get the total number of clones and breakdown per day or week for the last 14 days from the PowerShell\PowerShellForGitHub project. | ||
| #> | ||
| [CmdletBinding( | ||
| 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.")] | ||
| param( | ||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $OwnerName, | ||
|
|
||
| [Parameter(ParameterSetName='Elements')] | ||
| [string] $RepositoryName, | ||
|
|
||
| [Parameter( | ||
| Mandatory, | ||
| ParameterSetName='Uri')] | ||
| [string] $Uri, | ||
|
|
||
| [ValidateSet('day', 'week')] | ||
| [string] $Per = 'day', | ||
|
|
||
| [string] $AccessToken, | ||
|
|
||
| [switch] $NoStatus | ||
| ) | ||
|
|
||
| Write-InvocationLog -Invocation $MyInvocation | ||
|
|
||
| $elements = Resolve-RepositoryElements -BoundParameters $PSBoundParameters | ||
| $OwnerName = $elements.ownerName | ||
| $RepositoryName = $elements.repositoryName | ||
|
|
||
| $telemetryProperties = @{ | ||
| 'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName) | ||
| 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) | ||
| 'Per' = $Per | ||
| } | ||
|
|
||
| $getParams = @( | ||
| "per=$Per" | ||
| ) | ||
|
|
||
| $params = @{ | ||
| 'UriFragment' = "repos/$OwnerName/$RepositoryName/traffic/clones`?" + ($getParams -join '&') | ||
| 'Method' = 'Get' | ||
| 'Description' = "Getting number of clones for $RepositoryName" | ||
| 'AccessToken' = $AccessToken | ||
| 'TelemetryEventName' = $MyInvocation.MyCommand.Name | ||
| 'TelemetryProperties' = $telemetryProperties | ||
| 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus) | ||
| } | ||
|
|
||
| return Invoke-GHRestMethod @params | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like
$getParamsis used elsewhere with multiple elements and we're just matching a style here. It seems unnecessary and I would support just adding"per=$Per"to the rest of the UriFragment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally reasonable feedback. I'm preparing to publish the 0.4.0 update. I can make that minor change.