- Full Module Documentation
- Logging
- Telemetry
- Common PowerShell API Patterns
- Examples
- Overview
- Analytics
- Labels
- Users
- Teams
- Repositories
- Create a repository
- Create a repository in an organization
- Create a repository in an organization and grant access to a team
- Create a repository from a template repository
- Get repository vulnerability alert status
- Enable repository vulnerability alerts
- Disable repository vulnerability alerts
- Enable repository automatic security fixes
- Disable repository automatic security fixes
- Get repository GitHub Actions permissions
- Set repository GitHub Actions permissions
- Get a repository team permission
- Set a repository team permission
- Remove a repository team permission
- Branches
- Adding a new Branch to a Repository
- Removing a Branch from a Repository
- Getting a repository branch protection rule
- Creating a repository branch protection rule
- Removing a repository branch protection rule
- Getting a repository branch pattern protection rule
- Creating a repository branch pattern protection rule
- Removing a repository branch pattern protection rule
- Forks
- Content
- Traffic
- Assignees
- Comments
- Milestones
- Events
- Projects
- Releases
- Gists
- Deployments Environments
- Advanced
- Codespaces
- Codespaces
All commands for the module have "Comment-Based Help" available at your fingertips. You can access that help at any time by running:
Get-Help -Full <commandName>
In addition to accessing it from the commandline, all of that help documentation is also available online on our wiki.
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
([System.Environment]::GetFolderPath('MyDocuments'))\PowerShellForGitHub.log
. Will default to
([System.Environment]::GetFolderPath('LocalApplicationData'))\PowerShellForGitHub.log
when
there is no user profile (like in an Azure environment).
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[]]*' }
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.
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.
This module adopts many of the standard PowerShell API design patterns. We want to call attention to those patterns here so that you can identify how you can most efficiently use the module.
All commands that result in removing/deleting an object, as well as some commands that rename
objects (like renaming a repository) require user confirmation before the comamnd will be processed.
You can avoid that user confirmation by passing in either -Confirm:$false
or -Force
.
Any command that isn't Get-GitHub*
supports the -WhatIf
switch. You can safely call that
command by passing in the -WhatIf
switch and know that the request will not actually be sent
to GitHub. This can be useful when paired with the -Verbose
switch if you are examining what
is happening behind the scenes.
By default, state changing commands like Set-*
, Rename-*
, etc... will not produce any output
unless you specify the -PassThru
switch. You can change that default behavior by calling
Set-GitHubConfiguration -DefaultPassThru:$true
One of the major benefits of PowerShell is its pipeline -- allowing you to "pipe" a saved value or the output of a previous command directly into the next command. There is absolutely no requirement to make use of it in order to use the module, but you will find that the module becomes increasingly easier to use and more powerful if you do.
Some of the examples that you find below will show how you might be able to use it to your advantage.
Most commands require you to pass in either a Uri
for the repository or its elements (the
OwnerName
and RepositoryName
). If you keep around the repo that you're interacting with in
a local var (like $repo
), then you can pipe that into any command to avoid having to specify that
information. Further, piping in a more specific object (like an Issue
) allows you to avoid even
specifying the relevant Issue number.
Without the pipeline, an interaction log might look like this:
# Find all of the issues that have the label "repro steps needed" and add a new comment to those
# issues asking for an update.
$issues = @(Get-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label 'repro steps needed')
foreach ($issue in $issues)
{
$params = @{
'OwnerName' = 'microsoft'
'RepositoryName' = 'PowerShellForGitHub'
'Issue' = $issue.number
'Body' = 'Any update on those repro steps?'
}
New-GitHubIssueComment @params
}
With the pipeline, a similar interaction log might look like this:
# Find all of the issues that have the label "repro steps needed" and add a new comment to those
# issues asking for an update.
Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub |
Get-GitHubIssue -Label 'repro steps needed' |
New-GitHubIssueComment -Body 'Any update on those repro steps?'
We encourage you to explore how embracing the pipeline may simplify your code and interaction with GitHub using this module!
# 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
# 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
$collaborators = Get-GitHubRepositoryCollaborators`
-Uri @('https://github.com/PowerShell/DscResources')
# 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
$organizationMembers = Get-GitHubOrganizationMember -OrganizationName 'OrganizationName'
$teamMembers = Get-GitHubTeamMember -OrganizationName 'OrganizationName' -TeamName 'TeamName'
$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration
$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Issue 1
$labels = Get-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Milestone 1
New-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Name TestLabel -Color BBBBBB
Remove-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Name TestLabel
$labelNames = @('bug', 'discussion')
Add-GitHubIssueLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Issue 1 -LabelName $labelNames
Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -Issue 1
Set-GitHubLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00
This replaces the entire set of labels in a repository to only contain the labels in the provided array. Any labels already in the repository that are not in this array will be removed upon execution.
$labels = @( @{ 'name' = 'Label1'; 'color' = 'BBBB00'; 'description' = 'My label description' }, @{ 'name' = 'Label2'; 'color' = 'FF00000' })
Initialize-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels
Get-GitHubUser -Current
Set-GitHubProfile -Location 'Seattle, WA' -Hireable:$false
Get-GitHubUser -UserName octocat
Get-GitHubUser
Warning: This will take a while. It's getting every GitHub user.
New-GitHubRepositoryBranch -OwnerName microsoft -RepositoryName PowerShellForGitHub -Name develop
Remove-GitHubRepositoryBranch -OwnerName microsoft -RepositoryName PowerShellForGitHub -Name develop
Get-GitHubTeam -OrganizationName microsoft
Get-GitHubTeam -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubTeam -OrganizationName microsoft -TeamName MyTeam
Get-GitHubTeam -OrganizationName microsoft -TeamId 378661
New-GitHubTeam -OrganizationName microsoft -TeamName MyTeam -Description 'Team Description'
New-GitHubTeam -OrganizationName microsoft -TeamName MyChildTeam -Description 'Team Description' -ParentTeamName MyTeam
Update-GitHubTeam -OrganizationName microsoft -TeamName MyChildTeam -Description 'Team Description' -ParentTeamName MyTeam
Remove-GitHubTeam -OrganizationName microsoft -TeamName MyTeam
New-GitHubRepository -RepositoryName TestRepo
New-GitHubRepository -RepositoryName TestRepo -OrganizationName MyOrg
$myTeam = Get-GitHubTeam -OrganizationName MyOrg | Where-Object -Property name -eq MyTeam
New-GitHubRepository -RepositoryName TestRepo -OrganizationName MyOrg -TeamId $myTeam.id
New-GitHubRepositoryFromTemplate -OwnerName MyOrg -RepositoryName TemplateRepoName -TargetRepositoryName MyNewRepo -TargetOwnerName MyUserName
Test-GitHubRepositoryVulnerabilityAlert -OwnerName microsoft -RepositoryName PowerShellForGitHub
Enable-GitHubRepositoryVulnerabilityAlert -OwnerName microsoft -RepositoryName PowerShellForGitHub
Disable-GitHubRepositoryVulnerabilityAlert -OwnerName microsoft -RepositoryName PowerShellForGitHub
Enable-GitHubRepositorySecurityFix -OwnerName microsoft -RepositoryName PowerShellForGitHub
Disable-GitHubRepositorySecurityFix -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubRepositoryActionsPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub
Set-GitHubRepositoryActionsPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -AllowedActions All
Get-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
Set-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins -Permission Admin
Remove-GitHubRepositoryTeamPermission -OwnerName microsoft -RepositoryName PowerShellForGitHub -TeamName Admins
Get-GitHubRepositoryBranchProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchName master
New-GitHubRepositoryBranchProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchName master -RequiredApprovingReviewCount 1
Remove-GitHubRepositoryBranchProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchName master
Get-GitHubRepositoryBranchPatternProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchPatternName 'Release/**/*'
New-GitHubRepositoryBranchPatternProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchPatternName 'Release/**/*' -RequiredApprovingReviewCount 1 -DismissStaleReviews -RequireStrictStatusChecks -StatusCheck 'CICheck'
Remove-GitHubRepositoryBranchPatternProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchPatternName 'Release/**/*'
Get-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub
New-GitHubRepositoryFork -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path README.md -MediaType Html
Get-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path LICENSE
Get-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path Tests
Set-GitHubContent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Path README.md -CommitMessage 'Adding README.md' -Content '# README' -BranchName master
Get-GitHubReferrerTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubPathTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubViewTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub -Per Week
Get-GitHubCloneTraffic -OwnerName microsoft -RepositoryName PowerShellForGitHub -Per Day
Get-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub
$HasPermission = Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignee "LoginID123"
Add-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1
Remove-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1
Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1
Get-GitHubRepositoryComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Sort Created -Direction Ascending -Since '2011-04-14T16:00:49Z'
Get-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1
New-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Body "Testing this API"
Set-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API"
Remove-GitHubIssueComment -OwnerName microsoft -RepositoryName PowerShellForGitHub -CommentID 1
Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Sort DueOn -Direction Ascending -DueOn '2011-04-14T16:00:49Z'
Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1
New-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API"
Set-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1
Set-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API edited"
Remove-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Milestone 1
Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1
Get-GitHubEvent -OwnerName microsoft -RepositoryName PowerShellForGitHub -EventID 1
Get-GitHubProject -OwnerName microsoft -RepositoryName PowerShellForGitHub
Get-GitHubProject -UserName octocat
New-GitHubProject -OwnerName octocat -RepositoryName PowerShellForGitHub -ProjectName TestProject
New-GitHubProjectColumn -Project 1 -ColumnName 'To Do'
New-GitHubProjectCard -Column 2 -Note 'Fix this bug'
New-GitHubProjectCard -Column 2 -ContentId 3 -ContentType Issue
Move-GitHubProjectCard -Card 4 -After 5
Move-GitHubProjectCard -Card 4 -ColumnId 6 -Bottom
Get-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell
or with pipelining...
Get-GitHubRepository -OwnerName PowerShell -RepositoryName PowerShell |
Get-GitHubRelease
Get-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell |
Select-Object -First 1 |
Get-GitHubRelease
New-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell -Tag 11.0
or with pipelining...
Get-GitHubRepository -OwnerName PowerShell -RepositoryName PowerShell |
New-GitHubRelease -Tag 11.0
Set-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell -Release 123456 -Body 'Updated body'
or with pipelining...
$repo | Set-GitHubRelease -Release 123456 -Body 'Updated body'
# or
$release | Set-GitHubRelease -Body 'Updated body'
Remove-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell -Release 123456 -Force
or with pipelining...
$repo | Remove-GitHubRelease -Release 123456 -Force
# or
$release | Remove-GitHubRelease -Force
Get-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Release 123456
or with pipelining...
$repo | Get-GitHubReleaseAsset -Release 123456
# or
$release | Get-GitHubReleaseAsset
Get-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Asset 123456 -Path 'c:\downloads\asset'
or with pipelining...
# Downloads the first asset of the latest release from PowerShell\PowerShell to the file located
# at c:\downloads\asset
Get-GitHubRelease -OwnerName PowerShell -RepositoryName PowerShell -Latest |
Get-GitHubReleaseAsset |
Select-Object -First 1 |
Get-GitHubReleaseAsset -Path 'c:\downloads\asset'
New-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Release 123456 -Path 'c:\foo.zip'
or with pipelining...
$release | New-GitHubReleaseAsset -Path 'c:\foo.zip'
# or
@('c:\foo.zip', 'c:\bar.txt') |
New-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Release 123456
Set-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Asset 123456 -Name 'newFileName.zip'
or with pipelining...
$asset | Set-GitHubReleaseAsset -Name 'newFileName.zip'
Remove-GitHubReleaseAsset -OwnerName PowerShell -RepositoryName PowerShell -Asset 123456 -Force
or with pipelining...
$asset | Remove-GitHubReleaseAsset -Force
# There are many options here:
# 1. Getting all gists for the current authenticated user:
Get-GitHubGist
# 1b. Getting all gists for the current authenticated user that were updated in the past 6 days.
Get-GitHubGist -Since ((Get-Date).AddDays(-6))
# 2. Get all starred gists for the current authenticated user
Get-GitHubGist -Starred
# 3. Get all public gists for a specific user
Get-GitHubGist -UserName 'octocat'
# 4. Get all public gists (well, the first 3000):
Get-GitHubGist -Public
# 5. Get a specific gist
Get-GitHubGist -Gist '6cad326836d38bd3a7ae'
# 5a. List all commits for a specific gist
Get-GitHubGist -Gist '6cad326836d38bd3a7ae' -Commits
# 5b. Get a gist at a specific commit (Sha)
Get-GitHubGist -Gist '6cad326836d38bd3a7ae' -Sha 'de5b9b59d1f28206e8d646c7c8025e9809d0ed73'
# 5c. Get all of the forks for a gist
Get-GitHubGist -Gist '6cad326836d38bd3a7ae' -Forks
Get-GitHubGist -Gist '6cad326836d38bd3a7ae' -Path 'c:\users\octocat\downloads\gist\'
Fork-GitHubGist -Gist '6cad326836d38bd3a7ae'
# You can create a gist by specifying a single file's content in-line...
New-GitHubGist -FileName 'foo.txt' -Content 'foo content'
# or by providing one or more files that should be part of the gist
New-GitHubGist -File @('c:\files\foo.txt', 'c:\files\bar.txt')
@('c:\files\foo.txt', 'c:\files\bar.txt') | New-GitHubGist
Remove-GitHubGist -Gist '6cad326836d38bd3a7ae'
$gist = New-GitHubGist -FileName 'foo.txt' -Content 'content'
# The main method to use is Set-GitHubGist, however it is quite complicated.
$params = @{
Description = 'new description' # modifies the description of the gist
Update = @{
'foo.txt' = @{
fileName = 'alpha.txt' # Will rename foo.txt -> alpha.txt
content = 'updated content' # and will also update its content
}
'bar.txt' = @{
filePath = 'c:\files\bar.txt' # Will upload the content of bar.txt to the gist.
}
}
Delete = @('bar.txt')
Force = $true # avoid confirmation prompting due to the deletion
}
Set-GitHubGist -Gist $gist.id @params
# Therefore, you can use simpler helper methods to accomplish atomic tasks
Set-GistHubGistFile -Gist $gist.id -FileName 'foo.txt' -Content 'updated content'
# This will update the text in the existing file 'foo.txt' and add the file 'bar.txt'
$gist | Set-GitHubGistFile -File ('c:\files\foo.txt', 'c:\files\bar.txt')
Rename-GistHubGistFile -Gist $gist.id -FileName 'foo.txt' -NewName 'bar.txt'
$gist | Remove-GitHubGistFile -FileName 'bar.txt' -Force
$gistId = '6cad326836d38bd3a7ae'
# All of these options will star the same gist
Star-GitHubGist -Gist $gistId
Add-GitHubGistStar -Gist $gistId
Set-GitHubGistStar -Gist $gistId -Star
Get-GitHubGist -Gist $gistId | Star-GitHubGist
# All of these options will unstar the same gist
Unstar-GitHubGist -Gist $gistId
Remove-GitHubGistStar -Gist $gistId
Set-GitHubGistStar -Gist $gistId
Set-GitHubGistStar -Gist $gistId -Star:$false
Get-GitHubGist -Gist $gistId | Unstar-GitHubGist
# All of these options will tell you if you have starred a gist
Test-GitHubGistStar -Gist $gistId
Get-GitHubGist -Gist $gistId | Test-GitHubGistStar
$gistId = '6cad326836d38bd3a7ae'
$commentId = 1507813
# You can get all comments for a gist with any of these options:
Get-GitHubGistComment -Gist $gistId
Get-GitHubGist -Gist $gistId | Get-GitHubGistComment
# You can retrieve an individual comment like this:
Get-GitHubGistComment -Gist $gistId -Comment $commentId
$gistId = '6cad326836d38bd3a7ae'
New-GitHubGistComment -Gist $gistId -Body 'Hello World'
# or with the pipeline
Get-GitHubGist -Gist $gistId | New-GitHubGistComment -Body 'Hello World'
$gistId = '6cad326836d38bd3a7ae'
$commentId = 1507813
Set-GitHubGistComment -Gist $gistId -Comment $commentId -Body 'Updated comment'
# or with the pipeline
Get-GitHubGist -Gist $gistId -Comment $commentId | Set-GitHubGistComment -Body 'Updated comment'
$gistId = '6cad326836d38bd3a7ae'
$commentId = 1507813
# If you don't specify -Force, it will prompt for confirmation before it will delete the comment
Remove-GitHubGistComment -Gist $gistId -Comment $commentId -Force
# or with the pipeline
Get-GitHubGist -Gist $gistId -Comment $commentId | Remove-GitHubGistComment -Force
New-GitHubDeploymentEnvironment -OwnerName microsoft -RepositoryName TestRepo -Environment Test
Get-GitHubDeploymentEnvironment -OwnerName microsoft -RepositoryName TestRepo -Environment Test
Set-GitHubDeploymentEnvironment -OwnerName microsoft -RepositoryName TestRepo -Environment Test -DeploymentBranchPolicy ProtectedBranches
Remove-GitHubDeploymentEnvironment -OwnerName microsoft -RepositoryName TestRepo -Environment Test
@LazyWinAdmin used this module to migrate his blog comments from Disqus to GitHub Issues. See blog post for full details.
# Get your repo
$repo = Get-GitHubRepository -OwnerName <yourName> -RepositoryName RepoName
# Create an issue
$issue = $repo | New-GitHubIssue -Title $IssueTitle -Body $body -Label 'blog comments'
# Create Comment
$issue | New-GitHubIssueComment -Body $CommentBody
# Close issue
$issue | Set-GitHubIssue -State Closed
# Get all codespaces for the current authenticated user
Get-GitHubCodespace
# Get all codespaces for the current authenticated user in a repository
Get-GitHubCodespace -OwnerName microsoft -RepositoryName TestRepo
# Get a codespace by name
Get-GitHubCodespace -CodespaceName 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Create a codespace in the specified repository by id
New-GitHubCodespace -RepositoryId 582779513
# Create a codespace in the specified repository by name
New-GitHubCodespace -OwnerName microsoft -RepositoryName TestRepo
# Create a codespace in the specified repository by id from a pull request
New-GitHubCodespace -RepositoryId 582779513 -PullRequest 508
# Create a codespace in the specified repository by name from a pull request
New-GitHubCodespace -OwnerName microsoft -RepositoryName TestRepo -PullRequest 42
# Create a codespace in repository from pipeline
$repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName TestRepo
$repo | New-GitHubCodespace
# Create a codespace in repository from pipeline with options
$newGitHubCodespaceParms = @{
DisplayName = 'PowerShellForGitHub usage'
Geo = 'UsWest'
Machine = 'basicLinux32gb'
NoMultipleRepoPermissions = $true
IdleRetentionPeriodMinutes = 10
TimeoutMinutes = 5
}
$codespace = $repo | New-GitHubCodespace @newGitHubCodespaceParms
$codespaceName = 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Remove a codespace for the current authenticated user
Remove-GitHubCodespace -CodespaceName $codespaceName
$codespaceName = 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Starting a codespace (asynchronous)
Start-GithubCodespace -CodespaceName $codespaceName
# Starting a codespace (wait for Available)
Start-GithubCodespace -CodespaceName $codespaceName -Wait
$codespaceName = 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Stopping a codespace (asynchronous)
Stop-GithubCodespace -CodespaceName $codespaceName
# Stopping a codespace (wait for Shutdown)
Stop-GithubCodespace -CodespaceName $codespaceName -Wait
# Get all codespaces for an Organization
Get-GitHubCodespace -OrganizationName microsoft
# Get all codespaces for a specific organization user
Get-GitHubCodespace -OrganizationName microsoft -UserName octocat
$codespaceName = 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Remove a codespace for an organization user
Remove-GitHubCodespace -OrganizationName microsoft -UserName octocat -CodespaceName $codespaceName
$codespaceName = 'microsoft-symmetrical-chainsaw-7q4vp6v7q3pwqq'
# Stopping a codespace (wait for Shutdown)
Stop-GithubCodespace -OrganizationName microsoft -UserName octocat -CodespaceName $codespaceName -Wait