Documentation
¶
Overview ¶
Package github provides a client for interacting with the GitHub API
Index ¶
- Constants
- Variables
- func CanHandleOwner(_ context.Context, prov db.Provider, owner string) bool
- func IsMinderHook(hook *github.Hook, hostURL string) (bool, error)
- func NewFallbackTokenClient(appConfig config.ProviderConfig) *github.Client
- type ClientService
- type ClientServiceImplementation
- func (ClientServiceImplementation) DeleteInstallation(ctx context.Context, id int64, jwt string) (*github.Response, error)
- func (ClientServiceImplementation) GetInstallation(ctx context.Context, installationID int64, jwt string) (*github.Installation, *github.Response, error)
- func (ClientServiceImplementation) GetUserIdFromToken(ctx context.Context, token *oauth2.Token) (*int64, error)
- func (ClientServiceImplementation) ListUserInstallations(ctx context.Context, token *oauth2.Token) ([]*github.Installation, error)
- type Delegate
- type GitHub
- func (c *GitHub) AddAuthToPushOptions(ctx context.Context, pushOptions *git.PushOptions) error
- func (_ *GitHub) CanImplement(trait minderv1.ProviderType) bool
- func (c *GitHub) Clone(ctx context.Context, cloneUrl string, branch string) (*git.Repository, error)
- func (c *GitHub) ClosePullRequest(ctx context.Context, owner, repo string, number int) (*github.PullRequest, error)
- func (c *GitHub) CloseSecurityAdvisory(ctx context.Context, owner, repo, id string) error
- func (c *GitHub) CreateHook(ctx context.Context, owner, repo string, hook *github.Hook) (*github.Hook, error)
- func (c *GitHub) CreateIssueComment(ctx context.Context, owner, repo string, number int, comment string) (*github.IssueComment, error)
- func (c *GitHub) CreatePullRequest(ctx context.Context, owner, repo, title, body, head, base string) (*github.PullRequest, error)
- func (c *GitHub) CreateReview(ctx context.Context, owner, repo string, number int, ...) (*github.PullRequestReview, error)
- func (c *GitHub) CreateSecurityAdvisory(ctx context.Context, owner, repo, severity, summary, description string, ...) (string, error)
- func (c *GitHub) DeleteHook(ctx context.Context, owner, repo string, id int64) (*github.Response, error)
- func (c *GitHub) DismissReview(ctx context.Context, owner, repo string, prId int, reviewId int64, ...) (*github.PullRequestReview, error)
- func (c *GitHub) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (c *GitHub) EditHook(ctx context.Context, owner, repo string, id int64, hook *github.Hook) (*github.Hook, error)
- func (c *GitHub) GetBaseURL() string
- func (c *GitHub) GetBranchProtection(ctx context.Context, owner string, repo_name string, branch_name string) (*github.Protection, error)
- func (c *GitHub) GetCredential() provifv1.GitHubCredential
- func (c *GitHub) GetLogin(ctx context.Context) (string, error)
- func (c *GitHub) GetName(ctx context.Context) (string, error)
- func (c *GitHub) GetNamespaceURL() string
- func (c *GitHub) GetPackageByName(ctx context.Context, owner string, package_type string, package_name string) (*github.Package, error)
- func (c *GitHub) GetPackageVersionById(ctx context.Context, owner string, packageType string, packageName string, ...) (*github.PackageVersion, error)
- func (c *GitHub) GetPackageVersionByTag(ctx context.Context, owner string, package_type string, package_name string, ...) (*github.PackageVersion, error)
- func (c *GitHub) GetPackageVersions(ctx context.Context, owner string, package_type string, package_name string) ([]*github.PackageVersion, error)
- func (c *GitHub) GetPrimaryEmail(ctx context.Context) (string, error)
- func (c *GitHub) GetPullRequest(ctx context.Context, owner string, repo string, number int) (*github.PullRequest, error)
- func (c *GitHub) GetRepository(ctx context.Context, owner string, name string) (*github.Repository, error)
- func (c *GitHub) GetUserId(ctx context.Context) (int64, error)
- func (c *GitHub) IsOrg() bool
- func (c *GitHub) ListAllRepositories(ctx context.Context) ([]*minderv1.Repository, error)
- func (c *GitHub) ListFiles(ctx context.Context, owner string, repo string, prNumber int, perPage int, ...) ([]*github.CommitFile, *github.Response, error)
- func (c *GitHub) ListHooks(ctx context.Context, owner, repo string) ([]*github.Hook, error)
- func (c *GitHub) ListImages(ctx context.Context) ([]string, error)
- func (c *GitHub) ListIssueComments(ctx context.Context, owner, repo string, number int, ...) ([]*github.IssueComment, error)
- func (c *GitHub) ListPackagesByRepository(ctx context.Context, owner string, artifactType string, repositoryId int64, ...) ([]*github.Package, error)
- func (c *GitHub) ListPullRequests(ctx context.Context, owner, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, error)
- func (c *GitHub) ListReviews(ctx context.Context, owner, repo string, number int, opt *github.ListOptions) ([]*github.PullRequestReview, error)
- func (c *GitHub) NewRequest(method, requestUrl string, body any) (*http.Request, error)
- func (c *GitHub) SetCommitStatus(ctx context.Context, owner, repo, ref string, status *github.RepoStatus) (*github.RepoStatus, error)
- func (c *GitHub) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, ...) error
- func (c *GitHub) UpdateIssueComment(ctx context.Context, owner, repo string, number int64, comment string) error
- func (c *GitHub) UpdateReview(ctx context.Context, owner, repo string, number int, reviewId int64, ...) (*github.PullRequestReview, error)
Constants ¶
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 ¶
var ( // ErrNotFound denotes if the call returned a 404 ErrNotFound = errors.New("not found") // ErrBranchNotFound denotes if the branch was not found ErrBranchNotFound = errors.New("branch not found") // ErrNoPackageListingClient denotes if there is no package listing client available ErrNoPackageListingClient = errors.New("no package listing client available") )
Functions ¶
func CanHandleOwner ¶ added in v0.0.39
CanHandleOwner checks if the GitHub provider has the right credentials to handle the owner
func IsMinderHook ¶ added in v0.0.37
IsMinderHook checks if a GitHub hook is a Minder hook
func NewFallbackTokenClient ¶ added in v0.0.42
func NewFallbackTokenClient(appConfig config.ProviderConfig) *github.Client
NewFallbackTokenClient creates a new GitHub client that uses the GitHub App's fallback token
Types ¶
type ClientService ¶ added in v0.0.39
type ClientService interface { GetInstallation(ctx context.Context, id int64, jwt string) (*github.Installation, *github.Response, error) GetUserIdFromToken(ctx context.Context, token *oauth2.Token) (*int64, error) ListUserInstallations(ctx context.Context, token *oauth2.Token) ([]*github.Installation, error) DeleteInstallation(ctx context.Context, id int64, jwt string) (*github.Response, error) }
ClientService is an interface for GitHub operations It is used to mock GitHub operations in tests, but in order to generate mocks, the interface must be exported
type ClientServiceImplementation ¶ added in v0.0.39
type ClientServiceImplementation struct{}
ClientServiceImplementation is the implementation of the ClientService interface
func (ClientServiceImplementation) DeleteInstallation ¶ added in v0.0.40
func (ClientServiceImplementation) DeleteInstallation(ctx context.Context, id int64, jwt string) (*github.Response, error)
DeleteInstallation is a wrapper for the GitHub API to delete an installation
func (ClientServiceImplementation) GetInstallation ¶ added in v0.0.39
func (ClientServiceImplementation) GetInstallation( ctx context.Context, installationID int64, jwt string, ) (*github.Installation, *github.Response, error)
GetInstallation is a wrapper for the GitHub API to get an installation
func (ClientServiceImplementation) GetUserIdFromToken ¶ added in v0.0.39
func (ClientServiceImplementation) GetUserIdFromToken(ctx context.Context, token *oauth2.Token) (*int64, error)
GetUserIdFromToken is a wrapper for the GitHub API to get the user id from a token
func (ClientServiceImplementation) ListUserInstallations ¶ added in v0.0.39
func (ClientServiceImplementation) ListUserInstallations( ctx context.Context, token *oauth2.Token, ) ([]*github.Installation, error)
ListUserInstallations is a wrapper for the GitHub API to list user installations
type Delegate ¶ added in v0.0.36
type Delegate interface { GetCredential() provifv1.GitHubCredential ListAllRepositories(context.Context) ([]*minderv1.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) GetOwner() string IsOrg() bool }
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, packageListingClient *github.Client, cache ratecache.RestClientCache, delegate Delegate, ) *GitHub
NewGitHub creates a new GitHub client
func (*GitHub) AddAuthToPushOptions ¶ added in v0.0.36
AddAuthToPushOptions adds authorization to the push options
func (*GitHub) CanImplement ¶ added in v0.0.48
func (_ *GitHub) CanImplement(trait minderv1.ProviderType) bool
CanImplement returns true/false depending on whether the Provider can implement the specified trait
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) ClosePullRequest ¶ added in v0.0.39
func (c *GitHub) ClosePullRequest(ctx context.Context, owner, repo string, number int) (*github.PullRequest, error)
ClosePullRequest closes a pull request in a repository.
func (*GitHub) CloseSecurityAdvisory ¶ added in v0.0.35
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) EditHook ¶ added in v0.0.37
func (c *GitHub) EditHook(ctx context.Context, owner, repo string, id int64, hook *github.Hook) (*github.Hook, error)
EditHook edits an existing Hook.
func (*GitHub) GetBaseURL ¶ added in v0.0.35
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) GetNamespaceURL ¶ added in v0.0.49
GetNamespaceURL returns the URL for the repository
func (*GitHub) GetPackageByName ¶ added in v0.0.35
func (c *GitHub) GetPackageByName(ctx context.Context, 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, 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, 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, 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
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) ListAllRepositories ¶ added in v0.0.35
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) ListImages ¶ added in v0.0.49
ListImages lists all containers in the GitHub Container Registry
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) ListPackagesByRepository ¶ added in v0.0.35
func (c *GitHub) ListPackagesByRepository( ctx context.Context, 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) NewRequest ¶ added in v0.0.35
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
Directories
¶
Path | Synopsis |
---|---|
Package clients contains github client logic
|
Package clients contains github client logic |
mock
Package mock_clients is a generated GoMock package.
|
Package mock_clients is a generated GoMock package. |
Package common provides common utilities for the GitHub provider
|
Package common provides common utilities for the GitHub provider |
Package ghcr provides a client for interacting with the GitHub Container Registry
|
Package ghcr provides a client for interacting with the GitHub Container Registry |
Package installations contains logic relating to GitHub provider installations
|
Package installations contains logic relating to GitHub provider installations |
Package manager contains the GitHubProviderClassManager
|
Package manager contains the GitHubProviderClassManager |
Package mock_github is a generated GoMock package.
|
Package mock_github is a generated GoMock package. |
Package service contains the GitHubProviderService
|
Package service contains the GitHubProviderService |
mock
Package mock_service is a generated GoMock package.
|
Package mock_service is a generated GoMock package. |