• Stars
    star
    72
  • Rank 423,621 (Top 9 %)
  • Language
    PowerShell
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Powershell cmdlets that expose the GitHub API

PowerShell Logo GitHub Mark

Posh-GitHub

Unofficial Powershell cmdlets that expose the GitHub API

Early Code

This is a super super early take on some rudimentary GitHub functionality. I will continue to improve this over time as need grows / time allows. There may be bugs or things I haven't thought of -- please report if that's the case!

Compatibility

  • This is written for Powershell v3 and makes use of the simplified Invoke-RestMethod instead of the WebClient class.

    • Powershell v3 can be installed with Chocolatey via cinst powershell
  • This is written against GitHub API v3

Installation

Chocolatey

Once Chocolatey has been installed, simply use the cinst command.

cinst posh-github

Chocolatey installation will import the module into your PowerShell profile.

Updating

Chocolatey

After installing with Chocolatey, simply use the cup command.

cup posh-github

Supported Commands

Environment Variables

Cmdlets are set to use the following environment variables as defaults

  • GITHUB_OAUTH_TOKEN - Required for all cmdlets - use New-GitHubOAuthToken to establish a token and automatically set this variable for the current user
  • GITHUB_USERNAME - Can be optionally set to specify a global default user - use the Set-GitHubUserName helper
  • GITHUB_ORGANIZATION - Can be optionally set to specify a global default organization - use the Set-GitHubOrganization helper

Last Command Output

A Powershell object created from the incoming JSON is always stored in the variable $GITHUB_API_OUTPUT after each call to the GitHub API

New-GitHubOAuthToken

Used to create a new OAuth token for use with the GitHub using your username/password in basic auth over HTTPS. The result is stashed in the GITHUB_OAUTH_TOKEN environment variable.

New-GitHubOAuthToken -UserName Bob -Password bobpassword
New-GitHubOAuthToken -UserName Bob -Password bobpassword -NoEnvironmentVariable

Get-GitHubOAuthTokens

Used to list all the authorizations you have provided to applications / tooling

Get-GitHubOAuthTokens Bob bobspass

Set-GitHubUserName

Adds the username to the current Powershell session and sets a global User environment variable

Set-GitHubUserName Iristyle

Set-GitHubOrganization

Adds the organization to the current Powershell session and sets a global User environment variable

Set-GitHubOrganization EastPoint

Get-GitHubRepositories

List all your repositories - gives a fork indicator, a date for when the last update (push) occurred, how many open issues and size

Get-GitHubRepositories
Get-GitHubRepositories -Type owner -Sort pushed

New-GitHubRepository

Creates a new GitHub repository and clones it locally by default.

By default creates a public repository for the user configured by GITHUB_USERNAME, and clones it afterwards.

New-GitHubRepository MyNewRepository

If you are a member of an organization and have set a GITHUB_ORG environment variable, this will create the repository under that organization. Note that organization repositories require a TeamId

New-GitHubRepository MyNewOrgRepo -ForOrganization -TeamId 1234

If you are a member of multiple organizations you may override the default configured organization

New-GitHubRepository MyNewOrgRepo -Organization DifferentOrg -TeamId 1234

A fancier set of switches -- pretty self-explanatory. The complete Gitignore list here is at your disposal.

New-GitHubRepository RepoName -Description 'A New Repo' `
  -Homepage 'https://www.foo.com' -Private -NoIssues -NoWiki -NoDownloads `
  -AutoInit -GitIgnoreTemplate 'CSharp' -NoClone

New-GitHubFork

Forks a repository, clones it locally, then properly adds a remote named upstream to point back to the parent repository. Aborts if there is a directory in the current working directory that shares the name of the repository.

Uses the environment variable GITHUB_OAUTH_TOKEN to properly fork to your account. After forking, clones the original source, resets origin to the new url for your account https://github.com/YOURUSERNAME/Posh-GitHub.git, and sets the upstream remote to https://github.com/Iristyle/Posh-GitHub.git

New-GitHubFork Iristyle 'Posh-GitHub'

Performs the same operation as above, instead forking to the default organization specified by the GITHUB_ORG environment variable.

New-GitHubFork Iristyle 'Posh-GitHub' -ForOrganization

Performs the same operation as above, instead forking to a user specified organization specified by the -Organization switch.

New-GitHubFork Iristyle 'Posh-GitHub' -Organization MySecondOrganization

Forks the repository, without calling git clone after the fork.

New-GitHubFork -Owner Iristyle -Repository 'Posh-GitHub' -NoClone

Get-GitHubIssues

List issues against the repository for the current working directory, or can list issues against a specific repo and owner.

Simply list issues for the current working directory repository. Checks first for an upstream remote and falls back to origin

If the current directory is not a repository, then lists all the issues assigned to you, assuming the GITHUB_OAUTH_TOKEN has been set properly.

Get-GitHubIssues

To get your issues regardless of whether or not the current directory is a Git repository.

Get-GitHubIssues -ForUser

Same as above, but finds up to the last 30 closed issues.

Get-GitHubIssues -State closed

All parameters possible when searching for user issues

Get-GitHubIssues -ForUser -State open -Filter created -Sort comments `
  -Direction asc -Labels 'ui','sql' -Since 8/31/2012

Must be ordered by Owner, Repo if not using switches on params

Get-GitHubIssues EastPoint Burden

Switch on params form

Get-GitHubIssues -Owner EastPoint -Repository Burden

Closed issues

Get-GitHubIssues -Owner EastPoint -Repository Burden -State closed

Supplying all parameters for a repository based issue search

Get-GitHubIssues -Owner EastPoint -Repository Burden -State closed `
  -Milestone '*' -Assignee 'none' -Creator 'Iristyle' -Mentioned 'Iristyle'
  -Labels 'ui','sql' -Sort updated -Direction desc -Since 8/31/2012

New-GitHubPullRequest

Initiates a new pull request to the upstream repo.

If you follow the convention of setting a remote named upstream, and you create new branches for new work, then this cmdlet should work mostly automatically to find the appropriate owner and repo to send the pull request to, and it will base it on the origin username and current branch name.

Supports a title and body.

New-GitHubPullRequest -Title 'Fixed some stuff' -Body 'More detail'

Support an issue id.

New-GitHubPullRequest -Issue 5

Supports a branch other than master to send the pull to.

New-GitHubPullRequest -Issue 10 -Base 'devel'

If you don't have a remote set, then override the default sniffing behavior.

New-GitHubPullRequest -Issue 10 -Owner EastPoint -Repository Burden

If you're not on the current branch you want to send the pull for, override it.

New-GitHubPullRequest -Title 'fixes' -Head 'myusername:somebranch'

Note that GitHub generally requires that head be prefixed with username:

Get-GitHubPullRequests

List pull requests against the repository for the current working directory, or can list pull requests against all forks from a user.

Inside of a Git repository, this will look first for a remote named upstream before falling back to origin.

Inside of a non-Git directory, this will list pulls for all of your forks, assuming you have set the GITHUB_USERNAME environment variable

Get-GitHubPullRequests

When inside of a Git directory, the repo lookup behavior may be overridden with the -ForUser switch, assuming GITHUB_USERNAME has been set

Get-GitHubPullRequests -ForUser

Will list all open pull requests the 'Posh-GitHub' repository

Get-GitHubPullRequests -Owner EastPoint -Repository 'Posh-GitHub'

Lists all open public pull requests against the given users forks, overriding the GITHUB_USERNAME default user.

Get-GitHubPullRequests -User Iristyle

Will list all closed pull requests against the 'Posh-GitHub' repository

Get-GitHubPullRequests -Owner EastPoint -Repository 'Posh-Github' -State closed

Get-GitHubTeams

The default parameterless version will use the GITHUB_ORG environment variable to get the list of teams, their ids and members.

Get-GitHubTeams

This will find all the teams for the EastPoint organization. You must have access to the given organization to list its teams.

Get-GitHubTeams EastPoint

Get-GitHubEvents

Will list, in chronological order, the last 30 events that you have generated

Get-GitHubEvents

Will list the public events for another user

Get-GitHubEvents -User Iristyle

Backup-GitHubRepositories

This will clone every repository for the specified user or organization, and will additionally clone each fork, as determined by open pull requests. Does not backup issues or wiki (yet).

The default parameterless version will use the GITHUB_USERNAME environment variable to get the list of repos where the user is an owner or a member, and will backup each one locally to disk

Backup-GitHubRepositories

This will find all the public repos for the github organization, and will clone each one locally

Backup-GitHubRepositories -Organization github

Additional Git helper commands

These commands do not use GitHub service, but are common enough for inclusion.

Clear-GitMergedBranches

Will remove any local branch cruft from branches that have been merged into the master branch.

Clear-GitMergedBranches

When pull requests have been merged, it's typical to delete the branch after accepting. Remotes may no longer have branch names for things that have been merged. This command removes remote branch names that no longer exist.

Clear-GitMergedBranches -Remote

Roadmap

None really.. just waiting to see what I might need.

More Repositories

1

PerfTap

A Windows PerfMon monitoring service that pushes data to a graphite server
C#
123
star
2

Sublime-AngularJS-Coffee-Completions

A Sublime Text Package for AngularJS when using CoffeeScript
54
star
3

Burden

A simple / persistent .NET job queue system based on Rx
C#
43
star
4

ChocolateyPackages

Chocolatey Install Packages
Python
23
star
5

Midori

A set of Powershell modules designed to extend Psake with common functionality, but also useful for any build or continuous delivery system powered by PowerShell
PowerShell
18
star
6

Posh-VsVars

PowerShell helper for loading Visual Studio command line tools
PowerShell
13
star
7

EqualityComparer

.NET library for doing comparisons of objects based on their property and member values, including support for custom comparers
C#
13
star
8

NLog.AirBrake

A custom NLog target that will push errors to AirBrake or Errbit
C#
9
star
9

NanoTube

A .NET Udp based StatsD or StatSite client for submitting metrics to Graphite
C#
9
star
10

Redis-win32-FxTestIntegration

Provides a simple .NET library and the Redis binaries to reduce development friction in Windows tests
C#
6
star
11

CroMagVersion

An MSBuild integration for shared versioning across all projects in a solution, where user supplies Major / Minor and Build / Revision are calculated by date/time and other DVCS properties make their way into the assembly metadata.
PowerShell
6
star
12

BookKeeper

Track immutable objects through a history of changesets. Provides a serialization format that is distributed data friendly
C#
4
star
13

puppetconf2014

PuppetConf 2014 Workshop Code
Ruby
3
star
14

Tahiti

A WinDev bootstrap script based on PowerShell and Chocolatey
PowerShell
2
star
15

puppetconf2015

PuppetConf 2015 DSC Demo Samples
Puppet
2
star
16

bower-angularAuth

A repository for hosting the angular-auth module capable of handling 401 redirects
JavaScript
2
star
17

Authentic

A pluggable .NET based authentication library supporting basic and digest auth
C#
2
star
18

Elevate

.NET Source code for John Robbins Elevate utility
C#
2
star
19

StyleGuide

Styleguides are all the rage right now, so let's cobble something together too!
2
star
20

DevTools

Developer tool packages for project on-boarding, including Vagrant VMs
PowerShell
1
star
21

Gendarme.Rules

Custom Gendarme Rules for static code analysis
C#
1
star
22

puppetconf2016

PuppetConf 2016 Vagrant Setup
PowerShell
1
star
23

puppetconf2016-controlrepo

PuppetConf 2016 Control Repo
Puppet
1
star