githubutil

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TreeModeFile       = "100644"
	TreeModeExecutable = "100755"
	TreeModeDir        = "040000"
	TreeModeSubmodule  = "160000"
	TreeModeGitlink    = "120000"
)

Git tree entry mode constants defined by https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#create-a-tree--parameters

Variables

View Source
var (
	// ErrFileNotExists indicates that the requested file does not exist in the specified GitHub repository and branch.
	ErrFileNotExists = errors.New("file does not exist in the given repository and branch")
	// ErrRepositoryNotExists indicates that the requested repository does not exist.
	ErrRepositoryNotExists = errors.New("repository does not exist")
)

Types of error that may be returned from the GitHub API that the caller may want to handle.

Functions

func BindPATFlag

func BindPATFlag() *string

BindPATFlag returns a flag to specify the personal access token.

func BindRepoFlag

func BindRepoFlag() *string

BindRepoFlag returns a flag to specify a GitHub repo to target. Parse it with ParseRepoFlag.

func DownloadFile added in v0.0.3

func DownloadFile(ctx context.Context, client *github.Client, owner, repo, ref, path string) ([]byte, error)

DownloadFile downloads a file from a given repository.

func FetchEachPage

func FetchEachPage(f func(options github.ListOptions) (*github.Response, error)) error

FetchEachPage helps fetch all data from a GitHub API call that may or may not span multiple pages. FetchEachPage initially calls f with no paging parameters, then inspects the GitHub response to see if there are more pages to fetch. If so, it constructs paging parameters that will fetch the next page and calls f again. This repeats until there aren't any more pages.

Note that FetchEachPage doesn't process any of the result data, and doesn't actually call the GitHub API. f must do this itself. This allows FetchEachPage to work with any GitHub API.

func FetchRepository added in v0.0.6

func FetchRepository(ctx context.Context, client *github.Client, owner, repo string) (*github.Repository, error)

FetchRepository fetches a repository from GitHub or returns an error. If the GitHub API error matches one of the errors defined in this package, it is wrapped. Retries if necessary.

func FullyCreateFork added in v0.0.6

func FullyCreateFork(ctx context.Context, client *github.Client, upstreamOwner, repo string) (*github.Repository, error)

FullyCreateFork creates a fork of the given repository under the PAT owner's account, waits for the fork to be fully created, and returns its full information.

func NewClient

func NewClient(ctx context.Context, pat string) (*github.Client, error)

NewClient creates a GitHub client using the given personal access token.

func PATScopes added in v0.0.6

func PATScopes(ctx context.Context, client *github.Client) ([]string, error)

PATScopes gets the scopes of the client's PAT by reading a simple API call's response headers.

func ParseRepoFlag

func ParseRepoFlag(repo *string) (owner, name string, err error)

ParseRepoFlag splits a given repo (owner/name) into owner and name, or returns an error.

func Retry

func Retry(f func() error) error

Retry runs f up to 'retryAttempts' times, printing the error if one is encountered. Handles GitHub rate limit exceeded errors by waiting, if the reset will happen reasonably soon.

func UploadFile added in v0.0.2

func UploadFile(ctx context.Context, client *github.Client, owner, repo, branch, path, message string, content []byte) error

UploadFile is a function that will upload a file to a given repository.

Types

This section is empty.

Jump to

Keyboard shortcuts

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