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 AppInstallation

    type AppInstallation struct {
    	ID int64
    }

    type AppInstallations

    type AppInstallations []AppInstallation

    func (AppInstallations) IDPresent

    func (ai AppInstallations) IDPresent(id int64) bool

    type AppRepoPermissions

    type AppRepoPermissions struct {
    	Repo              string
    	Admin, Push, Pull bool
    }

    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)
        	GetUserAppInstallationsFunc   func(ctx context.Context) (AppInstallations, error)
        	GetUserAppReposFunc           func(ctx context.Context, instID int64) ([]string, error)
        	GetUserFunc                   func(ctx context.Context) (string, error)
        	GetUserAppRepoPermissionsFunc func(ctx context.Context, instID int64) (map[string]AppRepoPermissions, error)
        	GetRepoArchiveFunc            func(ctx context.Context, repo, ref string) (string, 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) GetRepoArchive

          func (frc *FakeRepoClient) GetRepoArchive(ctx context.Context, repo, ref string) (string, error)

          func (*FakeRepoClient) GetTags

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

          func (*FakeRepoClient) GetUser

          func (frc *FakeRepoClient) GetUser(ctx context.Context) (string, error)

          func (*FakeRepoClient) GetUserAppInstallations

          func (frc *FakeRepoClient) GetUserAppInstallations(ctx context.Context) (AppInstallations, error)

          func (*FakeRepoClient) GetUserAppRepoPermissions

          func (frc *FakeRepoClient) GetUserAppRepoPermissions(ctx context.Context, instID int64) (map[string]AppRepoPermissions, error)

          func (*FakeRepoClient) GetUserAppRepos

          func (frc *FakeRepoClient) GetUserAppRepos(ctx context.Context, instID int64) ([]string, 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 GitHubAppInstallationClient

            type GitHubAppInstallationClient interface {
            	GetUserAppInstallations(ctx context.Context) (AppInstallations, error)
            	GetUserAppRepos(ctx context.Context, appID int64) ([]string, error)
            	GetUser(ctx context.Context) (string, error)
            	GetUserAppRepoPermissions(ctx context.Context, instID int64) (map[string]AppRepoPermissions, error)
            }

              GitHubAppInstallationClient describes a GitHub client that returns user-scoped metadata regarding an app installation

              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) GetRepoArchive

                              func (ghc *GitHubClient) GetRepoArchive(ctx context.Context, repo, ref string) (string, error)

                                GetRepoArchive fetches repo at ref as a gzip-compressed tar archive and returns the local filesystem path, or error It is the caller's responsibility to clean up the file when finished

                                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) GetUser

                                  func (ghc *GitHubClient) GetUser(ctx context.Context) (string, error)

                                    GetUser gets the authenticated user login name This method only uses the static token associated with the GitHubClient and not anything present in the context GitHubClient should be populated with the user token returned by the oauth login endpoint via the oauth callback handler

                                    func (*GitHubClient) GetUserAppInstallations

                                    func (ghc *GitHubClient) GetUserAppInstallations(ctx context.Context) (AppInstallations, error)

                                      GetUserAppInstallationCount returns the number of app installations that are accessible to the authenticated user This method only uses the static token associated with the GitHubClient and not anything present in the context GitHubClient should be populated with the user token returned by the oauth login endpoint via the oauth callback handler

                                      func (*GitHubClient) GetUserAppRepoPermissions

                                      func (ghc *GitHubClient) GetUserAppRepoPermissions(ctx context.Context, instID int64) (map[string]AppRepoPermissions, error)

                                      func (*GitHubClient) GetUserAppRepos

                                      func (ghc *GitHubClient) GetUserAppRepos(ctx context.Context, instID int64) ([]string, error)

                                        GetUserAppRepos gets repositories that are accessible to the authenticated user for an app installation This method only uses the static token associated with the GitHubClient and not anything present in the context GitHubClient should be populated with the user token returned by the oauth login endpoint via the oauth callback handler

                                        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  Note that the github client CreateStatus function will bail if the context was canceled. It is often recommended to pass a fresh context to this function.

                                          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
                                              	// SetStatusCallback is a callback executed whenever SetStatus is called, if non-nil
                                              	SetStatusCallback StatusCallback
                                              	// 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) GetRepoArchive

                                                func (lw *LocalWrapper) GetRepoArchive(ctx context.Context, repo, ref string) (string, error)

                                                func (*LocalWrapper) GetTags

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

                                                  stubs to satisfy the interface

                                                  func (*LocalWrapper) SetStatus

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

                                                  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)
                                                  	GetRepoArchive(ctx context.Context, repo, ref string) (string, 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.

                                                        type StatusCallback

                                                        type StatusCallback func(context.Context, string, string, *CommitStatus) error