util

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 31 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// CommitStatusPendingDescription is the description used for PR commit status for pipelines we have just kicked off.
	CommitStatusPendingDescription = "Pipeline pending"

	// OverriddenByPrefix is the beginning of the description for commit statuses set by /override
	OverriddenByPrefix = "Overridden by"

	// GitHubAppGitRemoteUsername Username for git https URLs when using a GitHub App token.
	// see https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation
	GitHubAppGitRemoteUsername = "x-access-token"

	// GitHubAppSecretDirEnvVar is the name of the environment variable which would contain secrets when this is configured
	// with the GitHub App.
	GitHubAppSecretDirEnvVar = "GITHUB_APP_SECRET_DIR" // #nosec

	// GitHubAppAPIUserFilename is the filename inside the GitHub App secrets dir which will contain the user we will
	// use for GitHub API calls when present.
	GitHubAppAPIUserFilename = "username"

	// LighthousePipelineActivityNameLabel is added to the LighthouseJob with
	// the name of the PipelineActivity corresponding to it.
	LighthousePipelineActivityNameLabel = "lighthouse.jenkins-x.io/activityName"

	// LighthouseJobAnnotation is added in resources created by lighthouse and
	// carries the name of the job that the pod is running. Since
	// job names can be arbitrarily long, this is added as
	// an annotation instead of a label.
	LighthouseJobAnnotation = "lighthouse.jenkins-x.io/job"

	// OrgLabel is added in resources created by Lighthouse and
	// carries the org associated with the job, eg kubernetes-sigs.
	OrgLabel = "lighthouse.jenkins-x.io/refs.org"

	// RepoLabel is added in resources created by Lighthouse and
	// carries the repo associated with the job, eg test-infra
	RepoLabel = "lighthouse.jenkins-x.io/refs.repo"

	// PullLabel is added in resources created by Lighthouse and
	// carries the PR number associated with the job, eg 321.
	PullLabel = "lighthouse.jenkins-x.io/refs.pull"

	// ContextLabel is added in resources created by Lighthouse and contains the job context.
	ContextLabel = "lighthouse.jenkins-x.io/context"

	// BranchLabel is added in resources created by Lighthouse and contains the branch name for the job.
	BranchLabel = "lighthouse.jenkins-x.io/branch"

	// BuildNumLabel is added in resources created by Lighthouse and contains the build number for the job.
	BuildNumLabel = "lighthouse.jenkins-x.io/buildNum"

	// LastCommitSHALabel is added in resources created by Lighthouse and contains the SHA being built.
	LastCommitSHALabel = "lighthouse.jenkins-x.io/lastCommitSHA"

	// BaseSHALabel is added in resources created by Lighthouse and contains the base SHA (for PRs) to be merged against..
	BaseSHALabel = "lighthouse.jenkins-x.io/baseSHA"

	// CloneURIAnnotation is added in resources created by Lighthouse and contains the clone URI for the git repo.
	CloneURIAnnotation = "lighthouse.jenkins-x.io/cloneURI"

	// GithubServer the default github server URL
	GithubServer = "https://github.com"

	// ProwConfigMapName name of the ConfgMap holding the config
	ProwConfigMapName = "config"
	// ProwPluginsConfigMapName name of the ConfigMap holding the plugins config
	ProwPluginsConfigMapName = "plugins"
	// ProwConfigFilename config file name
	ProwConfigFilename = "config.yaml"
	// ProwPluginsFilename plugins file name
	ProwPluginsFilename = "plugins.yaml"

	// LighthouseCommandPrefix is an optional prefix for commands to deal with things like GitLab hijacking /approve
	LighthouseCommandPrefix = "lh-"

	// LighthouseUserAgent is the header value for User-Agent when Lighthouse calls external plugins
	LighthouseUserAgent = "LighthouseHook"

	// LighthouseWebhookKindHeader is the header key used for the webhook kind when relaying to external plugins
	LighthouseWebhookKindHeader = "X-Lighthouse-Webhook-Kind"

	// LighthouseSignatureHeader is the header key used for the signature when relaying to external plugins
	LighthouseSignatureHeader = "X-Lighthouse-Signature"

	// LighthousePayloadTypeHeader is the header key displaying what type of payload this is, either "webhook" or "activity"
	LighthousePayloadTypeHeader = "X-Lighthouse-Payload-Type"

	// LighthousePayloadTypeWebhook is the webhook type
	LighthousePayloadTypeWebhook = "webhook"

	// LighthousePayloadTypeActivity is the activity type
	LighthousePayloadTypeActivity = "activity"
)

Variables

This section is empty.

Functions

func AddAuthToSCMClient added in v0.0.492

func AddAuthToSCMClient(client *scm.Client, token string, isGitHubApp bool)

AddAuthToSCMClient configures an existing go-scm client with transport and authorization using the given token, depending on whether the token is a GitHub App token

func BlobURLForProvider added in v0.0.717

func BlobURLForProvider(providerType string, baseURL *url.URL, owner, repo, branch string, fullPath string) string

BlobURLForProvider gets the link to the blob for an individual file in a commit or branch

func CallExternalPluginsWithActivityRecord added in v0.0.650

func CallExternalPluginsWithActivityRecord(l *logrus.Entry, externalPlugins []plugins.ExternalPlugin, activity *v1alpha1.ActivityRecord, hmacToken string, wg *sync.WaitGroup)

CallExternalPluginsWithActivityRecord dispatches the provided activity record to the external plugins.

func CallExternalPluginsWithWebhook added in v0.0.650

func CallExternalPluginsWithWebhook(l *logrus.Entry, externalPlugins []plugins.ExternalPlugin, webhook scm.Webhook, hmacToken string, wg *sync.WaitGroup)

CallExternalPluginsWithWebhook dispatches the provided webhook to the external plugins.

func CreateHMACHeader added in v1.1.31

func CreateHMACHeader(data []byte, key string) string

CreateHMACHeader creates the hmac token

func DirExists added in v0.0.492

func DirExists(path string) (bool, error)

DirExists checks if path exists and is a directory

func ErrorToMarkdown added in v0.0.868

func ErrorToMarkdown(err error, fileLink string) string

ErrorToMarkdown converts an error to markdown text so we can include it on a Pull Request comment

func ExternalPluginsForEvent added in v0.0.650

func ExternalPluginsForEvent(pluginConfig *plugins.ConfigAgent, eventKind string, srcRepo string, disabledExternalPlugins []string) []plugins.ExternalPlugin

ExternalPluginsForEvent returns whether there are any external plugins that need to get the present event.

func FileExists added in v0.0.492

func FileExists(path string) (bool, error)

FileExists checks if path exists and is a file

func GetBotName added in v0.0.697

func GetBotName(cfg config.Getter) string

GetBotName returns the bot name from the environment

func GetGitHubAppAPIUser added in v0.0.492

func GetGitHubAppAPIUser() (string, error)

GetGitHubAppAPIUser returns the username to be used for GitHub API calls with the GitHub App, if so configured. If there is no configured secrets dir, it returns an empty string.

func GetGitHubAppSecretDir added in v0.0.492

func GetGitHubAppSecretDir() string

GetGitHubAppSecretDir returns the location of the GitHub App secrets dir, if defined, and an empty string otherwise

func GetGitServer added in v0.0.697

func GetGitServer(cfg config.Getter) string

GetGitServer returns the git server base URL from the environment

func GetSCMClient added in v0.0.697

func GetSCMClient(owner string, cfg config.Getter) (scmprovider.SCMClient, *scm.Client, string, string, error)

GetSCMClient gets the Lighthouse SCM client, go-scm client, server URL, and token for the current user and server

func GetSCMToken added in v0.0.697

func GetSCMToken(gitKind string) (string, error)

GetSCMToken gets the SCM secret from the environment

func GitKind added in v0.0.697

func GitKind(cfg config.Getter) string

GitKind gets the git kind from the environment

func HMACToken added in v0.0.697

func HMACToken() string

HMACToken gets the HMAC token from the environment or filesystem

func ParseExternalPluginEvent added in v0.0.650

func ParseExternalPluginEvent(req *http.Request, secretToken string) (scm.Webhook, *v1alpha1.ActivityRecord, error)

ParseExternalPluginEvent parses a webhook relayed to an external plugin

func Stopper added in v0.0.699

func Stopper() chan struct{}

Stopper returns a channel that remains open until an interrupt is received.

func StringArrayIndex added in v1.1.20

func StringArrayIndex(array []string, value string) int

StringArrayIndex returns the index in the slice which equals the given value

func ToValidName added in v0.0.525

func ToValidName(name string) string

ToValidName converts the given string into a valid Kubernetes resource name

func ToValidNameTruncated added in v0.0.525

func ToValidNameTruncated(name string, maxLength int) string

ToValidNameTruncated converts the given string into a valid Kubernetes resource name, truncating the result if it is more than maxLength characters.

func URLJoin added in v0.0.677

func URLJoin(paths ...string) string

URLJoin joins the given paths so that there is only ever one '/' character between the paths

Types

type OwnerTokensDir added in v0.0.492

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

OwnerTokensDir handles finding owner based tokens in a directory for GitHub Apps

func NewOwnerTokensDir added in v0.0.492

func NewOwnerTokensDir(gitServer, dir string) *OwnerTokensDir

NewOwnerTokensDir creates a new dir token scanner

func (*OwnerTokensDir) FindToken added in v0.0.492

func (o *OwnerTokensDir) FindToken(owner string) (string, error)

FindToken finds the token for the given owner

Jump to

Keyboard shortcuts

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