generate

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: GPL-3.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSMP

func ComputeSMP(oldContent, newContent []byte) []byte

ComputeSMP computes a strategic merge patch: the minimal YAML document that, when deep-merged into oldContent, produces newContent. Only changed and added fields are included.

If the YAML cannot be parsed, it returns nil (caller should fall back to treating it as a new file).

func Parameterize

func Parameterize(content string, params map[string]string) string

Parameterize replaces literal occurrences of param values in content with Go template expressions ({{ .key }}). Replacements are applied longest-value-first to avoid partial-match issues.

func ParameterizePath

func ParameterizePath(path string, params map[string]string) string

ParameterizePath replaces literal occurrences of param values in a file path with Go template expressions ({{ .key }}). Replacements are applied longest-value-first.

func Run

func Run(ctx context.Context, opts Options, logger *slog.Logger) error

Run generates a loom module from a PR/MR.

Types

type ChangeType

type ChangeType int

ChangeType classifies what happened to a file in a PR/MR.

const (
	ChangeAdded ChangeType = iota
	ChangeModified
	ChangeDeleted
	ChangeRenamed
)

func (ChangeType) String

func (c ChangeType) String() string

type DiffProvider

type DiffProvider interface {
	FetchDiff(ctx context.Context, ref string, token string, logger *slog.Logger) (*PRInfo, error)
}

DiffProvider fetches file changes from a PR/MR.

func ParsePRRef

func ParsePRRef(ref string, logger *slog.Logger) (provider string, _ DiffProvider, _ error)

ParsePRRef parses a PR/MR URL and returns the provider type and a reference string suitable for the provider's FetchDiff method.

Supported formats:

type FileChange

type FileChange struct {
	Type       ChangeType
	Path       string // file path relative to repo root
	OldPath    string // previous path (only for renames)
	NewContent []byte // full file content after the change (for added/modified)
	OldContent []byte // full file content before the change (for modified)
}

FileChange represents a single file change from a PR/MR.

type GitHubDiffProvider

type GitHubDiffProvider struct{}

GitHubDiffProvider fetches PR diffs from GitHub.

func (*GitHubDiffProvider) FetchDiff

func (p *GitHubDiffProvider) FetchDiff(ctx context.Context, ref, token string, logger *slog.Logger) (*PRInfo, error)

type GitLabDiffProvider

type GitLabDiffProvider struct{}

GitLabDiffProvider fetches MR diffs from GitLab.

func (*GitLabDiffProvider) FetchDiff

func (p *GitLabDiffProvider) FetchDiff(ctx context.Context, ref, token string, logger *slog.Logger) (*PRInfo, error)

type Options

type Options struct {
	// Ref is the PR/MR URL or short reference.
	Ref string
	// Params maps param names to concrete values to parameterize.
	Params map[string]string
	// OutputDir is the directory to write the generated module.
	OutputDir string
	// ModuleName overrides the auto-derived module name.
	ModuleName string
	// TokenEnv is the env var name for the API token.
	TokenEnv string
	// ExcludeGitOps skips generating target, commitPush, and pr operations.
	ExcludeGitOps bool
}

Options configures module generation.

type PRInfo

type PRInfo struct {
	Title      string
	Body       string
	BaseBranch string
	HeadBranch string
	RepoURL    string
	Provider   string // "github" or "gitlab"
	Files      []FileChange
}

PRInfo holds metadata about a PR/MR.

Jump to

Keyboard shortcuts

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