PowerShellForGitHub/USAGE.md

21 KiB

PowerShellForGitHub PowerShell Module

Usage

Table of Contents


Logging

All commands will log to the console, as well as to a log file, by default. The logging is affected by configuration properties (which can be checked with Get-GitHubConfiguration and changed with Set-GitHubConfiguration).

LogPath [string] The logfile. Defaults to $env:USERPROFILE\Documents\PowerShellForGitHub.log

DisableLogging [bool] Defaults to $false.

LogTimeAsUtc [bool] Defaults to $false. If $false, times are logged in local time. When $true, times are logged using UTC (and those timestamps will end with a Z per the W3C standard)

LogProcessId [bool] Defaults to $false. If $true, the Process ID ($global:PID) of the current PowerShell process will be added to every log entry. This can be helpful if you have situations where multiple instances of this module run concurrently and you want to more easily isolate the log entries for one process. An alternative solution would be to use Set-GitHubConfiguration -LogPath <path> -SessionOnly to specify a different log file for each PowerShell process. An easy way to view the filtered entries for a session is (replacing PID with the PID that you are interested in):

Get-Content -Path <logPath> -Encoding UTF8 | Where { $_ -like '*[[]PID[]]*' }

Telemetry

In order to track usage, gauge performance and identify areas for improvement, telemetry is employed during execution of commands within this module (via Application Insights). For more information, refer to the Privacy Policy.

You may notice some needed assemblies for communicating with Application Insights being downloaded on first run of a command within each PowerShell session. The automatic dependency downloads section of the setup documentation describes how you can avoid having to always re-download the telemetry assemblies in the future.

We recommend that you always leave the telemetry feature enabled, but a situation may arise where it must be disabled for some reason. In this scenario, you can disable telemetry by calling:

Set-GitHubConfiguration -DisableTelemetry -SessionOnly

The effect of that value will last for the duration of your session (until you close your console window). To make that change permanent, remove -SessionOnly from that call.

The following type of information is collected:

  • Every major command executed (to gauge usefulness of the various commands)
  • Types of parameters used with the command
  • Error codes / information

The following information is also collected, but the reported information is only reported in the form of an SHA512 Hash (to protect PII (personal identifiable information)):

  • Username
  • OwnerName
  • RepositoryName
  • OrganizationName

The hashing of the above items can be disabled (meaning that the plaint-text data will be reported instead of the hash of the data) by setting

Set-GitHubConfiguration -DisablePiiProtection -SessionOnly

Similar to DisableTelemetry, the effect of this value will only last for the duration of your session (until you close your console window), unless you call it without -SessionOnly.

The first time telemetry is tracked in a new PowerShell session, a reminder message will be displayed to the user. To suppress this reminder in the future, call:

Set-GitHubConfiguration -SuppressTelemetryReminder

Finally, the Application Insights Key that the telemetry is reported to is exposed as

Get-GitHubConfiguration -Name ApplicationInsightsKey

It is requested that you do not change this value, otherwise the telemetry will not be reported to us for analysis. We expose it here for complete transparency.


Examples

Analytics

Querying Issues

# Getting all of the issues from the PowerShell\xPSDesiredStateConfiguration repository
$issues = Get-GitHubIssue -OwnerName PowerShell -RepositoryName 'xPSDesiredStateConfiguration'
# An example of accomplishing what Get-GitHubIssueForRepository (from v0.1.0) used to do.
# Get all of the issues from multiple repos, but only return back the ones that were created within
# past two weeks.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$issues = @()
$repos | ForEach-Object { $issues += Get-GitHubIssue -Uri $_ }
$issues | Where-Object { $_.created_at -gt (Get-Date).AddDays(-14) }
# An example of accomplishing what Get-GitHubWeeklyIssueForRepository (from v0.1.0) used to do.
# Get all of the issues from multiple repos, and group them by the week in which they were created.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$issues = @()
$repos | ForEach-Object { $issues += Get-GitHubIssue -Uri $_ }
$issues | Group-GitHubIssue -Weeks 12 -DateType Created
# An example of accomplishing what Get-GitHubTopIssueRepository (from v0.1.0) used to do.
# Get all of the issues from multiple repos, and sort the repos by the number issues that they have.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$issueCounts = @()
$issueSearchParams = @{
    'State' = 'open'
}
$repos | ForEach-Object { $issueCounts += ([PSCustomObject]@{ 'Uri' = $_; 'Count' = (Get-GitHubIssue -Uri $_ @issueSearchParams).Count }) }
$issueCounts | Sort-Object -Property Count -Descending

Querying Pull Requests

# Getting all of the pull requests from the Microsoft\PowerShellForGitHub repository
$issues = Get-GitHubIssue -OwnerName Microsoft -RepositoryName 'PowerShellForGitHub'
# An example of accomplishing what Get-GitHubPullRequestForRepository (from v0.1.0) used to do.
# Get all of the pull requests from multiple repos, but only return back the ones that were created
# within the past two weeks.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$pullRequests = @()
$repos | ForEach-Object { $pullRequests += Get-GitHubPullRequest -Uri $_ }
$pullRequests | Where-Object { $_.created_at -gt (Get-Date).AddDays(-14) }
# An example of accomplishing what Get-GitHubWeeklyPullRequestForRepository (from v0.1.0) used to do.
# Get all of the pull requests from multiple repos, and group them by the week in which they were merged.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$pullRequests = @()
$repos | ForEach-Object { $pullRequests += Get-GitHubPullRequest -Uri $_ }
$pullRequests | Group-GitHubPullRequest -Weeks 12 -DateType Merged
# An example of accomplishing what Get-GitHubTopPullRequestRepository (from v0.1.0) used to do.
# Get all of the pull requests from multiple repos, and sort the repos by the number
# of closed pull requests that they have had within the past two weeks.
$repos = @('https://github.com/powershell/xpsdesiredstateconfiguration', 'https://github.com/powershell/xactivedirectory')
$pullRequestCounts = @()
$pullRequestSearchParams = @{
    'State' = 'closed'
}
$repos |
    ForEach-Object {
        $pullRequestCounts += ([PSCustomObject]@{
            'Uri' = $_;
            'Count' = (
                (Get-GitHubPullRequest -Uri $_ @pullRequestSearchParams) |
                    Where-Object { $_.completed_at -gt (Get-Date).AddDays(-14) }
            ).Count
        }) }

$pullRequestCounts | Sort-Object -Property Count -Descending

Querying Collaborators

$collaborators = Get-GitHubRepositoryCollaborators`
    -Uri @('https://github.com/PowerShell/DscResources')

Querying Contributors

# Getting all of the contributors for a single repository
$contributors = Get-GitHubRepositoryContributor -OwnerName 'PowerShell' -RepositoryName 'PowerShellForGitHub' }
# An example of accomplishing what Get-GitHubRepositoryContributors (from v0.1.0) used to do.
# Getting all of the contributors for a set of repositories
$repos = @('https://github.com/PowerShell/DscResources', 'https://github.com/PowerShell/xWebAdministration')
$contributors = @()
$repos | ForEach-Object { $contributors += Get-GitHubRepositoryContributor -Uri $_ }
# An example of accomplishing what Get-GitHubRepositoryUniqueContributor (from v0.1.0) used to do.
# Getting the unique set of contributors from the previous results of Get-GitHubRepositoryContributor
Get-GitHubRepositoryContributor -OwnerName 'PowerShell' -RepositoryName 'PowerShellForGitHub' } |
    Select-Object -ExpandProperty author |
    Select-Object -ExpandProperty login -Unique
    Sort-Object

Querying Team and Organization Membership

$organizationMembers = Get-GitHubOrganizationMembers -OrganizationName 'OrganizationName'
$teamMembers = Get-GitHubTeamMembers -OrganizationName 'OrganizationName' -TeamName 'TeamName'

Labels

Getting Labels for a Repository

$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration

Getting Labels for an Issue

$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Issue 1

Getting Labels for a Milestone

$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Milestone 1

Adding a New Label to a Repository

New-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Name TestLabel -Color BBBBBB

Removing a Label From a Repository

Remove-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Name TestLabel

Adding Labels to an Issue

$labelNames = @{'bug', 'discussion')
Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue 1 -LabelName $labelNames

Removing a Label From an Issue

Remove-GitHubIssueLabel -OwnerName Microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -Issue 1

Updating a Label With a New Name and Color

Update-GitHubLabel -OwnerName Microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00

Bulk Updating Labels in a Repository

$labels = @( @{ 'name' = 'Label1'; 'color' = 'BBBB00'; 'description' = 'My label description' }, @{ 'name' = 'Label2'; 'color' = 'FF00000' })
Set-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels

Users

Getting the current authenticated user

Get-GitHubUser -Current

Updating the current authenticated user

Update-GitHubCurrentUser -Location 'Seattle, WA' -Hireable:$false

Getting any user

Get-GitHubUser -Name octocat

Getting all users

Get-GitHubUser

Warning: This will take a while. It's getting every GitHub user.


Forks

Get all the forks for a repository

Get-GitHubRepositoryFork -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Create a new fork

New-GitHubRepositoryForm -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Traffic

Get the referrer traffic for a repository

Get-GitHubReferrerTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub
Get-GitHubPathTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Get the number of views for a repository

Get-GitHubViewTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Per Week

Get the number of clones for a repository

Get-GitHubCloneTraffic -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Per Day

Assignees

Get assignees

Get-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Check assignee permission

$HasPermission = Test-GitHubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123"

Add assignee to an issue

New-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1

Remove assignee from an issue

Remove-GithubAssignee -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1

Comments

Get comments from an issue

Get-GitHubIssueComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1

Get comments from a repository

Get-GitHubRepositoryComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort Created -Direction Ascending -Since '2011-04-14T16:00:49Z'

Get a single comment

Get-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1

Adding a new comment to an issue

New-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API"

Editing an existing comment

Set-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API"

Removing a comment

Remove-GitHubComment -OwnerName Microsoft -RepositoryName PowerShellForGitHub -CommentID 1

Milestones

Get milestones from a repository

Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Sort DueOn -Direction Ascending -DueOn '2011-04-14T16:00:49Z'

Get a single milestone

Get-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1

Assign an existing issue to a new milestone

New-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API"
Update-GitHubIssue -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1

Editing an existing milestone

Set-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API edited"

Removing a milestone

Remove-GitHubMilestone -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Milestone 1

Events

Get events from a repository

Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Get events from an issue

Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Issue 1

Get a single event

Get-GitHubEvent -OwnerName Microsoft -RepositoryName PowerShellForGitHub -EventID 1

Projects

Get projects for a repository

Get-GitHubProject -OwnerName Microsoft -RepositoryName PowerShellForGitHub

Get projects for a user

Get-GitHubProject -UserName octocat

Create a project

New-GitHubProject -OwnerName octocat -RepositoryName PowerShellForGitHub -Name TestProject

Add a column to a project

New-GitHubProjectColumn -Project 1 -Name 'To Do'

Add a card to a column

New-GitHubProjectCard -Column 2 -Note 'Fix this bug'

Add an existing issue as a card to a column

New-GitHubProjectCard -Column 2 -ContentId 3 -ContentType Issue

Move a card to be after a certain card in the same column

Move-GitHubProjectCard -Card 4 -After 5

Move a card to the bottom of another column

Move-GitHubProjectCard -Card 4 -ColumnId 6 -Bottom

Advanced

Migrating blog comments to GitHub issues

@LazyWinAdmin used this module to migrate his blog comments from Disqus to GitHub Issues. See blog post for full details.

# Create an issue
$IssueObject = New-GitHubIssue @githubsplat -Title $IssueTitle -Body $body -Label 'blog comments'

# Create Comment
New-GitHubComment @githubsplat -Issue $IssueObject.number -Body $CommentBody

# Close issue
Update-GitHubIssue @githubsplat -Issue $IssueObject.number -State Closed