prinfo

package
v1.108.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EvidenceID is the identifier for the PR/MR info material type
	EvidenceID = "CHAINLOOP_PR_INFO"
	// EvidenceSchemaURL is the URL to the JSON schema for PR/MR info
	EvidenceSchemaURL = "https://schemas.chainloop.dev/prinfo/1.3/pr-info.schema.json"

	// AuthorTypeUser represents a human user account
	AuthorTypeUser = "User"
	// AuthorTypeBot represents a bot/service account
	AuthorTypeBot = "Bot"
	// AuthorTypeUnknown represents an account with unknown type
	AuthorTypeUnknown = "unknown"
)

Variables

View Source
var ErrInvalidJSONPayload = errors.New("invalid JSON payload")

ErrInvalidJSONPayload represents an error for an invalid JSON payload.

Functions

func Schema

func Schema(version Version) (string, error)

Schema returns the raw JSON schema document for the given version.

func SchemaURL

func SchemaURL(version Version) string

SchemaURL returns the canonical, published URL of the given schema version.

func Validate

func Validate(data any, version Version) error

Validate validates a generically-decoded PR/MR info data payload against the given schema version. An empty version defaults to LatestVersion.

Types

type Author

type Author struct {
	Login string `json:"login" jsonschema:"required,description=Username of the PR/MR author"`
	Type  string `json:"type" jsonschema:"required,enum=User,enum=Bot,enum=unknown,description=Account type of the PR/MR author"`
}

Author represents the author of the PR/MR with account type information

type Data

type Data struct {
	Platform     string     `json:"platform" jsonschema:"required,enum=github,enum=gitlab,description=The CI/CD platform"`
	Type         string     `json:"type" jsonschema:"required,enum=pull_request,enum=merge_request,description=The type of change request"`
	Number       string     `json:"number" jsonschema:"required,description=The PR/MR number or identifier"`
	Title        string     `json:"title" jsonschema:"description=The PR/MR title"`
	Description  string     `json:"description" jsonschema:"description=The PR/MR description or body"`
	SourceBranch string     `json:"source_branch" jsonschema:"description=The source branch name"`
	TargetBranch string     `json:"target_branch" jsonschema:"description=The target branch name"`
	URL          string     `json:"url" jsonschema:"required,format=uri,description=Direct URL to the PR/MR"`
	Author       *Author    `json:"author,omitempty" jsonschema:"description=The PR/MR author"`
	Reviewers    []Reviewer `json:"reviewers,omitempty" jsonschema:"description=List of reviewers who reviewed or were requested to review"`
}

Data represents the data payload of the PR/MR info evidence

func (*Data) UnmarshalJSON

func (d *Data) UnmarshalJSON(b []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Data to handle backwards compatibility where author can be either a string (v1.0-v1.2) or an object (v1.3+).

type Evidence

type Evidence struct {
	ID     string `json:"chainloop.material.evidence.id"`
	Schema string `json:"schema"`
	Data   Data   `json:"data"`
}

Evidence represents the complete evidence structure for PR/MR metadata

func NewEvidence

func NewEvidence(data Data) *Evidence

NewEvidence creates a new Evidence instance

type Generator

type Generator struct {
}

Generator handles the generation of JSON schemas for PR info.

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new schema generator

func (*Generator) GenerateSchema

func (g *Generator) GenerateSchema(version Version) *jsonschema.Schema

GenerateSchema generates a JSON schema for the PR/MR info data.

func (*Generator) Save

func (g *Generator) Save(schema *jsonschema.Schema, outputDir string, version Version) error

Save writes the schema to a file

type Reviewer

type Reviewer struct {
	Login        string `json:"login" jsonschema:"required,description=Username of the reviewer"`
	Type         string `json:"type" jsonschema:"required,enum=User,enum=Bot,enum=unknown,description=Account type of the reviewer"`
	Requested    bool   `json:"requested" jsonschema:"required,description=Whether the reviewer was explicitly requested to review"`
	ReviewStatus string `` /* 203-byte string literal not displayed */
}

Reviewer represents a reviewer of the PR/MR

type Version

type Version string

Version represents the version of the PR/MR info schema.

const (
	// Version1_0 represents PR/MR Info version 1.0 schema.
	Version1_0 Version = "1.0"
	// Version1_1 represents PR/MR Info version 1.1 schema (adds reviewers).
	Version1_1 Version = "1.1"
	// Version1_2 represents PR/MR Info version 1.2 schema (adds requested and review_status to reviewers).
	Version1_2 Version = "1.2"
	// Version1_3 represents PR/MR Info version 1.3 schema (author as object with type).
	Version1_3 Version = "1.3"

	// LatestVersion is the schema version emitted by this package.
	LatestVersion = Version1_3
)

func Versions

func Versions() []Version

Versions returns the supported schema versions, oldest first.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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