Help us shape the future of Go! Take the 2026 Go Developer Survey

common

package
v0.0.0-...-73f62ca Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrForbidden    = errors.New("forbidden")
	ErrNotSupported = errors.New("not supported by this git provider")
)

Sentinel errors that git clients translate provider errors into, so observers can react without knowing the provider's error shape.

View Source
var AllAttestationTypes = []AttestationType{
	BuildProvenance,
	SourceProvenance,
	SARIF,
	SBOM,
	VEX,
}
View Source
var AttestationRegex = map[AttestationType][]*regexp.Regexp{
	SBOM: {
		regexp.MustCompile(`^https://cyclonedx\.org/bom(/v[\d\.]+)?$`),
		regexp.MustCompile(`^https://spdx\.dev/Document/v[\d\.]+$`),
	},
	VEX: {
		regexp.MustCompile(`^https://cyclonedx\.org/vex$`),
	},
	SARIF: {
		regexp.MustCompile(`^https://www\.schemastore\.org/schemas/json/sarif-[\d\.]+.json$`),
	},
	BuildProvenance: {
		regexp.MustCompile(`^https://slsa\.dev/provenance/v[\d\.]+$`),
		regexp.MustCompile(`^https://cosign\.sigstore\.dev/attestation/v[\d\.]+$`),
	},
	SourceProvenance: {
		regexp.MustCompile(`^https://gitlab\.opencode\.de/open-code/badgebackend/source-provenance-attestation-service/schema/source-provenance-report-v[\d]+$`),
		regexp.MustCompile(`^https://gitlab\.opencode\.de/open-code/badgebackend/source-provenance-attestation-service/-/raw/main/schema/source-provenance-schema-1\.\d+\.\d+\.json$`),
	},
}
View Source
var Version = GetEnvWithDefault[string]("BADGE_API_VERSION", "dev")

Version is the Badge API version. The container image bakes it in at build time (see the BADGE_API_VERSION build argument in the Dockerfile), so a deployed instance reports the tag it was built from. Anything running outside that image - a local `make run`, a test, a locally built image without the build argument - reports "dev".

Functions

func AllTrue

func AllTrue[K comparable](m map[K]bool) bool

func AppendStringToFile

func AppendStringToFile(filename, text string)

func Average

func Average(data []int) int

func CheckIfImageHasRequiredAttestations

func CheckIfImageHasRequiredAttestations(ctx context.Context, image name.Reference, cosignClient CosignAttestationClient, attestationTypes []AttestationType) (map[AttestationType]bool, error)

func Contains

func Contains[T comparable](s []T, e T) bool

func ExtractBaseURL

func ExtractBaseURL(u string) (string, error)

func Filter

func Filter[T any](s []T, f func(T) bool) []T

func Find

func Find[T any](s []T, f func(T) bool) *T

func Flatten

func Flatten[T any](s [][]T) []T

func FormatContributorsByValue

func FormatContributorsByValue(obfuscatedContributors map[string]int, unit string) string

func FormatStringBoolMap

func FormatStringBoolMap[K ~string](data map[K]bool) string

func GetBytesFromAPI

func GetBytesFromAPI(ctx context.Context, URL string, httpHeader map[string]string) ([]byte, error)

func GetEnvOrNil

func GetEnvOrNil(key string) *string

func GetEnvWithDefault

func GetEnvWithDefault[T string](key string, defaultValue string) string

func GetIndexOfLargestElement

func GetIndexOfLargestElement[T cmp.Ordered](s []T) int

func GetIndexOfSmallestElement

func GetIndexOfSmallestElement[T cmp.Ordered](s []T) int

func GetJSONFromAPI

func GetJSONFromAPI(ctx context.Context, target any, URL string) error

func GetOrDefault

func GetOrDefault[T any](val *T, deflt T) T

func GetOrDefaultStr

func GetOrDefaultStr(val *string, deflt string) string

func Index

func Index[T comparable](s []T, e T) int

func IsImageValidSemVer

func IsImageValidSemVer(image string) (name.Reference, *semver.Version, error)

func Map

func Map[T, U any](s []T, f func(T) U) []U

func Median

func Median(data []int) int

func ObfuscateEmail

func ObfuscateEmail(val string) string

func ObfuscateEmails

func ObfuscateEmails(mapping map[string]int) map[string]int

func ObfuscateString

func ObfuscateString(val string) string

Obfuscate string by replacing all chars in the middle with * while allowing special chars like dots and dashes (e.g. david.luhmer would be d***.*****r)

func Ptr

func Ptr[T any](v T) *T

func Reduce

func Reduce[T any, U any](s []T, f func(U, T) U, initial U) U

func SafeDeref

func SafeDeref(ptr *int) string

func TimeMidnight

func TimeMidnight(t time.Time) time.Time

func TimeMidnightOffsetDays

func TimeMidnightOffsetDays(t time.Time, days int) time.Time

func TimeMidnightOffsetMonth

func TimeMidnightOffsetMonth(month int) time.Time

today 0am X month ago

func TimeMidnightTomorrow

func TimeMidnightTomorrow() time.Time

tomorrow 0am

func ToDescriptionString

func ToDescriptionString[T Describer](elements []T) string

func Unique

func Unique[T comparable](s []T) []T

func UniqueBy

func UniqueBy[T any, U comparable](s []T, extractor func(el T) U) []T

func UserAgent

func UserAgent() string

UserAgent is the User-Agent every outgoing request identifies itself with, so GitLab and GitHub can tell which version of the Badge API is talking to them.

func WaitAll

func WaitAll[T any](tasks []func() (T, error)) ([]T, error)

Types

type AttestationType

type AttestationType string
const (
	SBOM             AttestationType = "sbom"
	VEX              AttestationType = "vex"
	SARIF            AttestationType = "sarif"
	BuildProvenance  AttestationType = "build-provenance"
	SourceProvenance AttestationType = "source-provenance"
)

type Branch

type Branch interface {
	GetName() string
	IsDefault() bool
	IsProtected() bool
}

func GetDefaultBranch

func GetDefaultBranch(branches []Branch) (Branch, error)

type CIPipeline

type CIPipeline interface {
	Describer
	GetCreatedAt() time.Time
	Successful() bool
}

type Commit

type Commit interface {
	Describer
	GetCreatedAt() time.Time
	GetAuthoredAt() time.Time
	GetSHA() string
	GetTitle() string
	GetAuthorName() string
	GetAuthorEmail() string
	GetCommitterName() string
	GetCommitterEmail() string
	GetWebURL() string
	GetStatsTotal() int64
}

type CommitRef

type CommitRef interface {
	Describer
	GetName() string
	GetType() string
}

type CommitVerificationStatus

type CommitVerificationStatus interface {
	Describer
	GetVerificationStatus() string
	MaybeGetSignature() *string
	MaybeGetSignaturePayload() *string
}

type ContainerRegistryTag

type ContainerRegistryTag interface {
	Describer
	GetTagName() string
	GetLocation() string
	GetRegistryRepositoryID() int64
}

type CosignAttestationClient

type CosignAttestationClient interface {
	GetAttestationsAnnotations(ctx context.Context, image name.Reference) ([]map[string]string, error)
}

type CosignAttestationClientImpl

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

func NewCosignAttestationClient

func NewCosignAttestationClient(opts ...cosignRemote.Option) *CosignAttestationClientImpl

func (*CosignAttestationClientImpl) GetAttestationsAnnotations

func (c *CosignAttestationClientImpl) GetAttestationsAnnotations(ctx context.Context, image name.Reference) ([]map[string]string, error)

type DateRangeListOptions

type DateRangeListOptions struct {
	CreatedAfter  *time.Time
	CreatedBefore *time.Time
}

type Describer

type Describer interface {
	Describe() string
}

type GetCommitOptions

type GetCommitOptions struct {
}

type GetProjectOptions

type GetProjectOptions struct {
	License bool
}

type Issue

type Issue interface {
	Describer
	GetID() int64
	GetCreatedAt() time.Time
	GetAuthorID() int64

	GetAssigneeIDs() []int64
	GetClosedByID() *int64
}

type IssueEvent

type IssueEvent interface {
	Describer

	GetAuthorID() int64
	GetCreatedAt() time.Time
	AuthorHasToBeProjectMember() bool
}

type IssueState

type IssueState string
const (
	IssueStateOpen   IssueState = "open"
	IssueStateClosed IssueState = "closed"
)

type KeyInt

type KeyInt struct {
	Key   string
	Value int
}

func StringIntMapToSortedKeyInt

func StringIntMapToSortedKeyInt(obfuscatedContributors map[string]int) []KeyInt

type ListCIPipelineRunsOptions

type ListCIPipelineRunsOptions struct {
	RunAfter  *time.Time
	RunBefore *time.Time
}

type ListCommitsOptions

type ListCommitsOptions struct {
	RefName       *string
	CreatedAfter  *time.Time
	CreatedBefore *time.Time
	Limit         *int
}

type ListMergeRequestsOptions

type ListMergeRequestsOptions struct {
	CreatedAfter  *time.Time
	CreatedBefore *time.Time
	State         *string
	TargetBranch  *string
}

type ListReleasesOptions

type ListReleasesOptions struct {
	ReleasedAfter  *time.Time
	ReleasedBefore *time.Time
}

type ListTagsOptions

type ListTagsOptions struct {
	TaggedAfter  *time.Time
	TaggedBefore *time.Time
}

type MergeRequest

type MergeRequest interface {
	Describer
	GetAssigneesIDs() []int64
	GetReviewersIDs() []int64
	GetAuthorID() int64
	GetMergeUserID() int64
	GetState() string
	GetIID() int64
	GetMergeCommitSHA() string
	GetSquashCommitSHA() string
	GetMergeRequestURL() string
	GetSourceBranch() string
}

type MergeRequestApprovals

type MergeRequestApprovals interface {
	Describer
	GetApprovedByIDs() []int64
}

type MergeRequestReviewers

type MergeRequestReviewers interface {
	GetReviewers() []ProjectMember
}

type Package

type Package interface {
	Describer
}

type Project

type Project interface {
	GetID() int64
	GetURL() string
	GetDescription() string
	GetLicenseKey() string
}

type ProjectMember

type ProjectMember interface {
	GetID() int64
	GetAccessLevel() int64
	GetName() string
}

type ProtectedBranch

type ProtectedBranch interface {
	GetName() string
	IsAllowForcePush() bool
	IsCodeOwnerApprovalRequired() bool
	GetMergeAccessMinLevel() int64
	GetPushAccessMinLevel() int64
}

type ProtectedTag

type ProtectedTag interface {
	GetName() string
	GetCreateAccessLevels() int64
}

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(limit int, gauge gauge) *RateLimiter

func (*RateLimiter) Done

func (r *RateLimiter) Done()

func (*RateLimiter) Wait

func (r *RateLimiter) Wait()

type Release

type Release interface {
	Describer
	GetReleasedAt() time.Time
	HasAssets() bool
	GetTagName() string
	GetCommitID() string
	GetCommit() Commit
	GetCommitPath() string
}

type RpsRateLimiter

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

RpsRateLimiter limits how many requests per second reach the origin server.

Every request has to take a token before it is sent, so the origin never sees more than maxRequestsPerSecond - not in the long run and not in a burst. A request the caching proxy answered itself never reached the origin though, so Refund puts its token straight back. Cache hits therefore cost nothing but the moment they are in flight, and the tokens keep circulating between them.

func NewRpsLimiter

func NewRpsLimiter(maxRequestsPerSecond int, gauge gauge) *RpsRateLimiter

Requests per second limiter

func (*RpsRateLimiter) Done

func (r *RpsRateLimiter) Done()

func (*RpsRateLimiter) Refund

func (r *RpsRateLimiter) Refund()

Refund returns a token that was not spent on the origin after all.

func (*RpsRateLimiter) Wait

func (r *RpsRateLimiter) Wait()

Wait blocks until a token is available and takes it.

type Tag

type Tag interface {
	Describer
	GetTagName() *string
	GetCommitAuthoredAt() time.Time
	GetReleaseTagName() *string
	GetReleaseDescription() *string
	GetReleaseOrAuthoredDate() *time.Time
}

type TagSignature

type TagSignature interface {
	Describer
	GetSignatureType() *string
}

type User

type User interface {
	Describer
	GetID() int64
	GetUsername() string
	GetEmail() string
	IsBot() bool
}

Source Files

  • concurrency.go
  • cosign.go
  • errors.go
  • file-io.go
  • http-api.go
  • oci_attestation.go
  • ratelimiter.go
  • slices.go
  • types.go
  • utils.go
  • version.go

Jump to

Keyboard shortcuts

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