Help us shape the future of Go! Take the 2026 Go Developer Survey

template

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEditorCancelled is returned when user cancels editor
	ErrEditorCancelled = errors.New("editor cancelled: template unchanged or empty")

	// ErrNoEditor is returned when no editor is available
	ErrNoEditor = errors.New("no editor available: set $EDITOR environment variable")

	// ErrTemplateValidationFailed is returned when template validation fails
	ErrTemplateValidationFailed = errors.New("template validation failed")
)

Functions

func ExtractBaseBranch

func ExtractBaseBranch(content string) (string, bool)

ExtractBaseBranch extracts only the base branch name from template header This is useful for continue mode where head branch is obtained from git Returns (baseBranch, found)

func ExtractBranchInfo

func ExtractBranchInfo(content string) (string, string, bool)

ExtractBranchInfo extracts head and base branch names from template header Returns (headBranch, baseBranch, found)

func FilterMergeCommits

func FilterMergeCommits(commitMessages []string) []string

FilterMergeCommits filters out merge commits from commit messages

func FindSavedTemplates

func FindSavedTemplates() ([]string, error)

FindSavedTemplates finds all saved template files in temp directory

func FormatValidationErrors

func FormatValidationErrors(errs []error, stackingCtx *StackingContext) string

FormatValidationErrors formats validation errors for display with stacking context stackingCtx can be nil for non-stacking scenarios

func GetDependentPRsWarning

func GetDependentPRsWarning(stackingCtx *StackingContext) string

GetDependentPRsWarning returns a formatted warning about dependent PRs

func GetEditorCommand

func GetEditorCommand() (string, error)

GetEditorCommand returns the editor command to use

func GetStackingInfo

func GetStackingInfo(stackingCtx *StackingContext) string

GetStackingInfo returns a formatted string with stacking information for display

func IsEmptyCommitMessage

func IsEmptyCommitMessage(message string) bool

IsEmptyCommitMessage checks if a commit message is effectively empty

func LoadSavedTemplate

func LoadSavedTemplate(path string) (string, error)

LoadSavedTemplate loads a previously saved template

func OpenEditor

func OpenEditor(templateContent string) (string, error)

OpenEditor opens the template in the user's $EDITOR

func ReadTemplateFrom

func ReadTemplateFrom(r io.Reader) (string, error)

ReadTemplateFrom reads template content from a reader (for testing)

func RemoveSavedTemplate

func RemoveSavedTemplate(path string) error

RemoveSavedTemplate removes a saved template file

func SaveTemplate

func SaveTemplate(content string) (string, error)

SaveTemplate saves template content to a file for --continue support

func ValidateFields

func ValidateFields(fields *TemplateFields, requireTestPlan bool, stackingCtx *StackingContext) []error

ValidateFields validates that required template fields are filled stackingCtx can be nil for non-stacking scenarios

func ValidateFieldsWithContext

func ValidateFieldsWithContext(fields *TemplateFields, requireTestPlan bool, stackingCtx *StackingContext) (bool, string)

ValidateFieldsWithContext is a convenience wrapper that combines validation and formatting

func WriteTemplateTo

func WriteTemplateTo(w io.Writer, templateContent string) error

WriteTemplateTo writes template content to a writer (for testing)

Types

type CommitAnalysis

type CommitAnalysis struct {
	Title           string   // Suggested PR title
	Summary         string   // Suggested PR summary/body
	BaseBranch      string   // Base branch used for analysis
	CommitCount     int      // Number of commits analyzed
	CommitMessages  []string // All commit messages
	HasMergeCommits bool     // Whether merge commits were found
}

CommitAnalysis represents the result of analyzing commits for template pre-filling

func AnalyzeCommitsForTemplate

func AnalyzeCommitsForTemplate(repo CommitRepository, baseBranch, headBranch string) (*CommitAnalysis, error)

AnalyzeCommitsForTemplate analyzes commits between base and head branches to generate suggested content for PR template

type CommitRepository

type CommitRepository interface {
	GetCommitsBetween(base, head string) ([]git.CommitInfo, error)
}

CommitRepository defines the minimal interface needed for commit analysis. This allows for easier testing without depending on the full git.Repository.

type StackingContext

type StackingContext struct {
	IsStacking     bool
	BaseBranch     string
	ParentPR       *github.PullRequest
	DependentPRs   []*github.PullRequest
	CurrentBranch  string
	ShowDependents bool
}

StackingContext contains stacking information for template header

type TemplateFields

type TemplateFields struct {
	Title      string
	Summary    string
	TestPlan   string
	Reviewers  []string // List of @usernames or @org/team
	Ref        []string // Linear issue references
	Draft      bool     // Whether PR should be created as draft
	BaseBranch string   // Read-only display of base branch
}

TemplateFields contains all the structured data from the template

func ParseTemplate

func ParseTemplate(content string) (*TemplateFields, error)

ParseTemplate parses the template content into structured fields

type TemplateGenerator

type TemplateGenerator struct {
	// contains filtered or unexported fields
}

TemplateGenerator generates PR templates with stacking context

func NewTemplateGenerator

func NewTemplateGenerator(stackingCtx *StackingContext, analysis *CommitAnalysis, reviewers []string, linearEnabled bool, defaultDraft bool) *TemplateGenerator

NewTemplateGenerator creates a new template generator

func (*TemplateGenerator) Generate

func (g *TemplateGenerator) Generate() string

Generate creates the template content

Jump to

Keyboard shortcuts

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