gogithub

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MinRepositoryCountGoal - number of repositories required to receive the maximum rate limit.
	// "Installations that have more than 20 repositories receive another 50 requests per hour for each repository. The maximum rate limit for an installation is 12,500 requests per hour."
	//
	//      (20 + 7500 // 50)
	//
	// Ref: https://docs.github.com/en/free-pro-team@latest/developers/apps/differences-between-github-apps-and-oauth-apps
	MinRepositoryCountGoal = 170

	// MinGitHubRateLimit - "GitHub Apps making server-to-server requests use the installation's
	// minimum rate limit of 5,000 requests per hour."
	//
	// Ref: https://docs.github.com/en/free-pro-team@latest/developers/apps/differences-between-github-apps-and-oauth-apps
	MinGitHubRateLimit = 5000

	// MaxGitHubRateLimit - the maximum rate limit for GitHub API requests in apps
	MaxGitHubRateLimit = 12500
)

Variables

View Source
var (

	// DefaultContext represents context.Background() which is a non-nil empty context that is
	// never canceled, has no values, and has no deadline. It is typically used by the main
	// function, initialization, and tests, and as the top-level Context for incoming requests.
	DefaultContext context.Context = context.Background()
)

Functions

func AuthClient

func AuthClient(ctx context.Context) (*http.Client, error)

AuthClient returns an authenticated *http.Client for use with API requests. It relies on getEnvToken to collect a secure Personal API Token (PAT) from an environment variable or other secure source.

If authentication fails, AuthClient falls back and returns http.DefaultClient with no authentication. Any error is also returned; calling func has a choice of action.

Most users will pass in ctx := DefaultContext which represents context.Background(). It is a non-nil empty context that is never canceled, has no values, and has no deadline. It is typically used by the main function, initialization, and tests, and as the top-level Context for incoming requests.

func GetEnvToken

func GetEnvToken() (oauth2.TokenSource, error)

GetEnvToken - get PAT from environment variable (const envGitTokenKey) global tokenSource is used to cache

func Input

func Input(prompt string) (string, error)

+ Input - displays a prompt and waits for user input

func NewGitHubClient

func NewGitHubClient(ctx context.Context) (*github.Client, error)

NewGitHubClient returns a pointer to a new authenticated GitHub client

Environment variables can be used for authentication:

username = GIT_AUTHOR_NAME

password = GITHUB_API_TOKEN_VSCODE

Most users will pass in ctx := DefaultContext which represents context.Background(). It is a non-nil empty context that is never canceled, has no values, and has no deadline. It is typically used by the main function, initialization, and tests, and as the top-level Context for incoming requests.

func PW

func PW(prompt string) (string, error)

PW - displays a prompt and waits for user secure password input

Types

This section is empty.

Directories

Path Synopsis
_example
cmd/gogithub command
The basicauth command demonstrates using the github.BasicAuthTransport, including handling two-factor authentication.
The basicauth command demonstrates using the github.BasicAuthTransport, including handling two-factor authentication.
escape-seq command
logrus command
title command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL