github

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 16 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
)
View Source
const Github = "github"

Github is the string that represents the GitHub provider

Variables

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 RestClient

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

RestClient is the struct that contains the GitHub REST API client

func NewRestClient

func NewRestClient(
	ctx context.Context,
	config *minderv1.GitHubProviderConfig,
	metrics telemetry.HttpClientMetrics,
	token string,
	owner string,
) (*RestClient, 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 (*RestClient) CloseSecurityAdvisory

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

CloseSecurityAdvisory closes a security advisory

func (*RestClient) CreateComment

func (c *RestClient) CreateComment(ctx context.Context, owner, repo string, number int, comment string) error

CreateComment creates a comment on a pull request or an issue

func (*RestClient) CreateHook

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

CreateHook creates a new Hook.

func (*RestClient) CreatePullRequest

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

CreatePullRequest creates a pull request in a repository.

func (*RestClient) CreateReview

func (c *RestClient) 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 (*RestClient) CreateSecurityAdvisory

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

CreateSecurityAdvisory creates a new security advisory

func (*RestClient) DeleteHook

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

DeleteHook deletes a specified Hook.

func (*RestClient) DismissReview

func (c *RestClient) 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 (*RestClient) Do

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

Do sends an API request and returns the API response.

func (*RestClient) GetAuthenticatedUser

func (c *RestClient) GetAuthenticatedUser(ctx context.Context) (*github.User, error)

GetAuthenticatedUser returns the authenticated user

func (*RestClient) GetBaseURL

func (c *RestClient) GetBaseURL() string

GetBaseURL returns the base URL for the REST API.

func (*RestClient) GetBranchProtection

func (c *RestClient) 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 (*RestClient) GetOwner

func (c *RestClient) GetOwner() string

GetOwner returns the owner of the repository

func (*RestClient) GetPackageByName

func (c *RestClient) 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 (*RestClient) GetPackageVersionById

func (c *RestClient) 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 (*RestClient) GetPackageVersionByTag

func (c *RestClient) 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 (*RestClient) GetPackageVersions

func (c *RestClient) 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 (*RestClient) GetPullRequest

func (c *RestClient) 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 (*RestClient) GetRepository

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

GetRepository returns a single repository for the authenticated user

func (*RestClient) GetToken

func (c *RestClient) GetToken() string

GetToken returns the token used to authenticate with the GitHub API

func (*RestClient) ListAllPackages

func (c *RestClient) 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 (*RestClient) ListAllRepositories

func (c *RestClient) 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 (*RestClient) ListEmails added in v0.0.22

func (c *RestClient) ListEmails(ctx context.Context, opts *github.ListOptions) ([]*github.UserEmail, error)

ListEmails lists all emails for the authenticated user.

func (*RestClient) ListFiles

func (c *RestClient) 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 (*RestClient) ListHooks

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

ListHooks lists all Hooks for the specified repository.

func (*RestClient) ListOrganizationRepsitories

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

ListOrganizationRepsitories returns a list of all repositories for the organization

func (*RestClient) ListPackagesByRepository

func (c *RestClient) 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 (*RestClient) ListPullRequests

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

ListPullRequests lists all pull requests in a repository.

func (*RestClient) ListReviews

func (c *RestClient) 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 (*RestClient) ListUserRepositories

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

ListUserRepositories returns a list of all repositories for the authenticated user

func (*RestClient) NewRequest

func (c *RestClient) 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 (*RestClient) SetCommitStatus

func (c *RestClient) 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 (*RestClient) UpdateBranchProtection

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

UpdateBranchProtection updates the branch protection for a given branch

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