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 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 ¶
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 Go template expressions ({{ .key }}). 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 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.
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 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.