github

package
v0.0.0-...-2267940 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: Apache-2.0, MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoGitHubToken   = fmt.Errorf("no GitHub token found")
	ErrNoRepository    = fmt.Errorf("no repository information found")
	ErrInvalidPR       = fmt.Errorf("invalid pull request number")
	ErrReleaseNotFound = fmt.Errorf("release not found")
)
View Source
var (
	ErrNoEventFound = fmt.Errorf("no GitHub event data found")
	ErrTagNotFound  = fmt.Errorf("tag not found")
)

Functions

func InCI

func InCI() bool

InCI returns whether the code is running in a CI environment.

Types

type Branch

type Branch struct {
	Name      string
	CommitSHA string
	Protected bool
}

Branch represents a Git branch in the repository.

type DefaultGithubClient

type DefaultGithubClient struct {
	Owner    string
	RepoName string
	// contains filtered or unexported fields
}

DefaultGithubClient is the default implementation of the Github client.

func NewDefaultGithubClient

func NewDefaultGithubClient(owner, repoName string, opts ...DefaultGithubClientOption) (*DefaultGithubClient, error)

NewDefaultGithubClient creates a new DefaultGithubClient with a *github.Client and repository owner and name.

func (*DefaultGithubClient) CreateRelease

CreateRelease creates a new release.

func (*DefaultGithubClient) Env

func (g *DefaultGithubClient) Env() GithubEnv

Env returns the Github environment.

func (*DefaultGithubClient) GetReleaseByTag

func (g *DefaultGithubClient) GetReleaseByTag(tag string) (*github.RepositoryRelease, error)

GetReleaseByTag gets a release by tag.

func (*DefaultGithubClient) ListBranches

func (g *DefaultGithubClient) ListBranches() ([]Branch, error)

ListBranches lists all branches in the repository.

func (*DefaultGithubClient) ListPullRequestComments

func (g *DefaultGithubClient) ListPullRequestComments(prNumber int) ([]PullRequestComment, error)

ListPullRequestComments lists comments for a pull request.

func (*DefaultGithubClient) PostPullRequestComment

func (g *DefaultGithubClient) PostPullRequestComment(prNumber int, body string) error

PostPullRequestComment posts a comment to a pull request.

func (*DefaultGithubClient) UploadReleaseAsset

func (g *DefaultGithubClient) UploadReleaseAsset(releaseID int64, path string) error

UploadReleaseAsset uploads a release asset to the given release.

type DefaultGithubClientOption

type DefaultGithubClientOption func(*DefaultGithubClient)

func WithCreds

func WithCreds(creds *common.Secret) DefaultGithubClientOption

WithCreds sets the credentials for the Github client.

func WithCredsOrEnv

func WithCredsOrEnv(creds *common.Secret) DefaultGithubClientOption

WithCredsOrEnv sets the credentials for the Github client. If a GITHUB_TOKEN environment variable is set, it will use that token. Otherwise, it will use the given secret.

func WithFs

WithFs sets the filesystem for the Github client.

func WithGithubClient

func WithGithubClient(client *github.Client) DefaultGithubClientOption

WithGithubClient sets the native Github client for the Github client.

func WithGithubEnv

func WithGithubEnv(env GithubEnv) DefaultGithubClientOption

WithGithubEnv sets the Github environment for the Github client.

func WithLogger

func WithLogger(logger *slog.Logger) DefaultGithubClientOption

WithLogger sets the logger for the Github client.

func WithSecretStore

func WithSecretStore(ss *secrets.SecretStore) DefaultGithubClientOption

WithSecretStore sets the secret store for the Github client.

type DefaultGithubClientOptions

type DefaultGithubClientOptions struct {
	Creds *common.Secret
	Token string
}

type DefaultGithubEnv

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

DefaultGithubEnv provides the default implementation of the GithubEnv interface.

func (*DefaultGithubEnv) GetBranch

func (g *DefaultGithubEnv) GetBranch() string

GetBranch returns the current branch from the CI environment.

func (*DefaultGithubEnv) GetEventPayload

func (g *DefaultGithubEnv) GetEventPayload() (any, error)

GetEventPayload returns the GitHub event payload.

func (*DefaultGithubEnv) GetEventType

func (g *DefaultGithubEnv) GetEventType() string

GetEventType returns the GitHub event type.

func (*DefaultGithubEnv) GetPRNumber

func (g *DefaultGithubEnv) GetPRNumber() int

GetPRNumber returns the pull request number if the current environment is associated with a PR. Returns 0 if not in a PR context or if the PR number cannot be determined.

func (*DefaultGithubEnv) GetTag

func (g *DefaultGithubEnv) GetTag() string

GetTag returns the tag from the CI environment if it exists. If the tag is not found, an empty string is returned.

func (*DefaultGithubEnv) HasEvent

func (g *DefaultGithubEnv) HasEvent() bool

HasEvent returns whether a GitHub event payload exists.

func (*DefaultGithubEnv) IsPR

func (g *DefaultGithubEnv) IsPR() bool

IsPR returns whether the current environment is associated with a pull request.

type GithubClient

type GithubClient interface {
	CreateRelease(opts *github.RepositoryRelease) (*github.RepositoryRelease, error)
	Env() GithubEnv
	GetReleaseByTag(tag string) (*github.RepositoryRelease, error)
	ListPullRequestComments(prNumber int) ([]PullRequestComment, error)
	PostPullRequestComment(prNumber int, body string) error
	ListBranches() ([]Branch, error)
	UploadReleaseAsset(releaseID int64, path string) error
}

GithubClient is the interface for the Github client.

type GithubEnv

type GithubEnv interface {
	GetBranch() string
	GetEventPayload() (any, error)
	GetEventType() string
	GetPRNumber() int
	GetTag() string
	IsPR() bool
	HasEvent() bool
}

GithubEnv provides GitHub environment information.

type GithubProviderCreds

type GithubProviderCreds struct {
	Token string
}

GithubProviderCreds is the struct that holds the credentials for the Github provider

type PullRequestComment

type PullRequestComment struct {
	Author string
	Body   string
}

PullRequestComment is a comment on a pull request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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