Skip to content

PowerShellModules/PowerShellForGitHub

 
 

Repository files navigation

PowerShellForGitHub

Build status

PowerShell wrapper for GitHub API.

This repository currently contains two modules:

  • GitHubAnalytics.psm1 - for querying issues, pull requests, collaborators, contributors, and organizations
  • GitHubLabels.psm1 - for operations on GitHub labels

Please scroll down to the "Examples" section for details on what operations are supported.

Installation

You can get latest release of the PowerShellForGitHub on the PowerShell Gallery

Install-Module -Name PowerShellForGitHub

Usage

  1. Rename ApiTokensTemplate.psm1 to ApiTokens.psm1 and update value of $global:gitHubApiToken with GitHub token for your account
  • You can obtain it from https://github.com/settings/tokens.
  • If you don't provide GitHub token, you can still use this module, but you will be limited to 60 queries per hour.
  • You will need to edit this file from an elevated context.
  1. Import module you want to use and call it's function, e.g.
Import-Module .\GitHubAnalytics.psm1
$issues = Get-GitHubIssuesForRepository -repositoryUrl @('https://github.com/PowerShell/DscResources')

Running tests

  1. Install Pester
Install-Module -Name Pester 
  1. Start test pass

Go to the Tests folder and run:

Invoke-Pester

Make sure ApiTokens.psm1 exists and contains $global:gitHubApiToken with your GitHub key. Please keep in mind some tests may fail on your machine, as they test private items (e.g. secret teams) which your key won't have access to.

Contributing

Contributions are welcome, please open issue on what functionality you would like to see added/contribute or simply send a pull request.

Examples

GitHubAnalytics

Querying issues

$issues = Get-GitHubIssuesForRepository `
-repositoryUrl @('https://github.com/PowerShell/xPSDesiredStateConfiguration')
$issues = Get-GitHubWeeklyIssuesForRepository `
-repositoryUrl @('https://github.com/powershell/xpsdesiredstateconfiguration',`
'https://github.com/powershell/xactivedirectory') -datatype closed
$issues = Get-GitHubTopIssuesRepository `
-repositoryUrl @('https://github.com/powershell/xsharepoint',`
'https://github.com/powershell/xCertificate', 'https://github.com/powershell/xwebadministration') -state open

Querying pull requests

$pullRequests = Get-GitHubPullRequestsForRepository `
-repositoryUrl @('https://github.com/PowerShell/xPSDesiredStateConfiguration')
$pullRequests = Get-GitHubWeeklyPullRequestsForRepository `
-repositoryUrl @('https://github.com/powershell/xpsdesiredstateconfiguration',`
'https://github.com/powershell/xwebadministration') -datatype merged
$pullRequests = Get-GitHubTopPullRequestsRepository `
-repositoryUrl @('https://github.com/powershell/xsharepoint', 'https://github.com/powershell/xwebadministration')`
-state closed -mergedOnOrAfter 2015-04-20

Querying collaborators

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

Querying contributors

$contributors = Get-GitHubRepositoryContributors`
-repositoryUrl @('https://github.com/PowerShell/DscResources', 'https://github.com/PowerShell/xWebAdministration')
$contributors = Get-GitHubRepositoryContributors`
-repositoryUrl @('https://github.com/PowerShell/DscResources','https://github.com/PowerShell/xWebAdministration')

$uniqueContributors = Get-GitHubRepositoryUniqueContributors -contributors $contributors

Quering teams / organization membership

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

GitHubLabels

Getting labels for given repository

$labels = Get-GitHubLabel -repositoryName DesiredStateConfiguration -ownerName Powershell

Adding new label to the repository

New-GitHubLabel -repositoryName DesiredStateConfiguration -ownerName PowerShell -labelName TestLabel -labelColor BBBBBB

Removing specific label from the repository

Remove-GitHubLabel -repositoryName desiredstateconfiguration -ownerName powershell -labelName TestLabel

Updating specific label with new name and color

Update-GitHubLabel -repositoryName DesiredStateConfiguration -ownerName Powershell -labelName TestLabel -newLabelName NewTestLabel -labelColor BBBB00

About

Microsoft PowerShell wrapper for GitHub API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PowerShell 100.0%