templates

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package templates provides configuration file template generation.

This package contains templates for generating workspace and repository configuration files in various formats.

Templates

  • Repository config (.gz-git.yaml)
  • Workspace config (hierarchical)
  • Profile templates

Usage

content, err := templates.Render(templates.RepositoriesConfig, data)

Package templates provides embedded YAML templates for configuration generation. Templates are compiled into the binary using Go's embed package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRaw

func GetRaw(name TemplateName) ([]byte, error)

GetRaw returns the raw template content without processing.

func MustRender

func MustRender(name TemplateName, data any) string

MustRender renders a template and panics on error.

PANIC CONDITIONS:

  • Template name not found (embedded file missing)
  • Template syntax error (malformed template)
  • Template execution error (missing field in data, type mismatch)

WHEN TO USE:

  • Initialization code where templates are known valid at compile time
  • Tests and examples where failure indicates programmer error
  • Embedded templates that ship with the binary (cannot be missing)

WHEN NOT TO USE:

  • User-provided templates (use Render instead)
  • Templates loaded from external files
  • Anywhere template errors should be recoverable

For recoverable error handling, use Render which returns an error.

func Render

func Render(name TemplateName, data any) (string, error)

Render renders a template with the given data. Returns an error if the template cannot be found, parsed, or executed. For cases where template errors indicate programmer error, use MustRender instead.

Types

type BootstrapData

type BootstrapData struct {
	Parent  string
	Profile string
}

BootstrapData is the data for RepositoriesBootstrap template.

type ChildForgeData

type ChildForgeData struct {
	Parent       string
	Profile      string
	GeneratedAt  string // RFC3339 timestamp
	Provider     string // github, gitlab, gitea
	Organization string
	Strategy     string
	Parallel     int
	CloneProto   string
	SSHPort      int
	Repositories []ChildForgeRepoData
}

ChildForgeData is the data for RepositoriesChildForge template. Used when generating child configs from forge-synced workspaces.

type ChildForgeRepoData

type ChildForgeRepoData struct {
	Name   string
	URL    string
	Path   string // relative path from workspace root
	Branch string
}

ChildForgeRepoData represents a repository entry in child forge config.

type ChildWorkspaceEntry

type ChildWorkspaceEntry struct {
	Name string
	Path string
}

ChildWorkspaceEntry represents a workspace entry in workspaces map format.

type ChildWorkspacesData

type ChildWorkspacesData struct {
	Parent       string
	Profile      string
	GeneratedAt  string // RFC3339 timestamp
	Provider     string // github, gitlab, gitea
	Organization string
	Workspaces   []ChildWorkspaceEntry
}

ChildWorkspacesData is the data for WorkspacesChildForge template. Used when generating child configs with workspaces map format.

type CommonScannedConfig

type CommonScannedConfig struct {
	ScannedAt  string // RFC3339 timestamp
	Count      int    // Number of repos/workspaces found
	Strategy   string // reset, pull, rebase, fetch, skip
	Parallel   int    // Parallel workers
	MaxRetries int    // Retry count on failure
	CloneProto string // ssh, https
	SSHPort    int    // Custom SSH port (0 = default)
	// ExplainDefaults toggles commented default values for omitted fields.
	ExplainDefaults bool
}

CommonScannedConfig contains shared configuration fields for scanned configs. Used by both ScannedData (repositories) and WorkspaceScannedData (workspace).

type ForgeGeneratedData

type ForgeGeneratedData struct {
	GeneratedAt  string // RFC3339 timestamp
	Provider     string // github, gitlab, gitea
	Organization string
	Strategy     string
	Parallel     int
	MaxRetries   int
	CloneProto   string
	SSHPort      int
	Repositories []ForgeRepoData
}

ForgeGeneratedData is the data for RepositoriesForge template.

type ForgeRepoData

type ForgeRepoData struct {
	Name string
	URL  string
	Path string
}

ForgeRepoData represents a forge repository entry.

type ForgeSourceData

type ForgeSourceData struct {
	Provider         string
	Org              string
	BaseURL          string
	Token            string
	IncludeSubgroups bool
	SubgroupMode     string
}

ForgeSourceData represents a forge source.

type ProfileData

type ProfileData struct {
	Provider         string
	BaseURL          string
	Token            string
	CloneProto       string
	SSHPort          int
	Parallel         int
	IncludeSubgroups bool
	SubgroupMode     string
	Sync             *SyncData
}

ProfileData represents a profile entry.

type RepoData

type RepoData struct {
	Name        string
	URL         string
	Path        string
	Branch      string
	Description string
}

RepoData represents a single repository entry.

type RepositoriesBasicData

type RepositoriesBasicData struct {
	Name         string
	Team         string
	Description  string
	Strategy     string // reset|pull|rebase|fetch
	Parallel     int
	Repositories []RepoData
}

RepositoriesBasicData is the data for RepositoriesBasic template.

type RepositoriesChildData

type RepositoriesChildData struct {
	Parent       string
	Profile      string
	Repositories []RepoData
}

RepositoriesChildData is the data for RepositoriesChild template.

type ScannedData

type ScannedData struct {
	CommonScannedConfig
	BasePath     string // Base path for relative paths (default: ".")
	Repositories []ScannedRepoData
}

ScannedData is the data for RepositoriesScanned template.

type ScannedRepoData

type ScannedRepoData struct {
	Name              string
	Path              string
	URL               string            // Primary URL (typically origin)
	AdditionalRemotes map[string]string // Additional remotes (name -> URL)
	Branch            string            // Current branch name (optional)
}

ScannedRepoData represents a scanned repository entry.

type SyncData

type SyncData struct {
	Strategy   string
	MaxRetries int
}

SyncData represents sync settings.

type TemplateName

type TemplateName string

TemplateName identifies available templates.

const (
	// RepositoriesBasic is a basic repositories config with flat repo list.
	RepositoriesBasic TemplateName = "repositories-basic.yaml"

	// RepositoriesChild is a child config that inherits from parent.
	RepositoriesChild TemplateName = "repositories-child.yaml"

	// RepositoriesBootstrap is a minimal bootstrap config for auto-generation.
	RepositoriesBootstrap TemplateName = "repositories-bootstrap.yaml"

	// RepositoriesSample is a sample config with comments for new users.
	RepositoriesSample TemplateName = "repositories-sample.yaml"

	// RepositoriesScanned is for configs generated by workspace scan.
	RepositoriesScanned TemplateName = "repositories-scanned.yaml"

	// RepositoriesForge is for configs generated from forge API.
	RepositoriesForge TemplateName = "repositories-forge.yaml"

	// RepositoriesChildForge is for child configs with forge-synced repositories.
	RepositoriesChildForge TemplateName = "repositories-child-forge.yaml"

	// WorkspacesChildForge is for child configs with workspaces map format.
	WorkspacesChildForge TemplateName = "workspaces-child-forge.yaml"

	// WorkspaceWorkstation is a top-level workstation config with profiles.
	WorkspaceWorkstation TemplateName = "workspace-workstation.yaml"

	// WorkspaceScanned is for workspace configs generated by directory scan.
	WorkspaceScanned TemplateName = "workspace-scanned.yaml"

	// WorkspaceForge is a workspace config with forge source integration.
	WorkspaceForge TemplateName = "workspace-forge.yaml"

	// Profile is a standalone profile configuration.
	Profile TemplateName = "profile.yaml"
)

func List

func List() []TemplateName

List returns all available template names.

type WorkspaceData

type WorkspaceData struct {
	Path     string
	Type     string // forge|git|config
	Profile  string
	Source   *ForgeSourceData
	Sync     *SyncData
	Parallel int
}

WorkspaceData represents a workspace entry.

type WorkspaceForgeData

type WorkspaceForgeData struct {
	Parent     string
	Profile    string
	Name       string
	Team       string
	Workspaces map[string]WorkspaceData
}

WorkspaceForgeData is the data for WorkspaceForge template.

type WorkspaceScannedData

type WorkspaceScannedData struct {
	CommonScannedConfig
	Name       string // Workspace name (usually directory name)
	Workspaces []WorkspaceScannedEntry
}

WorkspaceScannedData is the data for WorkspaceScanned template.

type WorkspaceScannedEntry

type WorkspaceScannedEntry struct {
	Name   string
	Path   string
	URL    string
	Type   string
	Branch string // Current branch name
}

WorkspaceScannedEntry represents a scanned workspace entry.

type WorkstationData

type WorkstationData struct {
	Name       string
	Owner      string
	Parallel   int
	CloneProto string
	Profiles   map[string]ProfileData
	Workspaces map[string]WorkspaceData
}

WorkstationData is the data for WorkspaceWorkstation template.

Jump to

Keyboard shortcuts

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