Giter VIP home page Giter VIP logo

github's Introduction

GitHub PowerShell

The module serves as a wrapper around GitHub's REST API, making the functionalities and data available on GitHub accessible through PowerShell functions and classes. This module is tailored for developers, administrators, and GitHub enthusiasts who are familiar with PowerShell and want to integrate or manage GitHub seamlessly.

Desired supported scenarios

  • Support operators of personal repos, organization repos, and enterprise repos. -> Similar to the GitHub CLI, but with more commands.
  • Help operators that have multiple account and is a member of multiple organizations/enterprises. -> Similar to the GitHub CLI.
  • A context aware module that knows what environment you are working in, both locally and in GitHub Actions. -> Similar to the Octokit.
  • Built to be a native companion with GitHub Actions with Workflow commands that you can use. -> Similar to the Octokit and github-scripts
  • A module that can be used in other PowerShell compatible automation environments, like FunctionApps. -> Similar to the Octokit.
  • A way to deploy, declare and manage resources in GitHub programmatically. -> Similar to Terraform and Pulumi.

Supported platforms

As the module is built with the goal to support modern operators (assumed to use a newer OS), GitHub Actions and FunctionApps, the module will only support the latest LTS version of PowerShell on Windows, macOS, and Linux.

Getting Started with GitHub PowerShell

To dive into the world of GitHub automation with PowerShell, follow the sections below.

Installing the module

Download and install the GitHub PowerShell module from the PowerShell Gallery with the following command:

Install-Module -Name GitHub -Force -AllowClobber

Logging on

Authenticate using your GitHub credentials or access tokens to begin executing commands. Tokens and other configuration details are stored encrypted on the system using the PowerShell modules SecretManagement and SecretStore Overview, for more info on the implementation, see the section on storing configuration.

Device flow

This is the recommended method for authentication due to access tokens being short lived. It opens a browser window and prompts you to log in to GitHub. Once you log in, you will be provided with a code that you need to paste into the PowerShell console. The command already puts the code in your clipboard. It uses a GitHub App to authenticate, which is more secure than using a personal access token. The GitHub App is only granted access to the repositories you add it to. Visit the GitHub Apps documentation to read more about GitHub Apps.

Connect-GitHubAccount
! We added the code to your clipboard: [AB55-FA2E]
Press Enter to open github.com in your browser...:  #-> Press enter and paste the code in the browser window
✓ Logged in as octocat!

After this you will need to install the GitHub App on the repos you want to manage. You can do this by visiting the PowerShell for GitHub app page.

Info: We will be looking to include this as a check in the module in the future. So it becomes a part of the regular sign in process.

Consecutive runs of the Connect-GitHubAccount will not require you to paste the code again unless you revoke the token or you change the type of authentication you want to use. Instead, it checks the remaining duration of the access token and uses the refresh token to get a new access token if its less than 4 hours remaining.

Connect-GitHubAccount
✓ Access token is still valid for 05:30:41 ...
✓ Logged in as octocat!

This is also happening automatically when you run a command that requires authentication. The validity of the token is checked before the command is executed. If it is no longer valid, the token is refreshed and the command is executed.

Device Flow with OAuth app

This uses the same flow as above, but instead of using the GitHub App, it uses an OAuth app with long lived tokens. During the signing you can also authorize the app to access your private repositories. Visit the OAuth apps documentation to read more about OAuth apps on GitHub.

Connect-GitHubAccount -Mode OAuth

! We added the code to your clipboard: [AB55-FA2E]
Press Enter to open github.com in your browser...:
✓ Logged in as octocat!

Personal access token

This is the least secure method of authentication, but it is also the simplest. Running the Connect-GitHubAccount command with the -AccessToken parameter will send you to the GitHub site where you can create a new personal access token. Give it the access you need and paste it into the terminal.

Connect-GitHubAccount -AccessToken
! Enter your personal access token: ****************************************
✓ Logged in as octocat!

System Access Token

The module also detects the presence of a system access token and uses that if it is present. This is useful if you are running the module in a CI/CD pipeline or in a scheduled task. The function looks for the GH_TOKEN and GITHUB_TOKEN environment variables (in order).

Connect-GitHubAccount
✓ Logged in as system!

Command Exploration

Familiarize yourself with the available cmdlets using the module's comprehensive documentation or inline help.

Get-Command -Module GitHub

References

Official GitHub Resources

General Web References

Inspiration Behind the Project

Authentication and Login

Module Configuration and Environment

github's People

Contributors

mariusstorhaug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

theposhwolf

github's Issues

[Enhancement] Invoke-GitHubAPI - Automatically set paging size

Currently the paging size is set per command that supports it, but for simplicity this could be set in the Invoke-GHAPI function and overridden when wanted. i.e. the default value gets removed from the calling function, but remains a default in the Invoke-GHAPI function and overrideable from the calling function by providing a value to the pagesize param for the function.

[Dev] Type/Class builder

Derived from REST-API-Description.

Get the component section and automatically build class(ps1 in classes folder) or type (ps1xml) files. Use the classes as input/return objects in functions.

[Feature] Config - Rearchitect how vars are stored

To avoid having too many config places (files classes and multiple vaults), we want to consolidate and bring all config to a SecretVault using SecretManagement.

This will allow the module to configure the configuration on the store separate from other config that users might have on SecretStore and other providers.

The vault should be able to hold different profiles of users along with having one for the

[Bug] Output Streaming - Fix all functions to support output streaming

Change the current implementation of wrapping the Invoke-GitHubApi in paranthesis and accessing the Response value. Instead, pipe for foreach and Write-Output the $_.Response. Optionally add the other fields as a write-verbose

    Invoke-GitHubAPI @inputObject | ForEach-Object {
        Write-Output $_.Response
    }

Create a REST method map/translation to verbs used in function names

Verb Method Description
Get Get
New/Add Post
Remove Delete
Update Patch

Special cases:
Method Put - Depends on endpoint I.e enable/disable, Start/Stop

Verb Set - Reserved for anything that is of a declarative nature. For endpoints that are not declarative already, create a wrapper function that provides the declarative functionality by combining methods Get + patch/put. The declarative functions should also provide a diff if running with -WhatIf.

Use impact on functions to determine if confirmation should be requested. This could be on activities such as remove/delete org/repo. For these we add -Force switch.

Places where there are only get and put methods available, create wrapper functions that provide add and remove functionality.

[FX] Create Issue when CI sees a known #TAG in code

Make sure that the code does not create multiple issues for a given tag.

Tags could be:

  • # BUG - #BUG -> Tag issue with bug
  • # HACK - #HACK -> Tag issue with Dept
  • # FIXME - #FIXME -> Tag issue with Dept
  • # TODO - #TODO -> Tag issue with Feature?
  • # DEBUG - #DEBUG -> Tag issue with Dept?

[Feature] Auth - Automatically detect if token is still valid for Device Flow

Add detection when running commands to see when the access token expires.

  • If running Connect-GitHubAccount with a valid access token, do not prompt again, just refresh. This chould also make the refresh parameter redundant.
  • When running commands and the token is expired, automatically refresh, then run the command.

[Dev] Function builder

Using the available OpenAPI spec from GitHub, create a function that scaffolds or fully creates a function that covers a given path of the spec.

The function builder should be able to take fields from the OpenAPI description to make some patterns of the function.

  • Namespace suggestion
  • Name of the function
  • Comment based documentation with:
    • Synopsis
    • Desciption
    • Parameter description
  • Write a warning if the token is of type GitHubApp to warn which functions are not supported

Tools to consider:

  • AutoRest - Issues though!
  • OpenAI - How though?
  • PowerShell directly with the GitHub OpenAPI description. - Time though! -> But more control...

[Enhancement] Auth - Auto refresh GitHub App access token

To not interrupt the user when running commands interactively, the access token for a user logging in with GitHub app should auto refresh.

This can be done when functions are called and the access token has reached a half- life or expired.

[FX] PSModule - Basic

Setup the basics needed for the PSModule framework to work in the repo.

  • Trigger on any branch
  • Default perform build, test and publish

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.