Documentation
¶
Overview ¶
Package codegen provides code generation tooling for GitLab CI/CD types.
Index ¶
- Constants
- Variables
- func FieldNameFromInput(s string) string
- func ToPascalCase(s string) string
- func ToSnakeCase(s string) string
- type CISchemaIR
- type ComponentIR
- type ComponentInput
- type DefinitionIR
- type FetchResult
- type Fetcher
- func (f *Fetcher) Fetch(url string) ([]byte, error)
- func (f *Fetcher) FetchAll() (*Manifest, error)
- func (f *Fetcher) FetchCISchema() (*FetchResult, error)
- func (f *Fetcher) FetchComponent(name string) (*FetchResult, error)
- func (f *Fetcher) ReadManifest() (*Manifest, error)
- func (f *Fetcher) WriteManifest(m *Manifest) error
- type GenerateResult
- type Generator
- type JSONSchema
- type Manifest
- type Parser
- type PropertyIR
Constants ¶
const ( // GitLabCISchemaURL is the URL to the GitLab CI JSON schema. GitLabCISchemaURL = "https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json" // ComponentBaseURL is the base URL for GitLab CI/CD components. ComponentBaseURL = "https://gitlab.com/components" )
Schema source URLs
Variables ¶
var DefaultComponents = []string{
"sast",
"secret-detection",
"dependency-scanning",
"container-scanning",
"dast",
"license-scanning",
"coverage-report",
}
DefaultComponents is the list of official GitLab CI/CD components.
Functions ¶
func FieldNameFromInput ¶
FieldNameFromInput converts an input name to a Go field name. Examples: "stage" -> "Stage", "scan_type" -> "ScanType", "SAST_EXCLUDED_PATHS" -> "SastExcludedPaths"
func ToPascalCase ¶
ToPascalCase converts a string to PascalCase. Examples: "sast" -> "Sast", "secret-detection" -> "SecretDetection"
func ToSnakeCase ¶
ToSnakeCase converts a string to snake_case. Examples: "SecretDetection" -> "secret_detection", "secret-detection" -> "secret_detection"
Types ¶
type CISchemaIR ¶
type CISchemaIR struct {
// TopLevel contains top-level keywords like stages, include, variables
TopLevel map[string]PropertyIR `json:"top_level"`
// JobProperties contains properties available in job definitions
JobProperties map[string]PropertyIR `json:"job_properties"`
// Definitions contains reusable schema definitions
Definitions map[string]DefinitionIR `json:"definitions"`
}
CISchemaIR is the intermediate representation of the parsed CI schema.
type ComponentIR ¶
type ComponentIR struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Inputs []ComponentInput `json:"inputs,omitempty"`
Outputs []string `json:"outputs,omitempty"`
}
ComponentIR is the intermediate representation of a component specification.
type ComponentInput ¶
type ComponentInput struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Default any `json:"default,omitempty"`
Required bool `json:"required,omitempty"`
}
ComponentInput represents an input parameter for a component.
type DefinitionIR ¶
type DefinitionIR struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
Properties []PropertyIR `json:"properties,omitempty"`
Enum []string `json:"enum,omitempty"`
}
DefinitionIR is the intermediate representation of a schema definition.
type FetchResult ¶
type FetchResult struct {
URL string `json:"url"`
Path string `json:"path"`
Size int64 `json:"size"`
Duration string `json:"duration"`
Error string `json:"error,omitempty"`
}
FetchResult represents the result of a fetch operation.
type Fetcher ¶
Fetcher handles downloading schemas and specs from remote sources.
func NewFetcher ¶
NewFetcher creates a new Fetcher with default settings.
func (*Fetcher) FetchCISchema ¶
func (f *Fetcher) FetchCISchema() (*FetchResult, error)
FetchCISchema downloads the GitLab CI JSON schema.
func (*Fetcher) FetchComponent ¶
func (f *Fetcher) FetchComponent(name string) (*FetchResult, error)
FetchComponent downloads a component specification.
func (*Fetcher) ReadManifest ¶
ReadManifest reads the manifest from specs/manifest.json.
func (*Fetcher) WriteManifest ¶
WriteManifest writes the manifest to specs/manifest.json.
type GenerateResult ¶
GenerateResult represents the result of a code generation operation.
type Generator ¶
type Generator struct {
OutputDir string
}
Generator generates Go code from parsed schemas and component specs.
func NewGenerator ¶
NewGenerator creates a new Generator.
func (*Generator) GenerateAll ¶
func (g *Generator) GenerateAll(components map[string]*ComponentIR) (map[string]*GenerateResult, error)
GenerateAll generates Go files for all components.
func (*Generator) GenerateComponentCode ¶
func (g *Generator) GenerateComponentCode(ir *ComponentIR) (string, error)
GenerateComponentCode generates Go code for a component.
func (*Generator) GenerateComponentFile ¶
func (g *Generator) GenerateComponentFile(ir *ComponentIR) error
GenerateComponentFile generates a Go file for a component.
type JSONSchema ¶
type JSONSchema struct {
Schema string `json:"$schema,omitempty"`
ID string `json:"$id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Type any `json:"type,omitempty"`
Properties map[string]JSONSchema `json:"properties,omitempty"`
Items *JSONSchema `json:"items,omitempty"`
Ref string `json:"$ref,omitempty"`
OneOf []JSONSchema `json:"oneOf,omitempty"`
AnyOf []JSONSchema `json:"anyOf,omitempty"`
AllOf []JSONSchema `json:"allOf,omitempty"`
Enum []any `json:"enum,omitempty"`
Const any `json:"const,omitempty"`
Default any `json:"default,omitempty"`
Required []string `json:"required,omitempty"`
Defs map[string]JSONSchema `json:"$defs,omitempty"`
Definitions map[string]JSONSchema `json:"definitions,omitempty"`
Pattern string `json:"pattern,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
MinItems *int `json:"minItems,omitempty"`
MaxItems *int `json:"maxItems,omitempty"`
Format string `json:"format,omitempty"`
}
JSONSchema represents a JSON Schema document.
type Manifest ¶
type Manifest struct {
FetchedAt time.Time `json:"fetched_at"`
CISchema *FetchResult `json:"ci_schema,omitempty"`
Components map[string]FetchResult `json:"components,omitempty"`
}
Manifest tracks fetched schemas and their metadata.
type Parser ¶
type Parser struct {
SpecsDir string
}
Parser parses GitLab CI schemas and component specs.
func (*Parser) ParseAllComponents ¶
func (p *Parser) ParseAllComponents() (map[string]*ComponentIR, error)
ParseAllComponents parses all component specifications.
func (*Parser) ParseCISchema ¶
func (p *Parser) ParseCISchema() (*CISchemaIR, error)
ParseCISchema parses the GitLab CI JSON schema.
func (*Parser) ParseComponent ¶
func (p *Parser) ParseComponent(name string) (*ComponentIR, error)
ParseComponent parses a component specification from YAML.
type PropertyIR ¶
type PropertyIR struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type"`
Required bool `json:"required,omitempty"`
Enum []string `json:"enum,omitempty"`
Default any `json:"default,omitempty"`
Items *PropertyIR `json:"items,omitempty"`
Properties []PropertyIR `json:"properties,omitempty"`
RefName string `json:"ref_name,omitempty"`
}
PropertyIR is the intermediate representation of a schema property.