template

package
v0.1.0-preview.4.rc Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTemplateURLs

func GetTemplateURLs(config *Config, framework, lang string) (string, string, error)

GetTemplateURLs returns template URL & version for the requested framework + language. Fails fast if the framework does not exist, the template URL is blank, or the language is not declared in the framework's Languages slice.

Types

type CloneEvent

type CloneEvent struct {
	Type     CloneEventType
	Parent   string // for submodule events
	Module   string // current module path
	Name     string // submodule name or module path
	URL      string // for discovery
	Ref      string // current ref we are cloning from
	Progress int    // 0–100
}

CloneEvent is a single “thing that happened” during clone

type CloneEventType

type CloneEventType int

CloneEventType enumerates the kinds of things git clone can tell us

const (
	EventSubmoduleDiscovered CloneEventType = iota
	EventSubmoduleCloneStart
	EventProgress
	EventCloneComplete
	EventCloneFailed
)

type Config

type Config struct {
	Framework map[string]FrameworkSpec `yaml:"framework"`
}

func LoadConfig

func LoadConfig() (*Config, error)

type FrameworkSpec

type FrameworkSpec struct {
	Template  string   `yaml:"template"`
	Version   string   `yaml:"version"`
	Languages []string `yaml:"languages"`
}

type GitClient

type GitClient struct {
	Runner         Runner
	ReceivingRegex *regexp.Regexp
	CloningRegex   *regexp.Regexp
	SubmoduleRegex *regexp.Regexp
}

GitClient does our actual clone + parsing

func NewGitClient

func NewGitClient() *GitClient

NewGitClient builds a GitClient using the real exec

func NewGitClientWithRunner

func NewGitClientWithRunner(r Runner) *GitClient

NewGitClientWithRunner enables injecting a custom Runner (e.g. in tests)

func (*GitClient) Clone

func (g *GitClient) Clone(
	ctx context.Context,
	repoURL, ref, dest string,
	config GitFetcherConfig,
	reporter Reporter,
) error

Clone runs the following to enable clones from SHAs, tags and branches:

  • git clone --no-checkout --depth 1 <repoURL> <dest>
  • git -C <dest> checkout --quiet <ref>
  • git -C <dest> submodule update --init --recursive --progress

func (*GitClient) ParseCloneOutput

func (g *GitClient) ParseCloneOutput(r io.Reader, rep Reporter, dest string, ref string) error

ParseCloneOutput scans gits progress output and emits events

type GitFetcher

type GitFetcher struct {
	Client  *GitClient
	Metrics GitMetrics
	Config  GitFetcherConfig
	Logger  logger.ProgressLogger
}

GitFetcher wraps clone with metrics and reporting

func (*GitFetcher) Fetch

func (f *GitFetcher) Fetch(ctx context.Context, repoURL, ref, targetDir string) error

type GitFetcherConfig

type GitFetcherConfig struct {
	Verbose bool
}

GitFetcherConfig holds options; we only care about Verbose here

type GitMetrics

type GitMetrics interface {
	CloneStarted(repo string)
	CloneFinished(repo string, err error)
}

TODO: implement metric transport

type Reporter

type Reporter interface {
	Report(CloneEvent)
}

Reporter consumes CloneEvents

func NewCloneReporter

func NewCloneReporter(repoURL string, lg logger.ProgressLogger, m GitMetrics) Reporter

type Runner

type Runner interface {
	// CommandContext mirrors exec.CommandContext
	CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
}

Runner lets us inject/mock command execution in tests

type SubmoduleReport

type SubmoduleReport struct {
	Name string
	Dest string
	URL  string
}

Jump to

Keyboard shortcuts

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