githubapi

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApprovePr

func ApprovePr(approverClient *github.Client, ghPrClientDetails GhPrClientDetails, prNumber *int) error

func BumpVersion

func BumpVersion(ghPrClientDetails GhPrClientDetails, defaultBranch string, filePath string, newFileContent string, triggeringRepo string, triggeringRepoSHA string, triggeringActor string, autoMerge bool) error

func CompareRepoDirectories

func CompareRepoDirectories(ghPrClientDetails GhPrClientDetails, sourcePath string, targetPath string, defaultBranch string) (bool, string, error)

func DetectDrift

func DetectDrift(ghPrClientDetails GhPrClientDetails) error

func DoesPrHasLabel

func DoesPrHasLabel(labels []*github.Label, name string) bool

func GeneratePromotionPlan

func GeneratePromotionPlan(ghPrClientDetails GhPrClientDetails, config *cfg.Config, configBranch string) (map[string]PromotionInstance, error)

func GenerateSyncTreeEntriesForCommit

func GenerateSyncTreeEntriesForCommit(treeEntries *[]*github.TreeEntry, ghPrClientDetails GhPrClientDetails, sourcePath string, targetPath string, defaultBranch string) error

func GetBotGhIdentity

func GetBotGhIdentity(githubGraphQlClient *githubv4.Client, ctx context.Context) (string, error)

go-github is my peffered way to interact with GitHub because of the better developer expirience(pre made types, easy API mocking). But some functionality is not availalble in GH V3 rest API, like PR comment minimization, so here we are:

func GetFileContent

func GetFileContent(ghPrClientDetails GhPrClientDetails, branch string, filePath string) (string, int, error)

func GetInRepoConfig

func GetInRepoConfig(ghPrClientDetails GhPrClientDetails, defaultBranch string) (*cfg.Config, error)

func HandlePREvent

func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPrClientDetails, mainGithubClientPair GhClientPair, approverGithubClientPair GhClientPair, ctx context.Context)

func MainGhMetricsLoop

func MainGhMetricsLoop(mainGhClientCache *lru.Cache[string, GhClientPair])

func MergePr

func MergePr(details GhPrClientDetails, number int) error

func MimizeStalePrComments

func MimizeStalePrComments(ghPrClientDetails GhPrClientDetails, githubGraphQlClient *githubv4.Client, botIdentity string) error

func ReciveEventFile

func ReciveEventFile(eventType string, eventFilePath string, mainGhClientCache *lru.Cache[string, GhClientPair], prApproverGhClientCache *lru.Cache[string, GhClientPair])

ReciveEventFile this one is similar to ReciveWebhook but it's used for CLI triggering, i simulates a webhook event to use the same code path as the webhook handler.

func ReciveWebhook

func ReciveWebhook(r *http.Request, mainGhClientCache *lru.Cache[string, GhClientPair], prApproverGhClientCache *lru.Cache[string, GhClientPair], githubWebhookSecret []byte) error

ReciveWebhook is the main entry point for the webhook handling it starts parases the webhook payload and start a thread to handle the event success/failure are dependant on the payload parsing only

func SetCommitStatus

func SetCommitStatus(ghPrClientDetails GhPrClientDetails, state string)

Types

type DiffCommentData

type DiffCommentData struct {
	DiffOfChangedComponents   []argocd.DiffResult
	DisplaySyncBranchCheckBox bool
	BranchName                string
}

type GhClientPair

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

func (*GhClientPair) GetAndCache

func (gcp *GhClientPair) GetAndCache(ghClientCache *lru.Cache[string, GhClientPair], ghAppIdEnvVarName string, ghAppPKeyPathEnvVarName string, ghOauthTokenEnvVarName string, repoOwner string, ctx context.Context)

type GhPrClientDetails

type GhPrClientDetails struct {
	GhClientPair *GhClientPair
	// This whole struct describe the metadata of the PR, so it makes sense to share the context with everything to generate HTTP calls related to that PR, right?
	Ctx           context.Context //nolint:containedctx
	DefaultBranch string
	Owner         string
	Repo          string
	PrAuthor      string
	PrNumber      int
	PrSHA         string
	Ref           string
	RepoURL       string
	PrLogger      *log.Entry
	Labels        []*github.Label
	PrMetadata    prMetadata
}

func (GhPrClientDetails) CommentOnPr

func (p GhPrClientDetails) CommentOnPr(commentBody string) error

func (*GhPrClientDetails) GetDefaultBranch

func (p *GhPrClientDetails) GetDefaultBranch() (string, error)

func (*GhPrClientDetails) ToggleCommitStatus

func (p *GhPrClientDetails) ToggleCommitStatus(context string, user string) error

type PromotionInstance

type PromotionInstance struct {
	Metadata          PromotionInstanceMetaData `deep:"-"` // Unit tests ignore Metadata currently
	ComputedSyncPaths map[string]string         // key is target, value is source
}

type PromotionInstanceMetaData

type PromotionInstanceMetaData struct {
	SourcePath                     string
	TargetPaths                    []string
	TargetDescription              string
	PerComponentSkippedTargetPaths map[string][]string // ComponentName is the key,
	ComponentNames                 []string
	AutoMerge                      bool
}

Jump to

Keyboard shortcuts

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