ghclient

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 23 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBranchNotFound = errors.New("branch not found")
View Source
var ErrRefNotFound = errors.New("reference not found")
View Source
var MaxFileDownloadSizeBytes = 500 * 1000000

MaxFileDownloadSizeBytes contains the size limit for file content downloads. Attempting to GetFileContents for a file larger than this will return an error.

Functions

This section is empty.

Types

type BranchInfo

type BranchInfo struct {
	Name string
	SHA  string
}

BranchInfo includes the information about a specific branch of a git repo

type CommitStatus

type CommitStatus struct {
	Context     string
	Status      string
	Description string
	TargetURL   string
}

CommitStatus describes a status associated with a git commit

type FakeRepoClient

type FakeRepoClient struct {
	GetBranchFunc            func(context.Context, string, string) (BranchInfo, error)
	GetBranchesFunc          func(context.Context, string) ([]BranchInfo, error)
	GetTagsFunc              func(context.Context, string) ([]BranchInfo, error)
	SetStatusFunc            func(context.Context, string, string, *CommitStatus) error
	GetPRStatusFunc          func(context.Context, string, uint) (string, error)
	GetCommitMessageFunc     func(context.Context, string, string) (string, error)
	GetFileContentsFunc      func(ctx context.Context, repo string, path string, ref string) ([]byte, error)
	GetDirectoryContentsFunc func(ctx context.Context, repo, path, ref string) (map[string]FileContents, error)
}

FakeRepoClient is fake implementaiton of RepoClient that runs user-supplied functions for each method

func (*FakeRepoClient) GetBranch

func (frc *FakeRepoClient) GetBranch(ctx context.Context, repo string, branch string) (BranchInfo, error)

func (*FakeRepoClient) GetBranches

func (frc *FakeRepoClient) GetBranches(ctx context.Context, repo string) ([]BranchInfo, error)

func (*FakeRepoClient) GetCommitMessage

func (frc *FakeRepoClient) GetCommitMessage(ctx context.Context, repo string, sha string) (string, error)

func (*FakeRepoClient) GetDirectoryContents

func (frc *FakeRepoClient) GetDirectoryContents(ctx context.Context, repo, path, ref string) (map[string]FileContents, error)

func (*FakeRepoClient) GetFileContents

func (frc *FakeRepoClient) GetFileContents(ctx context.Context, repo string, path string, ref string) ([]byte, error)

func (*FakeRepoClient) GetPRStatus

func (frc *FakeRepoClient) GetPRStatus(ctx context.Context, repo string, pr uint) (string, error)

func (*FakeRepoClient) GetTags

func (frc *FakeRepoClient) GetTags(ctx context.Context, repo string) ([]BranchInfo, error)

func (*FakeRepoClient) SetStatus

func (frc *FakeRepoClient) SetStatus(ctx context.Context, repo string, sha string, status *CommitStatus) error

type FileContents

type FileContents struct {
	Path, SymlinkTarget string
	Symlink             bool
	Contents            []byte
}

FileContents models a file from a repository

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

GitHubClient is an object that interacts with the GitHub API

func NewGitHubClient

func NewGitHubClient(token string) *GitHubClient

NewGitHubClient returns a GitHubClient instance that authenticates using the personal access token provided

func (*GitHubClient) GetBranch

func (ghc *GitHubClient) GetBranch(ctx context.Context, repo, branch string) (BranchInfo, error)

GetBranch gets the information for a specific branch

func (*GitHubClient) GetBranches

func (ghc *GitHubClient) GetBranches(ctx context.Context, repo string) ([]BranchInfo, error)

GetBranches returns the extant branches for repo (assumed to be "owner/repo-name")

func (*GitHubClient) GetCommitMessage

func (ghc *GitHubClient) GetCommitMessage(ctx context.Context, repo string, sha string) (string, error)

GetCommitMessage returns the git message associated with a particular commit

func (*GitHubClient) GetDirectoryContents

func (ghc *GitHubClient) GetDirectoryContents(ctx context.Context, repo, path, ref string) (map[string]FileContents, error)

GetDirectoryContents fetches path from repo at ref, returning a map of file path to file contents. If path is not a directory, an error is returned. The contents may include symlinks that point to arbitrary locations (ie, outside of the directory root).

func (*GitHubClient) GetFileContents

func (ghc *GitHubClient) GetFileContents(ctx context.Context, repo string, path string, ref string) ([]byte, error)

GetFileContents returns the file contents of path (which must be a regular file or a symlink to a regular file) in the specified repo at ref

func (*GitHubClient) GetPRStatus

func (ghc *GitHubClient) GetPRStatus(ctx context.Context, repo string, pr uint) (string, error)

GetPRStatus returns the status of a PR on a repo

func (*GitHubClient) GetTags

func (ghc *GitHubClient) GetTags(ctx context.Context, repo string) ([]BranchInfo, error)

GetTags returns the extant tags for repo (assumed to be "owner/repo-name")

func (*GitHubClient) SetStatus

func (ghc *GitHubClient) SetStatus(ctx context.Context, repo string, sha string, status *CommitStatus) error

SetStatus creates or updates a status on repo at commit sha

type LocalRepoInfo

type LocalRepoInfo struct {
	GitHubRepoName, HeadBranch, HeadSHA string
}

LocalRepoInfo models information about a local git repo

func RepoInfo

func RepoInfo(fs afero.Fs, path, gitHubHostname string) (LocalRepoInfo, error)

RepoInfo gets LocalRepoInfo for the git repo at path, which must be a valid repo with GitHub remotes.

type LocalWrapper

type LocalWrapper struct {
	Backend RepoClient
	// FSFunc is a function that returns a filesystem given a path
	FSFunc func(path string) billy.Filesystem
	// RepoPathMap is a map of GitHub repo names (ex: "owner/repo") to absolute local filesystem path (which must be a valid git repository)
	RepoPathMap map[string]string
	// WorkingTreeRepos are the repos to read contents directly from disk (not via commit SHA)
	WorkingTreeRepos []string
	// contains filtered or unexported fields
}

LocalWrapper is on object that satisfies RepoClient and which can optionally use local git repositories for repo names according to RepoPathMap, falling back to Backend if not found

func (*LocalWrapper) GetBranch

func (lw *LocalWrapper) GetBranch(ctx context.Context, repo, branch string) (BranchInfo, error)

func (*LocalWrapper) GetBranches

func (lw *LocalWrapper) GetBranches(ctx context.Context, repo string) ([]BranchInfo, error)

func (*LocalWrapper) GetCommitMessage

func (lw *LocalWrapper) GetCommitMessage(ctx context.Context, repo, sha string) (string, error)

func (*LocalWrapper) GetDirectoryContents

func (lw *LocalWrapper) GetDirectoryContents(ctx context.Context, repo, path, ref string) (map[string]FileContents, error)

func (*LocalWrapper) GetFileContents

func (lw *LocalWrapper) GetFileContents(ctx context.Context, repo string, path string, ref string) ([]byte, error)

func (*LocalWrapper) GetPRStatus

func (lw *LocalWrapper) GetPRStatus(context.Context, string, uint) (string, error)

func (*LocalWrapper) GetTags

func (lw *LocalWrapper) GetTags(context.Context, string) ([]BranchInfo, error)

stubs to satisfy the interface

func (*LocalWrapper) SetStatus

type RepoClient

type RepoClient interface {
	GetBranch(context.Context, string, string) (BranchInfo, error)
	GetBranches(context.Context, string) ([]BranchInfo, error)
	GetTags(context.Context, string) ([]BranchInfo, error)
	SetStatus(context.Context, string, string, *CommitStatus) error
	GetPRStatus(context.Context, string, uint) (string, error)
	GetCommitMessage(context.Context, string, string) (string, error)
	GetFileContents(ctx context.Context, repo string, path string, ref string) ([]byte, error)
	GetDirectoryContents(ctx context.Context, repo, path, ref string) (map[string]FileContents, error)
}

RepoClient describes an object capable of operating on git repositories

type RepoFinder

type RepoFinder struct {
	// GitHubHostname is the GitHub hostname to use when finding GitHub repos
	// (some people use fake GitHub hostnames to toggle SSH keys ("me.github.com") via ~/.ssh/config)
	GitHubHostname string
	FSFunc         func(path string) afero.Fs
	LF             func(string, ...interface{})
}

RepoFinder is an object that searches the local filesystem for git repositories configured for use with GitHub

func (*RepoFinder) Find

func (rf *RepoFinder) Find(searchPaths []string) (map[string]string, error)

Find recursively searches searchPaths and finds any valid git repositories with remotes configured for GitHub. It returns a map of GitHub repo name ("owner/repo") to absolute local filesystem path, or error.

Jump to

Keyboard shortcuts

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