github

package
v0.0.0-...-981f52d Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppsService

type AppsService interface {
	CreateInstallationToken(ctx context.Context, id int64, opts *ghapi.InstallationTokenOptions) (*ghapi.InstallationToken, *ghapi.Response, error)
}

AppsService defines the methods used in the github Apps service.

type CheckRunAdapter

type CheckRunAdapter struct {
	Owner          string
	Repository     string
	Name           string
	SHA            string
	ExternalID     string
	DetailsURL     string
	Conclusion     string
	Title          string
	Summary        string
	Text           string
	StartTime      time.Time
	CompletionTime time.Time
}

CheckRunAdapter is an abstraction for the github.CheckRun struct.

func (*CheckRunAdapter) GetStatus

func (s *CheckRunAdapter) GetStatus() string

GetStatus returns the appropriate status based on conclusion and start time.

type ChecksService

type ChecksService interface {
	CreateCheckRun(ctx context.Context, owner string, repo string, opts ghapi.CreateCheckRunOptions) (*ghapi.CheckRun, *ghapi.Response, error)
	ListCheckRunsForRef(ctx context.Context, owner string, repo string, ref string, opts *ghapi.ListCheckRunsOptions) (*ghapi.ListCheckRunsResults, *ghapi.Response, error)
	UpdateCheckRun(ctx context.Context, owner string, repo string, checkRunID int64, opts ghapi.UpdateCheckRunOptions) (*ghapi.CheckRun, *ghapi.Response, error)
}

ChecksService defines the methods used in the github Checks service.

type Client

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

Client is an abstraction around the API client.

func NewClient

func NewClient(logger logr.Logger, opts ...ClientOption) *Client

NewClient constructs a new Client.

func (*Client) CommitStatusExists

func (c *Client) CommitStatusExists(res []*ghapi.RepoStatus, commitStatus *CommitStatusAdapter) (bool, error)

CommitStatusExists returns if a match is found for the SHA, state, context and decription.

func (*Client) CreateAppInstallationToken

func (c *Client) CreateAppInstallationToken(ctx context.Context, appID int64, installationID int64, privateKey []byte) (string, error)

CreateAppInstallationToken creates an installation token for a GitHub App.

func (*Client) CreateCheckRun

func (c *Client) CreateCheckRun(ctx context.Context, cra *CheckRunAdapter) (*int64, error)

CreateCheckRun creates a new CheckRun via the GitHub API.

func (*Client) CreateComment

func (c *Client) CreateComment(ctx context.Context, owner string, repo string, issueNumber int, body string) (int64, error)

CreateComment creates a new issue comment via the GitHub API.

func (*Client) CreateCommitStatus

func (c *Client) CreateCommitStatus(ctx context.Context, owner string, repo string, SHA string, state string, description string, statusContext string, targetURL string) (int64, error)

CreateCommitStatus creates a repository commit status via the GitHub API.

func (*Client) EditComment

func (c *Client) EditComment(ctx context.Context, owner string, repo string, commentID int64, body string) (int64, error)

EditComment edits an existing issue comment via the GitHub API.

func (*Client) GetAllCheckRunsForRef

func (c *Client) GetAllCheckRunsForRef(ctx context.Context, owner string, repo string, SHA string, appID int64) ([]*ghapi.CheckRun, error)

GetAllCheckRunsForRef returns all existing GitHub CheckRuns if a match for the Owner, Repo, SHA, and appID.

func (*Client) GetAllCommentsForPR

func (c *Client) GetAllCommentsForPR(ctx context.Context, owner string, repo string, number int) ([]*ghapi.IssueComment, error)

GetAllCommentsForPR returns all existing comment if a match for the Owner, Repo, and PR.

func (*Client) GetAllCommitStatusesForRef

func (c *Client) GetAllCommitStatusesForRef(ctx context.Context, owner, repo, sha string) ([]*ghapi.RepoStatus, error)

GetAllCommitStatusesForRef returns all existing GitHub CommitStatuses if a match for the Owner, Repo, and SHA.

func (*Client) GetAppsService

func (c *Client) GetAppsService() AppsService

GetAppsService returns either the default or custom Apps service.

func (*Client) GetCheckRunID

func (c *Client) GetCheckRunID(ctx context.Context, owner string, repo string, SHA string, externalID string, appID int64) (*int64, error)

GetCheckRunID returns an existing GitHub CheckRun ID if a match is found for the SHA, externalID and appID.

func (*Client) GetChecksService

func (c *Client) GetChecksService() ChecksService

GetChecksService returns either the default or custom Checks service.

func (*Client) GetExistingCheckRun

func (c *Client) GetExistingCheckRun(checkRuns []*ghapi.CheckRun, newCheckRun *CheckRunAdapter) *ghapi.CheckRun

GetExistingCheckRun returns existing GitHub CheckRun for the ExternalID in checkRunAdapter.

func (*Client) GetExistingCommentID

func (c *Client) GetExistingCommentID(comments []*ghapi.IssueComment, snapshotName, scenarioName string) *int64

GetExistingComment returns existing GitHub comment for the scenario of ref.

func (*Client) GetIssuesService

func (c *Client) GetIssuesService() IssuesService

GetIssuesService returns either the default or custom Issues service.

func (*Client) GetRepositoriesService

func (c *Client) GetRepositoriesService() RepositoriesService

GetRepositoriesService returns either the default or custom Repositories service.

func (*Client) SetOAuthToken

func (c *Client) SetOAuthToken(ctx context.Context, token string)

SetOAuthToken configures the client with a GitHub OAuth token.

func (*Client) UpdateCheckRun

func (c *Client) UpdateCheckRun(ctx context.Context, checkRunID int64, cra *CheckRunAdapter) error

UpdateCheckRun updates an existing CheckRun via the GitHub API.

type ClientInterface

type ClientInterface interface {
	CreateAppInstallationToken(ctx context.Context, appID int64, installationID int64, privateKey []byte) (string, error)
	SetOAuthToken(ctx context.Context, token string)
	CreateCheckRun(ctx context.Context, cra *CheckRunAdapter) (*int64, error)
	UpdateCheckRun(ctx context.Context, checkRunID int64, cra *CheckRunAdapter) error
	GetCheckRunID(ctx context.Context, owner string, repo string, SHA string, externalID string, appID int64) (*int64, error)
	CreateComment(ctx context.Context, owner string, repo string, issueNumber int, body string) (int64, error)
	CreateCommitStatus(ctx context.Context, owner string, repo string, SHA string, state string, description string, statusContext string, targetURL string) (int64, error)
	GetAllCheckRunsForRef(ctx context.Context, owner string, repo string, SHA string, appID int64) ([]*ghapi.CheckRun, error)
	GetExistingCheckRun(checkRuns []*ghapi.CheckRun, newCheckRun *CheckRunAdapter) *ghapi.CheckRun
	GetAllCommitStatusesForRef(ctx context.Context, owner, repo, sha string) ([]*ghapi.RepoStatus, error)
	GetAllCommentsForPR(ctx context.Context, owner string, repo string, pr int) ([]*ghapi.IssueComment, error)
	CommitStatusExists(res []*ghapi.RepoStatus, commitStatus *CommitStatusAdapter) (bool, error)
	GetExistingCommentID(comments []*ghapi.IssueComment, snapshotName, scenarioName string) *int64
	EditComment(ctx context.Context, owner string, repo string, commentID int64, body string) (int64, error)
}

ClientInterface defines the methods that should be implemented by a GitHub client

type ClientOption

type ClientOption = func(c *Client)

ClientOption is used to extend Client with optional parameters.

func WithAppsService

func WithAppsService(svc AppsService) ClientOption

WithAppsService is an option which allows for overriding the github client's default Apps service.

func WithChecksService

func WithChecksService(svc ChecksService) ClientOption

WithChecksService is an option which allows for overriding the github client's default Checks service.

func WithIssuesService

func WithIssuesService(svc IssuesService) ClientOption

WithIssuesService is an option which allows for overriding the github client's default Issues service.

func WithRepositoriesService

func WithRepositoriesService(svc RepositoriesService) ClientOption

WithRepositoriesService is an option which allows for overriding the github client's default Issues service.

type CommitStatusAdapter

type CommitStatusAdapter struct {
	Owner       string
	Repository  string
	SHA         string
	State       string
	Description string
	Context     string
	TargetURL   string
}

CommitStatusAdapter is an abstraction for the github.CommiStatus struct.

type IssuesService

type IssuesService interface {
	CreateComment(ctx context.Context, owner string, repo string, number int, comment *ghapi.IssueComment) (*ghapi.IssueComment, *ghapi.Response, error)
	ListComments(ctx context.Context, owner string, repo string, number int, opts *ghapi.IssueListCommentsOptions) ([]*ghapi.IssueComment, *ghapi.Response, error)
	EditComment(ctx context.Context, owner string, repo string, id int64, comment *ghapi.IssueComment) (*ghapi.IssueComment, *ghapi.Response, error)
}

IssuesService defines the methods used in the github Issues service.

type RepositoriesService

type RepositoriesService interface {
	CreateStatus(ctx context.Context, owner string, repo string, ref string, status *ghapi.RepoStatus) (*ghapi.RepoStatus, *ghapi.Response, error)
	ListStatuses(ctx context.Context, owner, repo, ref string, opts *ghapi.ListOptions) ([]*ghapi.RepoStatus, *ghapi.Response, error)
}

RepositoriesService defines the methods used in the github Repositories service.

Jump to

Keyboard shortcuts

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