github

package
v0.9.20 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenEnvKey is the default GitHub token environemt variable key
	TokenEnvKey = "GITHUB_TOKEN"
	// GitHubURL Prefix for github URLs
	GitHubURL = "https://github.com/"
)
View Source
const (
	// UserForkName is the name we will give to the user's remote when adding
	// it to repos
	UserForkName = "userfork"
)

Variables

This section is empty.

Functions

func PrepareFork

func PrepareFork(branchName, upstreamOrg, upstreamRepo, myOrg, myRepo string) (repo *git.Repo, err error)

PrepareFork prepares a branch from a repo fork

func VerifyFork

func VerifyFork(branchName, forkOwner, forkRepo, parentOwner, parentRepo string) error

VerifyFork does a pre-check of a fork to see if we can create a PR from it

Types

type Client

type Client interface {
	GetCommit(
		context.Context, string, string, string,
	) (*github.Commit, *github.Response, error)
	GetPullRequest(
		context.Context, string, string, int,
	) (*github.PullRequest, *github.Response, error)
	GetIssue(
		context.Context, string, string, int,
	) (*github.Issue, *github.Response, error)
	GetRepoCommit(
		context.Context, string, string, string,
	) (*github.RepositoryCommit, *github.Response, error)
	ListCommits(
		context.Context, string, string, *github.CommitsListOptions,
	) ([]*github.RepositoryCommit, *github.Response, error)
	ListPullRequestsWithCommit(
		context.Context, string, string, string, *github.PullRequestListOptions,
	) ([]*github.PullRequest, *github.Response, error)
	ListMilestones(
		context.Context, string, string, *github.MilestoneListOptions,
	) ([]*github.Milestone, *github.Response, error)
	ListReleases(
		context.Context, string, string, *github.ListOptions,
	) ([]*github.RepositoryRelease, *github.Response, error)
	GetReleaseByTag(
		context.Context, string, string, string,
	) (*github.RepositoryRelease, *github.Response, error)
	DownloadReleaseAsset(
		context.Context, string, string, int64,
	) (io.ReadCloser, string, error)
	ListTags(
		context.Context, string, string, *github.ListOptions,
	) ([]*github.RepositoryTag, *github.Response, error)
	ListBranches(
		context.Context, string, string, *github.BranchListOptions,
	) ([]*github.Branch, *github.Response, error)
	CreatePullRequest(
		context.Context, string, string, string, string, string, string,
	) (*github.PullRequest, error)
	CreateIssue(
		context.Context, string, string, *github.IssueRequest,
	) (*github.Issue, error)
	GetRepository(
		context.Context, string, string,
	) (*github.Repository, *github.Response, error)
	UpdateReleasePage(
		context.Context, string, string, int64, *github.RepositoryRelease,
	) (*github.RepositoryRelease, error)
	UpdateIssue(
		context.Context, string, string, int, *github.IssueRequest,
	) (*github.Issue, *github.Response, error)
	AddLabels(
		context.Context, string, string, int, []string,
	) ([]*github.Label, *github.Response, error)
	UploadReleaseAsset(
		context.Context, string, string, int64, *github.UploadOptions, *os.File,
	) (*github.ReleaseAsset, error)
	DeleteReleaseAsset(
		context.Context, string, string, int64,
	) error
	ListReleaseAssets(
		context.Context, string, string, int64, *github.ListOptions,
	) ([]*github.ReleaseAsset, error)
	CreateComment(
		context.Context, string, string, int, string,
	) (*github.IssueComment, *github.Response, error)
}

Client is an interface modeling supported GitHub operations

func NewRecorder

func NewRecorder(c Client, recordDir string) Client

func NewReplayer

func NewReplayer(replayDir string) Client

type GitHub

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

GitHub is a wrapper around GitHub related functionality

func New

func New() *GitHub

New creates a new default GitHub client. Tokens set via the $GITHUB_TOKEN environment variable will result in an authenticated client. If the $GITHUB_TOKEN is not set, then the client will do unauthenticated GitHub requests.

func NewEnterprise

func NewEnterprise(baseURL, uploadURL string) (*GitHub, error)

func NewEnterpriseWithToken

func NewEnterpriseWithToken(baseURL, uploadURL, token string) (*GitHub, error)

func NewWithToken

func NewWithToken(token string) (*GitHub, error)

NewWithToken can be used to specify a GitHub token through parameters. Empty string will result in unauthenticated client, which makes unauthenticated requests.

func (*GitHub) BranchExists

func (g *GitHub) BranchExists(
	owner, repo, branchname string,
) (isBranch bool, err error)

BranchExists checks if a branch exists in a given repo

func (*GitHub) Client

func (g *GitHub) Client() Client

Client can be used to retrieve the Client type

func (*GitHub) CreateIssue

func (g *GitHub) CreateIssue(
	owner, repo, title, body string, opts *NewIssueOptions,
) (*github.Issue, error)

CreateIssue files a new issue in the specified respoitory

func (*GitHub) CreatePullRequest

func (g *GitHub) CreatePullRequest(
	owner, repo, baseBranchName, headBranchName, title, body string,
) (*github.PullRequest, error)

CreatePullRequest Creates a new pull request in owner/repo:baseBranch to merge changes from headBranchName which is a string containing a branch in the same repository or a user:branch pair

func (*GitHub) DeleteReleaseAsset

func (g *GitHub) DeleteReleaseAsset(owner, repo string, assetID int64) error

DeleteReleaseAsset deletes an asset from a release

func (*GitHub) DownloadReleaseAssets

func (g *GitHub) DownloadReleaseAssets(owner, repo string, releaseTags []string, outputDir string) (finalErr error)

DownloadReleaseAssets downloads a set of GitHub release assets to an `outputDir`. Assets to download are derived from the `releaseTags`.

func (*GitHub) GetMilestone

func (g *GitHub) GetMilestone(owner, repo, title string) (
	ms *github.Milestone, exists bool, err error,
)

GetMilestone returns a milestone object from its string name

func (*GitHub) GetReleaseTags

func (g *GitHub) GetReleaseTags(owner, repo string, includePrereleases bool) ([]string, error)

GetReleaseTags returns a list of GitHub release tags for the provided `owner` and `repo`. If `includePrereleases` is `true`, then the resulting slice will also contain pre/drafted releases.

func (*GitHub) GetRepository

func (g *GitHub) GetRepository(
	owner, repo string,
) (*github.Repository, error)

GetRepository gets a repository using the current client

func (*GitHub) LatestGitHubTagsPerBranch

func (g *GitHub) LatestGitHubTagsPerBranch() (TagsPerBranch, error)

LatestGitHubTagsPerBranch returns the latest GitHub available tag for each branch. The logic how releases are associates with branches is motivated by the changelog generation and bound to the default Kubernetes release strategy, which is also the reason why we do not provide a repo and org parameter here.

Releases are associated in the following way: - x.y.0-alpha.z releases are only associated with the main branch - x.y.0-beta.z releases are only associated with their release-x.y branch - x.y.0 final releases are associated with the main branch and the release-x.y branch

func (*GitHub) ListBranches

func (g *GitHub) ListBranches(
	owner, repo string,
) ([]*github.Branch, error)

ListBranches gets a repository using the current client

func (*GitHub) ListReleaseAssets

func (g *GitHub) ListReleaseAssets(
	owner, repo string, releaseID int64,
) ([]*github.ReleaseAsset, error)

ListReleaseAssets gets the assets uploaded to a GitHub release

func (*GitHub) ListTags

func (g *GitHub) ListTags(owner, repo string) ([]*github.RepositoryTag, error)

ListTags gets the tags from a GitHub repository

func (*GitHub) Options

func (g *GitHub) Options() *Options

Options return a pointer to the options struct

func (*GitHub) Releases

func (g *GitHub) Releases(owner, repo string, includePrereleases bool) ([]*github.RepositoryRelease, error)

Releases returns a list of GitHub releases for the provided `owner` and `repo`. If `includePrereleases` is `true`, then the resulting slice will also contain pre/drafted releases. TODO: Create a more descriptive method name and update references

func (*GitHub) RepoIsForkOf

func (g *GitHub) RepoIsForkOf(
	forkOwner, forkRepo, parentOwner, parentRepo string,
) (bool, error)

RepoIsForkOf Function that checks if a repository is a fork of another

func (*GitHub) SetClient

func (g *GitHub) SetClient(client Client)

SetClient can be used to manually set the internal GitHub client

func (*GitHub) SetOptions

func (g *GitHub) SetOptions(opts *Options)

SetOptions gets an options set for the GitHub object

func (*GitHub) TagExists

func (g *GitHub) TagExists(owner, repo, tag string) (exists bool, err error)

TagExists returns true is a specified tag exists in the repo

func (*GitHub) UpdateReleasePage

func (g *GitHub) UpdateReleasePage(
	owner, repo string,
	releaseID int64,
	tag, commitish, name, body string,
	isDraft, isPrerelease bool,
) (release *github.RepositoryRelease, err error)

UpdateReleasePage updates a release page in GitHub

func (*GitHub) UploadReleaseAsset

func (g *GitHub) UploadReleaseAsset(
	owner, repo string, releaseID int64, fileName string,
) (*github.ReleaseAsset, error)

UploadReleaseAsset uploads a file onto the release assets

type NewIssueOptions

type NewIssueOptions struct {
	Milestone string   // Name of milestone to set
	State     string   // open, closed or all. Defaults to "open"
	Assignees []string // List of GitHub handles of extra assignees, must be collaborators
	Labels    []string // List of labels to apply. They will be created if new
}

NewIssueOptions is a struct of optional fields for new issues

type Options

type Options struct {
	// How many items to request in calls to the github API
	// that require pagination.
	ItemsPerPage int
}

Options is a set of options to configure the behavior of the GitHub package

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions return an options struct with commonly used settings

func (*Options) GetItemsPerPage

func (o *Options) GetItemsPerPage() int

type TagsPerBranch

type TagsPerBranch map[string]string

TagsPerBranch is an abstraction over a simple branch to latest tag association

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