github

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package github provides a client for interacting with the GitHub API

Index

Constants

View Source
const (
	// ExpensiveRestCallTimeout is the timeout for expensive REST calls
	ExpensiveRestCallTimeout = 15 * time.Second
	// MaxRateLimitWait is the maximum time to wait for a rate limit to reset
	MaxRateLimitWait = 5 * time.Minute
	// MaxRateLimitRetries is the maximum number of retries for rate limit errors after waiting
	MaxRateLimitRetries = 1
	// DefaultRateLimitWaitTime is the default time to wait for a rate limit to reset
	DefaultRateLimitWaitTime = 1 * time.Minute
)

Variables

View Source
var (
	// ErrNotFound Denotes if the call returned a 404
	ErrNotFound = errors.New("not found")
)

Functions

func ConvertRepositories added in v0.0.36

func ConvertRepositories(repos []*github.Repository) []*minderv1.Repository

ConvertRepositories converts a list of GitHub repositories to a list of minder repositories

Types

type Delegate added in v0.0.36

type Delegate interface {
	GetCredential() provifv1.GitHubCredential
	ListUserRepositories(context.Context, string) ([]*minderv1.Repository, error)
	ListOrganizationRepositories(context.Context, string) ([]*minderv1.Repository, error)
	ListAllRepositories(context.Context, bool, string) ([]*github.Repository, error)
	GetUserId(ctx context.Context) (int64, error)
	GetName(ctx context.Context) (string, error)
	GetLogin(ctx context.Context) (string, error)
	GetPrimaryEmail(ctx context.Context) (string, error)
}

Delegate is the interface that contains operations that differ between different GitHub actors (user vs app)

type GitHub added in v0.0.35

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

GitHub is the struct that contains the shared GitHub client operations

func NewGitHub added in v0.0.36

func NewGitHub(
	client *github.Client,
	owner string,
	cache ratecache.RestClientCache,
	delegate Delegate,
) *GitHub

NewGitHub creates a new GitHub client

func (*GitHub) AddAuthToPushOptions added in v0.0.36

func (c *GitHub) AddAuthToPushOptions(ctx context.Context, pushOptions *git.PushOptions) error

AddAuthToPushOptions adds authorization to the push options

func (*GitHub) Clone added in v0.0.35

func (c *GitHub) Clone(ctx context.Context, cloneUrl string, branch string) (*git.Repository, error)

Clone clones a GitHub repository

func (*GitHub) CloseSecurityAdvisory added in v0.0.35

func (c *GitHub) CloseSecurityAdvisory(ctx context.Context, owner, repo, id string) error

CloseSecurityAdvisory closes a security advisory

func (*GitHub) CreateHook added in v0.0.35

func (c *GitHub) CreateHook(ctx context.Context, owner, repo string, hook *github.Hook) (*github.Hook, error)

CreateHook creates a new Hook.

func (*GitHub) CreateIssueComment added in v0.0.35

func (c *GitHub) CreateIssueComment(
	ctx context.Context, owner, repo string, number int, comment string,
) (*github.IssueComment, error)

CreateIssueComment creates a comment on a pull request or an issue

func (*GitHub) CreatePullRequest added in v0.0.35

func (c *GitHub) CreatePullRequest(
	ctx context.Context,
	owner, repo, title, body, head, base string,
) (*github.PullRequest, error)

CreatePullRequest creates a pull request in a repository.

func (*GitHub) CreateReview added in v0.0.35

func (c *GitHub) CreateReview(
	ctx context.Context, owner, repo string, number int, reviewRequest *github.PullRequestReviewRequest,
) (*github.PullRequestReview, error)

CreateReview is a wrapper for the GitHub API to create a review

func (*GitHub) CreateSecurityAdvisory added in v0.0.35

func (c *GitHub) CreateSecurityAdvisory(ctx context.Context, owner, repo, severity, summary, description string,
	v []*github.AdvisoryVulnerability) (string, error)

CreateSecurityAdvisory creates a new security advisory

func (*GitHub) DeleteHook added in v0.0.35

func (c *GitHub) DeleteHook(ctx context.Context, owner, repo string, id int64) (*github.Response, error)

DeleteHook deletes a specified Hook.

func (*GitHub) DismissReview added in v0.0.35

func (c *GitHub) DismissReview(
	ctx context.Context,
	owner, repo string,
	prId int,
	reviewId int64,
	dismissalRequest *github.PullRequestReviewDismissalRequest,
) (*github.PullRequestReview, error)

DismissReview is a wrapper for the GitHub API to dismiss a review

func (*GitHub) Do added in v0.0.35

func (c *GitHub) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do sends an API request and returns the API response.

func (*GitHub) GetBaseURL added in v0.0.35

func (c *GitHub) GetBaseURL() string

GetBaseURL returns the base URL for the REST API.

func (*GitHub) GetBranchProtection added in v0.0.35

func (c *GitHub) GetBranchProtection(ctx context.Context, owner string,
	repo_name string, branch_name string) (*github.Protection, error)

GetBranchProtection returns the branch protection for a given branch

func (*GitHub) GetCredential added in v0.0.36

func (c *GitHub) GetCredential() provifv1.GitHubCredential

GetCredential returns the credential used to authenticate with the GitHub API

func (*GitHub) GetLogin added in v0.0.36

func (c *GitHub) GetLogin(ctx context.Context) (string, error)

GetLogin returns the login for the acting user

func (*GitHub) GetName added in v0.0.36

func (c *GitHub) GetName(ctx context.Context) (string, error)

GetName returns the username for the acting user

func (*GitHub) GetOwner added in v0.0.35

func (c *GitHub) GetOwner() string

GetOwner returns the owner of the repository

func (*GitHub) GetPackageByName added in v0.0.35

func (c *GitHub) GetPackageByName(ctx context.Context, isOrg bool, owner string, package_type string,
	package_name string) (*github.Package, error)

GetPackageByName returns a single package for the authenticated user or for the org

func (*GitHub) GetPackageVersionById added in v0.0.35

func (c *GitHub) GetPackageVersionById(
	ctx context.Context,
	isOrg bool,
	owner string,
	packageType string,
	packageName string,
	version int64,
) (*github.PackageVersion, error)

GetPackageVersionById returns a single package version for the specific id

func (*GitHub) GetPackageVersionByTag added in v0.0.35

func (c *GitHub) GetPackageVersionByTag(ctx context.Context, isOrg bool, owner string, package_type string,
	package_name string, tag string) (*github.PackageVersion, error)

GetPackageVersionByTag returns a single package version for the specific tag

func (*GitHub) GetPackageVersions added in v0.0.35

func (c *GitHub) GetPackageVersions(ctx context.Context, isOrg bool, owner string, package_type string,
	package_name string) ([]*github.PackageVersion, error)

GetPackageVersions returns a list of all package versions for the authenticated user or org

func (*GitHub) GetPrimaryEmail added in v0.0.35

func (c *GitHub) GetPrimaryEmail(ctx context.Context) (string, error)

GetPrimaryEmail returns the primary email for the acting user

func (*GitHub) GetPullRequest added in v0.0.35

func (c *GitHub) GetPullRequest(
	ctx context.Context,
	owner string,
	repo string,
	number int,
) (*github.PullRequest, error)

GetPullRequest is a wrapper for the GitHub API to get a pull request

func (*GitHub) GetRepository added in v0.0.35

func (c *GitHub) GetRepository(ctx context.Context, owner string, name string) (*github.Repository, error)

GetRepository returns a single repository for the authenticated user

func (*GitHub) GetUserId added in v0.0.35

func (c *GitHub) GetUserId(ctx context.Context) (int64, error)

GetUserId returns the user id for the acting user

func (*GitHub) ListAllRepositories added in v0.0.35

func (c *GitHub) ListAllRepositories(ctx context.Context, isOrg bool, owner string) ([]*github.Repository, error)

ListAllRepositories lists all repositories the credential has access to

func (*GitHub) ListFiles added in v0.0.35

func (c *GitHub) ListFiles(
	ctx context.Context,
	owner string,
	repo string,
	prNumber int,
	perPage int,
	pageNumber int,
) ([]*github.CommitFile, *github.Response, error)

ListFiles is a wrapper for the GitHub API to list files in a pull request

func (*GitHub) ListHooks added in v0.0.35

func (c *GitHub) ListHooks(ctx context.Context, owner, repo string) ([]*github.Hook, error)

ListHooks lists all Hooks for the specified repository.

func (*GitHub) ListIssueComments added in v0.0.35

func (c *GitHub) ListIssueComments(
	ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions,
) ([]*github.IssueComment, error)

ListIssueComments is a wrapper for the GitHub API to get all comments in a review

func (*GitHub) ListOrganizationRepsitories added in v0.0.35

func (c *GitHub) ListOrganizationRepsitories(ctx context.Context, owner string) ([]*minderv1.Repository, error)

ListOrganizationRepsitories lists all repositories for the organization

func (*GitHub) ListPackagesByRepository added in v0.0.35

func (c *GitHub) ListPackagesByRepository(ctx context.Context, isOrg bool, owner string, artifactType string,
	repositoryId int64, pageNumber int, itemsPerPage int) ([]*github.Package, error)

ListPackagesByRepository returns a list of all packages for a specific repository

func (*GitHub) ListPullRequests added in v0.0.35

func (c *GitHub) ListPullRequests(
	ctx context.Context,
	owner, repo string,
	opt *github.PullRequestListOptions,
) ([]*github.PullRequest, error)

ListPullRequests lists all pull requests in a repository.

func (*GitHub) ListReviews added in v0.0.35

func (c *GitHub) ListReviews(
	ctx context.Context,
	owner, repo string,
	number int,
	opt *github.ListOptions,
) ([]*github.PullRequestReview, error)

ListReviews is a wrapper for the GitHub API to list reviews

func (*GitHub) ListUserRepositories added in v0.0.35

func (c *GitHub) ListUserRepositories(ctx context.Context, owner string) ([]*minderv1.Repository, error)

ListUserRepositories lists all repositories for the owner

func (*GitHub) NewRequest added in v0.0.35

func (c *GitHub) NewRequest(method, requestUrl string, body any) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*GitHub) SetCommitStatus added in v0.0.35

func (c *GitHub) SetCommitStatus(
	ctx context.Context, owner, repo, ref string, status *github.RepoStatus,
) (*github.RepoStatus, error)

SetCommitStatus is a wrapper for the GitHub API to set a commit status

func (*GitHub) UpdateBranchProtection added in v0.0.35

func (c *GitHub) UpdateBranchProtection(
	ctx context.Context, owner, repo, branch string, preq *github.ProtectionRequest,
) error

UpdateBranchProtection updates the branch protection for a given branch

func (*GitHub) UpdateIssueComment added in v0.0.35

func (c *GitHub) UpdateIssueComment(ctx context.Context, owner, repo string, number int64, comment string) error

UpdateIssueComment updates a comment on a pull request or an issue

func (*GitHub) UpdateReview added in v0.0.35

func (c *GitHub) UpdateReview(
	ctx context.Context, owner, repo string, number int, reviewId int64, body string,
) (*github.PullRequestReview, error)

UpdateReview is a wrapper for the GitHub API to update a review

Directories

Path Synopsis
Package app provides the GitHub App specific operations
Package app provides the GitHub App specific operations
Package mockgh is a generated GoMock package.
Package mockgh is a generated GoMock package.
Package oauth provides a client for interacting with the GitHub API using OAuth 2.0 authorization
Package oauth provides a client for interacting with the GitHub API using OAuth 2.0 authorization

Jump to

Keyboard shortcuts

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