gogithub

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 17 Imported by: 2

README

gogithub

A wrapper of a github wrapper

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGQLClientConfig = NewGQLClientConfig{
	Rt:             http.DefaultTransport,
	AppID:          intFromOsEnv("GITHUB_APP_ID"),
	InstallationID: intFromOsEnv("GITHUB_INSTALLATION_ID"),
	PEMKeyLoc:      os.Getenv("GITHUB_PEM_KEY_LOC"),
	PEMKey:         os.Getenv("GITHUB_PEM_KEY"),
	Token:          os.Getenv("GITHUB_TOKEN"),
}

Functions

func DebugLogTransport

func DebugLogTransport(base http.RoundTripper, logger *zap.Logger) http.RoundTripper

Types

type ExpireCache

type ExpireCache[K comparable, V any] struct {
	DefaultExpiry time.Duration
	// contains filtered or unexported fields
}

func (*ExpireCache[K, V]) Clear

func (e *ExpireCache[K, V]) Clear()

func (*ExpireCache[K, V]) Get

func (e *ExpireCache[K, V]) Get(key K) (V, bool)

func (*ExpireCache[K, V]) Set

func (e *ExpireCache[K, V]) Set(key K, value V)

type GitHub

type GitHub interface {
	// CreatePullRequest creates a PR of your current branch.  It assumes there is a remote branch with the
	// exact same name.  It will fail if you're already on master or main.
	CreatePullRequest(ctx context.Context, remoteRepositoryId graphql.ID, baseRefName string, remoteRefName string, title string, body string) (int64, error)
	// RepositoryInfo returns special information about a remote repository
	RepositoryInfo(ctx context.Context, owner string, name string) (*RepositoryInfo, error)
	// FindPRForBranch returns the PR for this branch
	FindPRForBranch(ctx context.Context, owner string, name string, branch string) (int64, error)
	// Self returns the current user
	Self(ctx context.Context) (string, error)
	// AcceptPullRequest approves a PR
	AcceptPullRequest(ctx context.Context, approvalmessage string, owner string, name string, number int64) error
	// MergePullRequest merges in a PR and closes it, but only if it's approved
	MergePullRequest(ctx context.Context, owner string, name string, number int64) error
	// EnablePullRequestAutoMerge enables auto-merge for the specified pull request
	EnablePullRequestAutoMerge(ctx context.Context, owner string, name string, number int64) error
	// FindPullRequest returns basic information for the specified pull request
	FindPullRequest(ctx context.Context, owner string, name string, number int64) (*PullRequest, error)
	// AddPRComment adds a comment to the specified pull request
	AddPRComment(ctx context.Context, owner string, name string, number int64, body string) error
	// FindPullRequestOid returns the OID of the PR
	FindPullRequestOid(ctx context.Context, owner string, name string, number int64) (githubv4.ID, error)
	GetAccessToken(ctx context.Context) (string, error)
	TriggerWorkflow(ctx context.Context, owner string, repo string, workflow_id string, ref string, inputs map[string]string) error
}

func NewGQLClient

func NewGQLClient(ctx context.Context, logger *zap.Logger, cfg *NewGQLClientConfig) (GitHub, error)

NewGQLClient generates a new GraphQL github client

type GithubGraphqlAPI

type GithubGraphqlAPI struct {
	ClientV4 *githubv4.Client
	Logger   *zap.Logger

	HttpClient *http.Client
	// contains filtered or unexported fields
}

func (*GithubGraphqlAPI) AcceptPullRequest

func (g *GithubGraphqlAPI) AcceptPullRequest(ctx context.Context, approvalmessage string, owner string, name string, number int64) error

func (*GithubGraphqlAPI) AddPRComment added in v0.1.4

func (g *GithubGraphqlAPI) AddPRComment(ctx context.Context, owner string, name string, number int64, body string) error

func (*GithubGraphqlAPI) CreatePullRequest

func (g *GithubGraphqlAPI) CreatePullRequest(ctx context.Context, remoteRepositoryId graphql.ID, baseRefName string, remoteRefName string, title string, body string) (int64, error)

func (*GithubGraphqlAPI) EnablePullRequestAutoMerge added in v0.1.4

func (g *GithubGraphqlAPI) EnablePullRequestAutoMerge(ctx context.Context, owner string, name string, number int64) error

func (*GithubGraphqlAPI) FindPRForBranch

func (g *GithubGraphqlAPI) FindPRForBranch(ctx context.Context, owner string, name string, branch string) (int64, error)

func (*GithubGraphqlAPI) FindPullRequest added in v0.1.4

func (g *GithubGraphqlAPI) FindPullRequest(ctx context.Context, owner string, name string, number int64) (*PullRequest, error)

func (*GithubGraphqlAPI) FindPullRequestOid

func (g *GithubGraphqlAPI) FindPullRequestOid(ctx context.Context, owner string, name string, number int64) (githubv4.ID, error)

func (*GithubGraphqlAPI) GetAccessToken

func (g *GithubGraphqlAPI) GetAccessToken(ctx context.Context) (string, error)

func (*GithubGraphqlAPI) MergePullRequest

func (g *GithubGraphqlAPI) MergePullRequest(ctx context.Context, owner string, name string, number int64) error

func (*GithubGraphqlAPI) RepositoryInfo

func (g *GithubGraphqlAPI) RepositoryInfo(ctx context.Context, owner string, name string) (*RepositoryInfo, error)

func (*GithubGraphqlAPI) Self

func (g *GithubGraphqlAPI) Self(ctx context.Context) (string, error)

func (*GithubGraphqlAPI) TriggerWorkflow added in v0.1.1

func (g *GithubGraphqlAPI) TriggerWorkflow(ctx context.Context, owner string, repo string, workflow_id string, ref string, inputs map[string]string) error

type GraphQLPRQueryNode

type GraphQLPRQueryNode struct {
	Number githubv4.Int
}

type NewGQLClientConfig

type NewGQLClientConfig struct {
	Rt             http.RoundTripper
	AppID          int64
	InstallationID int64
	PEMKeyLoc      string
	Token          string
	PEMKey         string
}

type PullRequest added in v0.1.4

type PullRequest struct {
	ID githubv4.ID
	// Number identifies the pull request number.
	Number int64
	// BaseRefName identifies the name of the base Ref associated with the pull request, even if the ref has been deleted.
	BaseRefName string
	// BaseRefOid identifies the oid of the base ref associated with the pull request, even if the ref has been deleted.
	BaseRefOid githubv4.ID
	// HeadRefName identifies the name of the head Ref associated with the pull request, even if the ref has been deleted.
	HeadRefName string
	// HeadRefOid identifies the oid of the head ref associated with the pull request, even if the ref has been deleted.
	HeadRefOid githubv4.ID
	// Body as Markdown.
	Body string
	// Closed is true if the pull request is closed.
	State PullRequestState
}

type PullRequestState added in v0.1.4

type PullRequestState string
const (
	PullRequstClosed PullRequestState = "CLOSED"
	PullRequstMerged PullRequestState = "MERGED"
	PullRequstOpen   PullRequestState = "OPEN"
)

type RepositoryInfo

type RepositoryInfo struct {
	Repository struct {
		ID               githubv4.ID
		DefaultBranchRef struct {
			Name githubv4.String
			ID   githubv4.ID
		}
	} `graphql:"repository(owner: $owner, name: $name)"`
}

type Zaptransport

type Zaptransport struct {
	Base   http.RoundTripper
	Logger *zap.Logger
}

func (*Zaptransport) RoundTrip

func (z *Zaptransport) RoundTrip(request *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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