generate

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: GPL-3.0 Imports: 22 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 applied through the expand+merge2 pipeline in pkg/action/patch.go, reproduces newContent from oldContent.

  • Maps are recursively diffed; only changed/added keys are included.
  • Scalar lists emit only added items (expandScalarLists prepends old values on apply).
  • Map-lists are matched by an inferred merge key (e.g. "name"); only changed/added items are included (merge2 matches by key on apply).

Returns nil if YAML cannot be parsed or if there are no changes.

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 DiffProvider suitable for fetching PR/MR data.

Short-form references (unambiguous, preferred for self-hosted instances):

  • github:owner/repo#123
  • gitlab:group/repo!123

URL-based detection (works for any host, including self-hosted):

  • https://<host>/owner/repo/pull/123 → GitHub
  • https://<host>/group/repo/-/merge_requests/123 → GitLab

For self-hosted instances where URL patterns may be ambiguous, use the short-form prefix (github: or gitlab:) to explicitly specify the provider.

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 name of the environment variable that holds the
	// GitHub personal access token or GitLab private token used to
	// authenticate API requests when fetching PR/MR data.
	TokenEnv string
}

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