github

package
v0.0.35 Latest Latest
Warning

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

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

Documentation

Overview

Package github provides a client for interacting with the GitHub API

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
)
View Source
const Github = "github"

Github is the string that represents the GitHub provider

Variables

AuthorizationFlows is the list of authorization flows that the GitHub provider supports

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

Implements is the list of provider types that the GitHub provider implements

Functions

func ParseV1Config

func ParseV1Config(rawCfg json.RawMessage) (*minderv1.GitHubProviderConfig, error)

ParseV1Config parses the raw config into a GitHubConfig struct

Types

type GitHub added in v0.0.35

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

GitHub is the struct that contains the GitHub client operations

func NewRestClient

func NewRestClient(
	config *minderv1.GitHubProviderConfig,
	metrics telemetry.HttpClientMetrics,
	restClientCache ratecache.RestClientCache,
	token string,
	owner string,
) (*GitHub, error)

NewRestClient creates a new GitHub REST API client BaseURL defaults to the public GitHub API, if needing to use a customer domain endpoint (as is the case with GitHub Enterprise), set the Endpoint field in the GitHubConfig struct

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) 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 authenticated 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) GetToken added in v0.0.35

func (c *GitHub) GetToken() string

GetToken returns the token used to authenticate with the GitHub API

func (*GitHub) GetUserId added in v0.0.35

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

GetUserId returns the user id for the authenticated user

func (*GitHub) GetUsername added in v0.0.35

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

GetUsername returns the username for the authenticated user

func (*GitHub) ListAllPackages added in v0.0.35

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

ListAllPackages returns a list of all packages for the authenticated user

func (*GitHub) ListAllRepositories added in v0.0.35

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

ListAllRepositories returns a list of all repositories for the authenticated user Two APIs are available, contigent on whether the token is for a user or an organization

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 returns a list of 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 returns a list of all repositories for the authenticated user

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 mockgh is a generated GoMock package.
Package mockgh is a generated GoMock package.

Jump to

Keyboard shortcuts

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