Documentation
¶
Index ¶
- Constants
- Variables
- func BindPATFlag() *string
- func BindRepoFlag() *string
- func DownloadFile(ctx context.Context, client *github.Client, owner, repo, ref, path string) ([]byte, error)
- func FetchEachPage(f func(options github.ListOptions) (*github.Response, error)) error
- func FetchRepository(ctx context.Context, client *github.Client, owner, repo string) (*github.Repository, error)
- func FullyCreateFork(ctx context.Context, client *github.Client, upstreamOwner, repo string) (*github.Repository, error)
- func NewClient(ctx context.Context, pat string) (*github.Client, error)
- func PATScopes(ctx context.Context, client *github.Client) ([]string, error)
- func ParseRepoFlag(repo *string) (owner, name string, err error)
- func Retry(f func() error) error
- func UploadFile(ctx context.Context, client *github.Client, ...) error
Constants ¶
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 ¶
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 ¶
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 PATScopes ¶ added in v0.0.6
PATScopes gets the scopes of the client's PAT by reading a simple API call's response headers.
func ParseRepoFlag ¶
ParseRepoFlag splits a given repo (owner/name) into owner and name, or returns an error.
Types ¶
This section is empty.