Documentation
¶
Index ¶
- func ComputeSMP(oldContent, newContent []byte) []byte
- func Parameterize(content string, params map[string]string) string
- func ParameterizePath(path string, params map[string]string) string
- func Run(ctx context.Context, opts Options, logger *slog.Logger) error
- type ChangeType
- type DiffProvider
- type FileChange
- type GitHubDiffProvider
- type GitLabDiffProvider
- type Options
- type PRInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeSMP ¶
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 ¶
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 ¶
ParameterizePath replaces literal occurrences of param values in a file path with the __key__ placeholder syntax. Replacements are applied longest-value-first.
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 ¶
ParsePRRef parses a PR/MR URL and returns the provider type and a reference string suitable for the provider's FetchDiff method.
Supported formats:
- https://github.com/owner/repo/pull/123
- https://gitlab.com/group/repo/-/merge_requests/123
- github:owner/repo#123
- gitlab:group/repo!123
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.
type GitLabDiffProvider ¶
type GitLabDiffProvider struct{}
GitLabDiffProvider fetches MR diffs from GitLab.
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
// IncludeGitOps adds commitPush and pr operations to the generated module.
IncludeGitOps bool
}
Options configures module generation.