github

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RepoListMaxResults is the number of results to return when getting a repository list
	// GitHub hard-limits this to 100
	RepoListMaxResults = 100
)

Variables

View Source
var (
	ErrVerifyTimeout = errors.New("Unable to verify GitHub access after 15 minutes")
)

Functions

func TreeToDisplay

func TreeToDisplay(entries []*github.TreeEntry, schemaType protos.SchemaType) *protos.Directory

TreeToDisplay turns a github GetRepoTree response into a nested structure This is necessary because GitHub's API returns a flat list of files

Types

type Github

type Github struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func New

func New() (*Github, error)

New returns a configured Github struct

func (*Github) CreateBranch

func (g *Github) CreateBranch(ctx context.Context, token, owner, repo, sha, branchName string) (*github.Reference, error)

CreateBranch creates a new branch under the repository for the given SHA and branchName

func (*Github) CreateCommit

func (g *Github) CreateCommit(ctx context.Context, token, owner, repo, treeSHA, commitName string, parent *github.Commit) (*github.Commit, error)

func (*Github) CreatePullRequest

func (g *Github) CreatePullRequest(ctx context.Context, token, owner, repo string, opts *PullRequestOpts) (*github.PullRequest, error)

func (*Github) CreateTree

func (g *Github) CreateTree(ctx context.Context, token, owner, repo, baseTreeSHA string, files []*github.TreeEntry) (*github.Tree, error)

CreateTree creates a new file tree.

func (*Github) Get

func (g *Github) Get(url, oAuthToken string) ([]byte, int, error)

Get makes a GET request with an oAuth token and returns the resulting body contents

func (*Github) GetMainBranch

func (g *Github) GetMainBranch(ctx context.Context, token, owner, repo string) (*github.Branch, error)

GetMainBranch gets the name and latest commit details of the main/master branch for a repository

func (*Github) GetRepoArchive

func (g *Github) GetRepoArchive(ctx context.Context, token, owner, repo string) ([]byte, error)

GetRepoArchive returns a zip of the contents of a github repository

func (*Github) GetRepoFile

func (g *Github) GetRepoFile(ctx context.Context, token, owner, repo, sha string) ([]byte, error)

GetRepoFile gets a single file from github. Used for Avro and JSONSchema imports

func (*Github) GetRepoList

func (g *Github) GetRepoList(ctx context.Context, installID int64, token string) ([]string, error)

GetRepoList gets all repositories that an install has access to

func (*Github) GetRepoTree

func (g *Github) GetRepoTree(ctx context.Context, token, owner, repo string) (*github.Tree, error)

func (*Github) Post

func (g *Github) Post(url string, values url.Values) ([]byte, int, error)

Post makes a form post and returns the resulting body contents

func (*Github) UpdateBranch

func (g *Github) UpdateBranch(ctx context.Context, token, owner, repo, sha, branchName string) (*github.Reference, error)

type IGithub

type IGithub interface {
	CreateBranch(ctx context.Context, token, owner, repo, sha, branchName string) (*github.Reference, error)
	CreateCommit(ctx context.Context, token, owner, repo, treeSHA, commitName string, parent *github.Commit) (*github.Commit, error)
	CreatePullRequest(ctx context.Context, token, owner, repo string, opts *PullRequestOpts) (*github.PullRequest, error)
	CreateTree(ctx context.Context, token, owner, repo, baseTreeSHA string, files []*github.TreeEntry) (*github.Tree, error)
	GetRepoArchive(ctx context.Context, token, owner, repo string) ([]byte, error)
	GetRepoFile(ctx context.Context, token, owner, repo, sha string) ([]byte, error)
	GetRepoList(ctx context.Context, installID int64, token string) ([]string, error)
	GetRepoTree(ctx context.Context, token, owner, repo string) (*github.Tree, error)
	Post(url string, values url.Values) ([]byte, int, error)
	UpdateBranch(ctx context.Context, token, owner, repo, sha, branchName string) (*github.Reference, error)
}

type PullRequestFile

type PullRequestFile struct {
	// Fill path to the file, including filename
	Path string

	// Contents of the file
	Content string
}

PullRequestFile represents a path to a file under a repository and it's contents. If the file path already exists, the existing contents will be modified

type PullRequestOpts

type PullRequestOpts struct {
	// Branch name, will be prefixed with "plumber_
	BranchName string

	// Optional, default is "Plumber commit"
	CommitName string

	// Title of the PR
	Title string

	// Description for PR
	Body string

	Files []*PullRequestFile
}

PullRequestOpts encapsulates all options necessary to create a PR with CreatePullRequest()

type RepoListResponse

type RepoListResponse struct {
	Repositories []*github.Repository `json:"repositories"`
}

RepoListResponse is used to unmarshal a response from api.github.com/user/installations/.../repositories The GitHub SDK does not have a method for that endpoint for some odd reason

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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