github

package
v0.0.0-...-b81d1be Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package github provides a Controller for GitHub operations and credentials management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyCommitOnBranchWithDefaultClient

func EmptyCommitOnBranchWithDefaultClient(ctx context.Context, req githubv4.CreateCommitOnBranchInput, opts ...GHOption) (string, error)

EmptyCommitOnBranchWithDefaultClient creates an empty commit on a branch using the default client.

Types

type CheckRunConclusion

type CheckRunConclusion string

CheckRunConclusion is a type to represent the check run conclusion.

const (
	// CheckRunConclusionSuccess represents a successful conclusion for a check run status, often used to indicate successful operations.
	CheckRunConclusionSuccess CheckRunConclusion = "success"
	// CheckRunConclusionFailure represents a failed conclusion for a check run status, typically used to indicate unsuccessful operations.
	CheckRunConclusionFailure CheckRunConclusion = "failure"
	// CheckRunConclusionNeutral represents a neutral conclusion for a check run status, used to indicate non-critical operations.
	CheckRunConclusionNeutral CheckRunConclusion = "neutral"
	// CheckRunConclusionCancelled represents a cancelled conclusion for a check run status, used to indicate aborted operations.
	CheckRunConclusionCancelled CheckRunConclusion = "cancelled"
	// CheckRunConclusionSkipped represents a skipped conclusion for a check run status, used to indicate skipped operations.
	CheckRunConclusionSkipped CheckRunConclusion = "skipped"
	// CheckRunConclusionTimedOut represents a timed-out conclusion for a check run status, used to indicate operations that exceeded the time limit.
	CheckRunConclusionTimedOut CheckRunConclusion = "timed_out"
	// CheckRunConclusionActionRequired represents an action-required conclusion for a check run status, used to indicate operations that require manual intervention.
	CheckRunConclusionActionRequired CheckRunConclusion = "action_required"
)

type CheckRunStatus

type CheckRunStatus string

CheckRunStatus is a type to represent the check run status.

const (
	// CheckRunStatusCompleted represents a completed state for a check run status, often used to indicate successful operations.
	CheckRunStatusCompleted CheckRunStatus = "completed"
	// CheckRunStatusInProgress represents an in-progress state for a check run status, typically used to indicate ongoing operations.
	CheckRunStatusInProgress CheckRunStatus = "in_progress"
	// CheckRunStatusQueued represents a queued state for a check run status, used to indicate pending operations.
	CheckRunStatusQueued CheckRunStatus = "queued"
)

type Client

type Client struct {
	V3 *github.Client
	V4 *githubv4.Client
	// contains filtered or unexported fields
}

Client - cache struct holding an entry for each installation ID.

type CommitOnBranchRequest

type CommitOnBranchRequest struct {
	Owner, Repository, Branch, Message string
}

CommitOnBranchRequest is a request to create a commit on a branch.

type CommitStatus

type CommitStatus string

CommitStatus is a type to represent the commit status.

const (
	// CommitStatusSuccess represents a successful state for a commit status, often used to indicate successful operations.
	CommitStatusSuccess CommitStatus = "success"
	// CommitStatusFailure represents a failed state for a commit status, typically used to indicate unsuccessful operations.
	CommitStatusFailure CommitStatus = "failure"
	// CommitStatusError represents an error state for a commit status, used to indicate critical issues in operations.
	CommitStatusError CommitStatus = "error"
	// CommitStatusPending represents a pending state for a commit status, typically used to indicate ongoing operations.
	CommitStatusPending CommitStatus = "pending"
)

type Controller

type Controller struct {
	Credentials
	// contains filtered or unexported fields
}

Controller encapsulates Controller-related operations and credentials management for various authentication modes.

func NewController

func NewController(opts ...GHOption) (*Controller, error)

NewController initializes a new Controller with the provided options, setting defaults where necessary.

func (*Controller) CreatePromotionTargetRef

func (g *Controller) CreatePromotionTargetRef(pCtx *promotion.Context) (*github.Reference, error)

CreatePromotionTargetRef creates a new ref in the repository.

func (*Controller) CreatePullRequest

func (g *Controller) CreatePullRequest(pCtx *promotion.Context) (*github.PullRequest, error)

CreatePullRequest creates a new pull request in the repository.

func (*Controller) EmptyCommitOnBranch

func (g *Controller) EmptyCommitOnBranch(ctx context.Context, clients *Client, createCommitOnBranchInput githubv4.CreateCommitOnBranchInput) (string, error)

EmptyCommitOnBranch creates an empty commit on a specific branch in a Controller repository using GraphQL mutation. It validates the current branch head and updates the expected head OID in the mutation input for consistency. Returns the OID of the newly created commit on success or an error on failure.

func (*Controller) FastForwardRefToSha

func (g *Controller) FastForwardRefToSha(pCtx *promotion.Context) error

FastForwardRefToSha pushes a commit to a ref, used to merge an open pull request via fast-forward.

func (*Controller) FindPullRequest

func (g *Controller) FindPullRequest(pCtx *promotion.Context) (*github.PullRequest, error)

FindPullRequest searches for an open pull request that matches the promotion request.

func (*Controller) GetGitHubClients

func (g *Controller) GetGitHubClients(body []byte) (*Client, error)

GetGitHubClients returns a Controller client for the given installation ID or token.

func (*Controller) GetPromotionSourceRootRef

func (g *Controller) GetPromotionSourceRootRef(pCtx *promotion.Context) (*string, error)

GetPromotionSourceRootRef fetches the root commit present on the head ref.

func (*Controller) ListPullRequestCommits

func (g *Controller) ListPullRequestCommits(pCtx *promotion.Context) ([]*github.RepositoryCommit, error)

ListPullRequestCommits fetches all commits present in the pull request.

func (*Controller) PromotionTargetRefExists

func (g *Controller) PromotionTargetRefExists(ctx *promotion.Context) bool

PromotionTargetRefExists checks if a ref exists in the repository.

func (*Controller) RequestTitle

func (g *Controller) RequestTitle(pCtx promotion.Context) *string

RequestTitle generates a title for a promotion request.

func (*Controller) RetrieveCredentials

func (g *Controller) RetrieveCredentials() error

RetrieveCredentials fetches the Controller credentials from the environment or SSM.

func (*Controller) SendPromotionFeedbackCheckRun

func (g *Controller) SendPromotionFeedbackCheckRun(bus *promotion.Bus, conclusion CheckRunConclusion) error

SendPromotionFeedbackCheckRun sends a check run to the head commit of the promotion request.

func (*Controller) SendPromotionFeedbackCommitStatus

func (g *Controller) SendPromotionFeedbackCommitStatus(bus *promotion.Bus, commitStatus CommitStatus) error

SendPromotionFeedbackCommitStatus sends a commit status to the head commit of the promotion request.

func (*Controller) ValidateWebhookSecret

func (g *Controller) ValidateWebhookSecret(secret []byte, headers map[string]string) error

ValidateWebhookSecret verifies the webhook secret against the signature in the provided headers for security validation.

type Credentials

type Credentials struct {
	AppID         int64                     `json:"app_id,omitempty"`
	PrivateKey    string                    `json:"private_key,omitempty"`
	WebhookSecret *validation.WebhookSecret `json:"webhook_secret"`
	Token         string                    `json:"token,omitempty"`
}

Credentials is a helper struct to hold the Controller credentials.

type EventInstallationID

type EventInstallationID struct {
	Installation struct {
		ID *int64 `json:"id"`
	} `json:"installation"`
}

EventInstallationID represents an event payload containing an installation ID. It embeds the installation details with its respective ID.

type GHOption

type GHOption func(*Controller)

GHOption is a functional option used to configure or modify the properties of a Controller instance.

func WithAWSController

func WithAWSController(aws *aws.Controller) GHOption

WithAWSController sets the awsController field of a Controller instance with the provided Controller instance.

func WithAuthMode

func WithAuthMode(mode string) GHOption

WithAuthMode sets the authentication mode for a Controller instance using the given mode string.

func WithLogger

func WithLogger(logger *slog.Logger) GHOption

WithLogger sets a custom logger for the Controller instance to use for logging operations.

func WithSSMKey

func WithSSMKey(key string) GHOption

WithSSMKey sets the SSM key used for fetching credentials and applies it to the Controller instance.

func WithToken

func WithToken(token string) GHOption

WithToken sets the Controller authentication token for the Controller instance.

func WithWebhookSecret

func WithWebhookSecret(secret *validation.WebhookSecret) GHOption

WithWebhookSecret configures a Controller instance to use the provided webhook secret for validating webhook signatures.

Directories

Path Synopsis
Package event provides a type for the event that triggered the webhook.
Package event provides a type for the event that triggered the webhook.
Package templates provides a set of standard functions that can be used in GitHub-related request templates.
Package templates provides a set of standard functions that can be used in GitHub-related request templates.

Jump to

Keyboard shortcuts

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