github

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 8 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

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

This section is empty.

Functions

This section is empty.

Types

type GitHubConfig

type GitHubConfig struct {
	Token    string
	Endpoint string
}

GitHubConfig is the struct that contains the configuration for the GitHub client Token: is the GitHub API token retrieved from the provider_access_tokens table in the database Endpoint: is the GitHub API endpoint If using the public GitHub API, Endpoint can be left blank disable revive linting for this struct as there is nothing wrong with the naming convention

type GraphQLAPI

type GraphQLAPI interface {
	RunQuery(ctx context.Context, query interface{}, variables map[string]interface{}) error
}

GraphQLAPI is the interface for interacting with the GitHub GraphQL API Add methods here for interacting with the GitHub GraphQL API e.g. GetRepositoryGraphInfo(ctx context.Context, owner string, name string) (*RepositoryInfo, error)

func NewGraphQLClient

func NewGraphQLClient(ctx context.Context, config GitHubConfig) (GraphQLAPI, error)

NewGraphQLClient creates a new GitHub GraphQL API client

type GraphQLClient

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

GraphQLClient is the struct that contains the GitHub GraphQL API client

func (*GraphQLClient) RunQuery

func (gc *GraphQLClient) RunQuery(ctx context.Context, query interface{}, variables map[string]interface{}) error

RunQuery executes a GraphQL query

type PackageListResult

type PackageListResult struct {
	Packages []*github.Package
}

PackageListResult is a struct to hold the results of a package list

type RepositoryListResult

type RepositoryListResult struct {
	Repositories []*github.Repository
}

RepositoryListResult is a struct that contains the information about a GitHub repository

type RestAPI

type RestAPI interface {
	GetAuthenticatedUser(context.Context) (*github.User, error)
	GetRepository(context.Context, string, string) (*github.Repository, error)
	ListAllRepositories(context.Context, bool, string) (RepositoryListResult, error)
	GetBranchProtection(context.Context, string, string, string) (*github.Protection, error)
	ListAllPackages(context.Context, bool, string, string, int, int) (PackageListResult, error)
	ListPackagesByRepository(context.Context, bool, string, string, int64, int, int) (PackageListResult, error)
	GetPackageByName(context.Context, bool, string, string, string) (*github.Package, error)
	GetPackageVersions(context.Context, bool, string, string, string) ([]*github.PackageVersion, error)
	GetPackageVersionByTag(context.Context, bool, string, string, string, string) (*github.PackageVersion, error)
	GetPackageVersionById(context.Context, bool, string, string, string, int64) (*github.PackageVersion, error)
	GetPullRequest(context.Context, string, string, int) (*github.PullRequest, error)
	CreateReview(context.Context, string, string, int, *github.PullRequestReviewRequest) (*github.PullRequestReview, error)
	ListReviews(context.Context, string, string, int, *github.ListOptions) ([]*github.PullRequestReview, error)
	DismissReview(context.Context, string, string, int, int64,
		*github.PullRequestReviewDismissalRequest) (*github.PullRequestReview, error)
	SetCommitStatus(context.Context, string, string, string, *github.RepoStatus) (*github.RepoStatus, error)
	ListFiles(context.Context, string, string, int, int, int) ([]*github.CommitFile, error)
	GetToken() string
	GetOwner() string

	// NewRequest allows for building raw and custom requests
	NewRequest(method, urlStr string, body any, opts ...github.RequestOption) (*http.Request, error)
	Do(ctx context.Context, req *http.Request, v any) (*github.Response, error)
}

RestAPI is the interface for interacting with the GitHub REST API Add methods here for interacting with the GitHub Rest API e.g. GetRepositoryRestInfo(ctx context.Context, owner string, name string) (*RepositoryInfo, error)

func NewRestClient

func NewRestClient(ctx context.Context, config GitHubConfig, owner string) (RestAPI, 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

type RestClient

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

RestClient is the struct that contains the GitHub REST API client

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) 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, v interface{}) (*github.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) 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) (PackageListResult, 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) (RepositoryListResult, 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) ListFiles

func (c *RestClient) ListFiles(
	ctx context.Context,
	owner string,
	repo string,
	number int,
	page int,
	perPage int,
) ([]*github.CommitFile, error)

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

func (*RestClient) ListPackagesByRepository

func (c *RestClient) ListPackagesByRepository(ctx context.Context, isOrg bool, owner string, artifactType string,
	repositoryId int64, pageNumber int, itemsPerPage int) (PackageListResult, error)

ListPackagesByRepository returns a list of all packages for an specific 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) NewRequest

func (c *RestClient) NewRequest(method, url string, body interface{}, opts ...github.RequestOption) (*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

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