importer

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package importer provides YAML parsing for converting existing .gitlab-ci.yml files to an intermediate representation for Go code generation.

Package importer provides YAML parsing for converting existing .gitlab-ci.yml files to an intermediate representation for Go code generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatReport

func FormatReport(report *DiagnosticReport) string

FormatReport formats a diagnostic report for display.

Types

type Analyzer

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

Analyzer analyzes an IRPipeline and produces diagnostics.

func NewAnalyzer

func NewAnalyzer() *Analyzer

NewAnalyzer creates a new diagnostic analyzer.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(ir *IRPipeline) *DiagnosticReport

Analyze examines an IRPipeline and produces a diagnostic report.

type Diagnostic

type Diagnostic struct {
	Level   DiagnosticLevel
	Phase   string
	Message string
	Hint    string
}

Diagnostic represents a single diagnostic message from the import process.

type DiagnosticLevel

type DiagnosticLevel string

DiagnosticLevel indicates the severity of a diagnostic.

const (
	DiagInfo    DiagnosticLevel = "info"
	DiagWarning DiagnosticLevel = "warning"
	DiagError   DiagnosticLevel = "error"
)

type DiagnosticReport

type DiagnosticReport struct {
	Diagnostics []Diagnostic
	Summary     ImportSummary
}

DiagnosticReport contains all diagnostics from an import operation.

type Generator

type Generator struct {
	PackageName string
	ModulePath  string
}

Generator generates Go code from an IR pipeline.

func NewGenerator

func NewGenerator(packageName, modulePath string) *Generator

NewGenerator creates a new Generator.

func (*Generator) GenerateGoMod

func (g *Generator) GenerateGoMod() string

GenerateGoMod generates a go.mod file.

func (*Generator) GenerateJobs

func (g *Generator) GenerateJobs(ir *IRPipeline) (string, error)

GenerateJobs generates Go code for all jobs.

func (*Generator) GenerateMain

func (g *Generator) GenerateMain() string

GenerateMain generates the main.go entry point.

func (*Generator) GenerateMultiFile

func (g *Generator) GenerateMultiFile(ir *IRPipeline) (map[string]string, error)

GenerateMultiFile generates Go code split into multiple files. Returns a map of filename to content:

  • pipeline.go: Pipeline configuration (stages, variables, workflow, default, includes)
  • jobs.go: Job definitions

func (*Generator) GeneratePipeline

func (g *Generator) GeneratePipeline(ir *IRPipeline) (string, error)

GeneratePipeline generates Go code for the pipeline configuration.

func (*Generator) GenerateSingleFile

func (g *Generator) GenerateSingleFile(ir *IRPipeline) (string, error)

GenerateSingleFile generates all code in a single file.

func (*Generator) GenerateTemplateFiles

func (g *Generator) GenerateTemplateFiles() map[string]string

GenerateTemplateFiles generates project scaffold files (go.mod, main.go, etc).

type IRArtifacts

type IRArtifacts struct {
	Paths     []string  `json:"paths,omitempty"`
	Exclude   []string  `json:"exclude,omitempty"`
	ExpireIn  string    `json:"expire_in,omitempty"`
	Name      string    `json:"name,omitempty"`
	When      string    `json:"when,omitempty"`
	Untracked bool      `json:"untracked,omitempty"`
	Reports   IRReports `json:"reports,omitempty"`
}

IRArtifacts represents artifacts configuration.

type IRCache

type IRCache struct {
	Key          any      `json:"key,omitempty"` // string or IRCacheKey
	Paths        []string `json:"paths,omitempty"`
	FallbackKeys []string `json:"fallback_keys,omitempty"`
	Policy       string   `json:"policy,omitempty"`
	Untracked    bool     `json:"untracked,omitempty"`
	When         string   `json:"when,omitempty"`
}

IRCache represents cache configuration.

type IRCacheKey

type IRCacheKey struct {
	Files  []string `json:"files,omitempty"`
	Prefix string   `json:"prefix,omitempty"`
}

IRCacheKey represents a dynamic cache key configuration.

type IRDefault

type IRDefault struct {
	Image        IRImage     `json:"image,omitempty"`
	BeforeScript []string    `json:"before_script,omitempty"`
	AfterScript  []string    `json:"after_script,omitempty"`
	Services     []IRService `json:"services,omitempty"`
	Cache        IRCache     `json:"cache,omitempty"`
	Artifacts    IRArtifacts `json:"artifacts,omitempty"`
	Tags         []string    `json:"tags,omitempty"`
	Retry        int         `json:"retry,omitempty"`
	Timeout      string      `json:"timeout,omitempty"`
}

IRDefault represents default job settings.

type IREnvironment

type IREnvironment struct {
	Name       string `json:"name,omitempty"`
	URL        string `json:"url,omitempty"`
	Action     string `json:"action,omitempty"`
	OnStop     string `json:"on_stop,omitempty"`
	AutoStopIn string `json:"auto_stop_in,omitempty"`
	Tier       string `json:"deployment_tier,omitempty"`
}

IREnvironment represents deployment environment configuration.

type IRHooks

type IRHooks struct {
	PreGetSourcesScript  []string `json:"pre_get_sources_script,omitempty"`
	PostGetSourcesScript []string `json:"post_get_sources_script,omitempty"`
}

IRHooks represents job lifecycle hooks configuration.

type IRImage

type IRImage struct {
	Name       string   `json:"name,omitempty"`
	Entrypoint []string `json:"entrypoint,omitempty"`
	PullPolicy string   `json:"pull_policy,omitempty"`
}

IRImage represents an image configuration.

type IRInclude

type IRInclude struct {
	Local     string `json:"local,omitempty"`
	Remote    string `json:"remote,omitempty"`
	Project   string `json:"project,omitempty"`
	File      string `json:"file,omitempty"`
	Ref       string `json:"ref,omitempty"`
	Template  string `json:"template,omitempty"`
	Component string `json:"component,omitempty"`
}

IRInclude represents an include directive.

type IRJob

type IRJob struct {
	Name               string         `json:"name"`
	Stage              string         `json:"stage,omitempty"`
	Script             []string       `json:"script,omitempty"`
	BeforeScript       []string       `json:"before_script,omitempty"`
	AfterScript        []string       `json:"after_script,omitempty"`
	Image              IRImage        `json:"image,omitempty"`
	Services           []IRService    `json:"services,omitempty"`
	Variables          map[string]any `json:"variables,omitempty"`
	Rules              []IRRule       `json:"rules,omitempty"`
	Needs              []string       `json:"needs,omitempty"`
	Dependencies       []string       `json:"dependencies,omitempty"`
	Artifacts          IRArtifacts    `json:"artifacts,omitempty"`
	Cache              IRCache        `json:"cache,omitempty"`
	Tags               []string       `json:"tags,omitempty"`
	When               string         `json:"when,omitempty"`
	AllowFailure       any            `json:"allow_failure,omitempty"` // bool or map with exit_codes
	Retry              any            `json:"retry,omitempty"`         // int or IRRetry
	Timeout            string         `json:"timeout,omitempty"`
	Extends            []string       `json:"extends,omitempty"`
	Environment        *IREnvironment `json:"environment,omitempty"`
	Trigger            *IRTrigger     `json:"trigger,omitempty"`
	Parallel           *IRParallel    `json:"parallel,omitempty"`
	Coverage           string         `json:"coverage,omitempty"`
	Interruptible      bool           `json:"interruptible,omitempty"`
	ResourceGroup      string         `json:"resource_group,omitempty"`
	Secrets            map[string]any `json:"secrets,omitempty"`
	IdTokens           map[string]any `json:"id_tokens,omitempty"`
	Hooks              *IRHooks       `json:"hooks,omitempty"`
	ManualConfirmation string         `json:"manual_confirmation,omitempty"`
}

IRJob is the intermediate representation of a job.

type IRParallel

type IRParallel struct {
	Matrix []map[string][]string `json:"matrix,omitempty"`
}

IRParallel represents parallel/matrix job configuration.

type IRPipeline

type IRPipeline struct {
	Stages    []string       `json:"stages,omitempty"`
	Variables map[string]any `json:"variables,omitempty"`
	Includes  []IRInclude    `json:"includes,omitempty"`
	Jobs      []IRJob        `json:"jobs,omitempty"`
	Default   *IRDefault     `json:"default,omitempty"`
	Workflow  *IRWorkflow    `json:"workflow,omitempty"`
}

IRPipeline is the intermediate representation of a GitLab CI pipeline.

type IRReports

type IRReports struct {
	JUnit           []string `json:"junit,omitempty"`
	Coverage        string   `json:"coverage_report,omitempty"`
	Cobertura       string   `json:"cobertura,omitempty"`
	Codequality     string   `json:"codequality,omitempty"`
	SAST            string   `json:"sast,omitempty"`
	DependencyScan  string   `json:"dependency_scanning,omitempty"`
	ContainerScan   string   `json:"container_scanning,omitempty"`
	DAST            string   `json:"dast,omitempty"`
	SecretDetection string   `json:"secret_detection,omitempty"`
	Terraform       string   `json:"terraform,omitempty"`
	Metrics         string   `json:"metrics,omitempty"`
	Dotenv          string   `json:"dotenv,omitempty"`
}

IRReports represents artifact report configuration.

type IRRetry

type IRRetry struct {
	Max       int      `json:"max,omitempty"`
	When      []string `json:"when,omitempty"`
	ExitCodes []int    `json:"exit_codes,omitempty"`
}

IRRetry represents retry configuration (structured form).

type IRRule

type IRRule struct {
	If           string         `json:"if,omitempty"`
	When         string         `json:"when,omitempty"`
	AllowFailure bool           `json:"allow_failure,omitempty"`
	Variables    map[string]any `json:"variables,omitempty"`
	Changes      []string       `json:"changes,omitempty"`
	Exists       []string       `json:"exists,omitempty"`
}

IRRule represents a rule configuration.

type IRService

type IRService struct {
	Name       string            `json:"name,omitempty"`
	Alias      string            `json:"alias,omitempty"`
	Entrypoint []string          `json:"entrypoint,omitempty"`
	Command    []string          `json:"command,omitempty"`
	Variables  map[string]string `json:"variables,omitempty"`
	PullPolicy string            `json:"pull_policy,omitempty"`
}

IRService represents a service configuration.

type IRTrigger

type IRTrigger struct {
	Project  string   `json:"project,omitempty"`
	Branch   string   `json:"branch,omitempty"`
	Strategy string   `json:"strategy,omitempty"`
	Include  string   `json:"include,omitempty"`
	Forward  []string `json:"forward,omitempty"`
}

IRTrigger represents a child pipeline trigger configuration.

type IRWorkflow

type IRWorkflow struct {
	Name  string   `json:"name,omitempty"`
	Rules []IRRule `json:"rules,omitempty"`
}

IRWorkflow represents workflow configuration.

type ImportSummary

type ImportSummary struct {
	StagesCount      int
	VariablesCount   int
	IncludesCount    int
	JobsCount        int
	HiddenJobsCount  int
	RulesCount       int
	ArtifactsCount   int
	CacheCount       int
	ServicesCount    int
	EnvironmentCount int
	NeedsCount       int
	TriggerCount     int
}

ImportSummary provides statistics about the imported pipeline.

type Parser

type Parser struct{}

Parser parses GitLab CI YAML files.

func NewParser

func NewParser() *Parser

NewParser creates a new Parser.

func (*Parser) ParseFile

func (p *Parser) ParseFile(path string) (*IRPipeline, error)

ParseFile parses a GitLab CI YAML file.

func (*Parser) ParseYAML

func (p *Parser) ParseYAML(data []byte) (*IRPipeline, error)

ParseYAML parses GitLab CI YAML content.

Jump to

Keyboard shortcuts

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