github

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRunPassed

func CheckRunPassed(checkRun CheckRun) bool

func CheckSuitePassed

func CheckSuitePassed(checkSuite CheckSuite) bool

func ExpectedCheckPassed

func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun, statusContexts []StatusContext, vcsstatusname string) bool

func GetVCSStatusNameFromRequiredCheck

func GetVCSStatusNameFromRequiredCheck(requiredCheck githubv4.String) string

func StatusContextPassed

func StatusContextPassed(statusContext StatusContext, vcsstatusname string) bool

Types

type AnonymousCredentials

type AnonymousCredentials struct{}

GithubAnonymousCredentials expose no credentials.

func (*AnonymousCredentials) Client

func (c *AnonymousCredentials) Client() (*http.Client, error)

Client returns a client with no credentials.

func (*AnonymousCredentials) GetToken

func (c *AnonymousCredentials) GetToken() (string, error)

GetToken returns an empty token.

func (*AnonymousCredentials) GetUser

func (c *AnonymousCredentials) GetUser() (string, error)

GetUser returns the username for these credentials.

type AppCredentials

type AppCredentials struct {
	AppID    int64
	Key      []byte
	Hostname string

	InstallationID int64

	AppSlug string
	// contains filtered or unexported fields
}

GithubAppCredentials implements GithubCredentials for github app installation token flow.

func (*AppCredentials) Client

func (c *AppCredentials) Client() (*http.Client, error)

Client returns a github app installation client.

func (*AppCredentials) GetToken

func (c *AppCredentials) GetToken() (string, error)

GetToken returns a fresh installation token.

func (*AppCredentials) GetUser

func (c *AppCredentials) GetUser() (string, error)

GetUser returns the username for these credentials.

type CheckRun

type CheckRun struct {
	Name       githubv4.String
	Conclusion githubv4.String
	// Not currently used: GitHub API classifies as required if coming from ruleset, even when the ruleset is not enforced!
	IsRequired githubv4.Boolean `graphql:"isRequired(pullRequestNumber: $number)"`
	CheckSuite CheckSuite
}

func (CheckRun) Copy

func (original CheckRun) Copy() CheckRun

type CheckSuite

type CheckSuite struct {
	Conclusion  githubv4.String
	WorkflowRun *WorkflowRun
}

func (CheckSuite) Copy

func (original CheckSuite) Copy() CheckSuite

type Client

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

Client is used to perform GitHub actions.

func New

func New(hostname string, credentials Credentials, config Config, maxCommentsPerCommand int, logger logging.SimpleLogging) (*Client, error)

func (*Client) CreateComment

func (g *Client) CreateComment(logger logging.SimpleLogging, repo models.Repo, pullNum int, comment string, command string) error

CreateComment creates a comment on the pull request. If comment length is greater than the max comment length we split into multiple comments.

func (*Client) DiscardReviews

func (g *Client) DiscardReviews(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) error

DiscardReviews dismisses all reviews on a pull request

func (*Client) ExchangeCode

func (g *Client) ExchangeCode(logger logging.SimpleLogging, code string) (*GithubAppTemporarySecrets, error)

ExchangeCode returns a newly created app's info

func (*Client) ExpectedWorkflowPassed

func (g *Client) ExpectedWorkflowPassed(expectedWorkflow WorkflowFileReference, checkRuns []CheckRun) (bool, error)

func (*Client) GetCloneURL

func (g *Client) GetCloneURL(logger logging.SimpleLogging, _ models.VCSHostType, repo string) (string, error)

func (*Client) GetFileContent

func (g *Client) GetFileContent(logger logging.SimpleLogging, repo models.Repo, branch string, fileName string) (bool, []byte, error)

GetFileContent a repository file content from VCS (which support fetch a single file from repository) The first return value indicates whether the repo contains a file or not if BaseRepo had a file, its content will placed on the second return value

func (*Client) GetModifiedFiles

func (g *Client) GetModifiedFiles(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error)

GetModifiedFiles returns the names of files that were modified in the pull request relative to the repo root, e.g. parent/child/file.txt.

func (*Client) GetPullLabels

func (g *Client) GetPullLabels(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) ([]string, error)

func (*Client) GetPullRequest

func (g *Client) GetPullRequest(logger logging.SimpleLogging, repo models.Repo, num int) (*github.PullRequest, error)

GetPullRequest returns the pull request.

func (*Client) GetPullRequestMergeabilityInfo

func (g *Client) GetPullRequestMergeabilityInfo(
	repo models.Repo,
	pull *github.PullRequest,
) (
	reviewDecision githubv4.String,
	requiredChecks []githubv4.String,
	requiredWorkflows []WorkflowFileReference,
	checkRuns []CheckRun,
	statusContexts []StatusContext,
	err error,
)

func (*Client) GetTeamNamesForUser

func (g *Client) GetTeamNamesForUser(logger logging.SimpleLogging, repo models.Repo, user models.User) ([]string, error)

GetTeamNamesForUser returns the names of the teams or groups that the user belongs to (in the organization the repository belongs to). https://docs.github.com/en/graphql/reference/objects#organization

func (*Client) HidePrevCommandComments

func (g *Client) HidePrevCommandComments(logger logging.SimpleLogging, repo models.Repo, pullNum int, command string, dir string) error

func (*Client) IsMergeableMinusApply

func (g *Client) IsMergeableMinusApply(logger logging.SimpleLogging, repo models.Repo, pull *github.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (bool, error)

IsMergeableMinusApply checks review decision (which takes into account CODEOWNERS) and required checks for PR (excluding the atlantis apply check).

func (*Client) LookupRepoId

func (g *Client) LookupRepoId(repo githubv4.String) (githubv4.Int, error)
func (g *Client) MarkdownPullLink(pull models.PullRequest) (string, error)

MarkdownPullLink specifies the string used in a pull request comment to reference another pull request.

func (*Client) MergePull

func (g *Client) MergePull(logger logging.SimpleLogging, pull models.PullRequest, pullOptions models.PullRequestOptions) error

MergePull merges the pull request.

func (*Client) PullIsApproved

func (g *Client) PullIsApproved(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest) (approvalStatus models.ApprovalStatus, err error)

PullIsApproved returns true if the pull request was approved.

func (*Client) PullIsMergeable

func (g *Client) PullIsMergeable(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, vcsstatusname string, ignoreVCSStatusNames []string) (models.MergeableStatus, error)

PullIsMergeable returns true if the pull request is mergeable.

func (*Client) ReactToComment

func (g *Client) ReactToComment(logger logging.SimpleLogging, repo models.Repo, _ int, commentID int64, reaction string) error

ReactToComment adds a reaction to a comment.

func (*Client) SupportsSingleFileDownload

func (g *Client) SupportsSingleFileDownload(_ models.Repo) bool

func (*Client) UpdateStatus

func (g *Client) UpdateStatus(logger logging.SimpleLogging, repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error

UpdateStatus updates the status badge on the pull request. See https://github.com/blog/1227-commit-status-api.

func (*Client) WorkflowRunMatchesWorkflowFileReference

func (g *Client) WorkflowRunMatchesWorkflowFileReference(workflowRunFile WorkflowRunFile, workflowFileReference WorkflowFileReference) (bool, error)

type Config

type Config struct {
	AllowMergeableBypassApply bool
}

GithubConfig allows for custom github-specific functionality and behavior

type Credentials

type Credentials interface {
	Client() (*http.Client, error)
	GetToken() (string, error)
	GetUser() (string, error)
}

GithubCredentials handles creating http.Clients that authenticate.

type GitHubRepoIdCache

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

func NewGitHubRepoIdCache

func NewGitHubRepoIdCache() GitHubRepoIdCache

func (*GitHubRepoIdCache) Get

func (*GitHubRepoIdCache) Set

func (c *GitHubRepoIdCache) Set(key githubv4.String, value githubv4.Int)

type GithubAppTemporarySecrets

type GithubAppTemporarySecrets struct {
	// ID is the app id.
	ID int64
	// Key is the app's PEM-encoded key.
	Key string
	// Name is the app name.
	Name string
	// WebhookSecret is the generated webhook secret for this app.
	WebhookSecret string
	// URL is a link to the app, like https://github.com/apps/octoapp.
	URL string
}

GithubAppTemporarySecrets holds app credentials obtained from github after creation.

type GithubPRReviewSummary

type GithubPRReviewSummary struct {
	ReviewDecision githubv4.String
	Reviews        []GithubReview
}

type GithubPullRequestGetter

type GithubPullRequestGetter interface {
	GetPullRequest(logger logging.SimpleLogging, repo models.Repo, pullNum int) (*github.PullRequest, error)
}

type GithubRepoIdCacheEntry

type GithubRepoIdCacheEntry struct {
	RepoId     githubv4.Int
	LookupTime time.Time
}

type GithubReview

type GithubReview struct {
	ID          githubv4.ID
	SubmittedAt githubv4.DateTime
	Author      struct {
		Login githubv4.String
	}
}

type IGithubClient

type IGithubClient interface {
	vcs.Client
	GithubPullRequestGetter
}

IGithubClient exists to bridge the gap between GithubPullRequestGetter and Client interface to allow for a single instrumented client

func NewInstrumentedGithubClient

func NewInstrumentedGithubClient(client *Client, statsScope tally.Scope, logger logging.SimpleLogging) IGithubClient

NewInstrumentedGithubClient creates a client proxy responsible for gathering stats and logging

type InstrumentedGithubClient

type InstrumentedGithubClient struct {
	*common.InstrumentedClient
	PullRequestGetter GithubPullRequestGetter
	StatsScope        tally.Scope
	Logger            logging.SimpleLogging
}

InstrumentedGithubClient should delegate to the underlying InstrumentedClient for vcs provider-agnostic methods and implement solely any github specific interfaces.

func (*InstrumentedGithubClient) GetPullRequest

func (c *InstrumentedGithubClient) GetPullRequest(logger logging.SimpleLogging, repo models.Repo, pullNum int) (*github.PullRequest, error)

type PageInfo

type PageInfo struct {
	EndCursor   *githubv4.String
	HasNextPage githubv4.Boolean
}

type StatusContext

type StatusContext struct {
	Context githubv4.String
	State   githubv4.String
	// Not currently used: GitHub API classifies as required if coming from ruleset, even when the ruleset is not enforced!
	IsRequired githubv4.Boolean `graphql:"isRequired(pullRequestNumber: $number)"`
}

type TokenRotator

type TokenRotator interface {
	Run()
	GenerateJob() (scheduled.JobDefinition, error)
}

GithubTokenRotator continuously tries to rotate the github app access token every 30 seconds and writes the ~/.git-credentials file

func NewTokenRotator

func NewTokenRotator(
	log logging.SimpleLogging,
	githubCredentials Credentials,
	githubHostname string,
	gitUser string,
	homeDirPath string) TokenRotator

type UserCredentials

type UserCredentials struct {
	User      string
	Token     string
	TokenFile string
}

GithubUserCredentials implements GithubCredentials for the personal auth token flow.

func (*UserCredentials) Client

func (c *UserCredentials) Client() (*http.Client, error)

Client returns a client for basic auth user credentials.

func (*UserCredentials) GetToken

func (c *UserCredentials) GetToken() (string, error)

GetToken returns the user token.

func (*UserCredentials) GetUser

func (c *UserCredentials) GetUser() (string, error)

GetUser returns the username for these credentials.

type UserTransport

type UserTransport struct {
	Credentials *UserCredentials
	Transport   *github.BasicAuthTransport
}

func (*UserTransport) RoundTrip

func (t *UserTransport) RoundTrip(req *http.Request) (*http.Response, error)

type WorkflowFileReference

type WorkflowFileReference struct {
	Path         githubv4.String
	RepositoryId githubv4.Int
	Sha          *githubv4.String
}

func (WorkflowFileReference) Copy

type WorkflowRun

type WorkflowRun struct {
	File      *WorkflowRunFile
	RunNumber githubv4.Int
}

func (WorkflowRun) Copy

func (original WorkflowRun) Copy() WorkflowRun

type WorkflowRunFile

type WorkflowRunFile struct {
	Path              githubv4.String
	RepositoryFileUrl githubv4.String
	RepositoryName    githubv4.String
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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