Documentation
¶
Overview ¶
Package pr provides PR title and body generation for GitHub pull requests.
Index ¶
- Constants
- func CreateLockSection(branch string, eng engine.BranchReader) string
- func CreateNavigationComment(branch string, eng engine.BranchReader, opts NavigationOptions) string
- func CreatePRBodyFooter(branch string, eng engine.BranchReader) string
- func CreatePRBodyFooterWithOptions(branch string, eng engine.BranchReader, opts NavigationOptions) string
- func FormatMergeBody(params MergeBodyParams) string
- func FormatMergeTitle(scopes []string, totalCount int) string
- func FormatMergeTitleWithDescription(desc *git.StackDescription, scopes []string, totalCount int) string
- func FormatStackTrailers(stackSize int, prNumbers []int, scope string) string
- func FormatStackTree(params StackTreeParams) string
- func GenerateBody(branch engine.Branch, existingBody string) string
- func GenerateTitle(branch engine.Branch, existingTitle string, scope engine.Scope) string
- func IsStackitComment(body string) bool
- func ResolveUnifiedScope(scopes []string) string
- func ShouldShowNavigation(opts NavigationOptions, branch string, eng engine.BranchReader) bool
- func StripFooter(body string) string
- func StripLockSection(body string) string
- func UpdatePRBodyFooter(existingBody, footer string) string
- func UpdatePRBodyLockSection(existingBody, lockSection string) string
- type Content
- type ExcludedBranch
- type MergeBodyParams
- type MergeBranch
- type NavigationOptions
- type StackMetadata
- type StackTrailerInfo
- type StackTreeBranch
- type StackTreeParams
Constants ¶
const ( // SectionStart marks the beginning of the stackit-generated section in PR body. SectionStart = "<!-- STACKIT-SECTION-START -->" // SectionEnd marks the end of the stackit-generated section in PR body. SectionEnd = "<!-- STACKIT-SECTION-END -->" // LockSectionStart marks the beginning of the lock status section in PR body. LockSectionStart = "<!-- STACKIT-LOCK-START -->" // LockSectionEnd marks the end of the lock status section in PR body. LockSectionEnd = "<!-- STACKIT-LOCK-END -->" // CommentMarker is used to identify stackit-generated navigation comments. CommentMarker = "<!-- STACKIT-NAV-COMMENT -->" )
const ( TrailerStackSize = "Stackit-Stack-Size" TrailerPRs = "Stackit-PRs" TrailerScope = "Stackit-Scope" )
Trailer key constants for stack metadata embedded in merge commits.
Variables ¶
This section is empty.
Functions ¶
func CreateLockSection ¶
func CreateLockSection(branch string, eng engine.BranchReader) string
CreateLockSection creates an independent lock status section for the PR body. Returns empty string if the branch is not locked. This section is independent of navigation settings and appears at the TOP of the PR body.
func CreateNavigationComment ¶
func CreateNavigationComment(branch string, eng engine.BranchReader, opts NavigationOptions) string
CreateNavigationComment creates the content for a navigation comment. This includes both the stack description and the navigation tree. Returns empty string if neither navigation nor description should be shown.
func CreatePRBodyFooter ¶
func CreatePRBodyFooter(branch string, eng engine.BranchReader) string
CreatePRBodyFooter creates a PR body footer with dependency tree using default options.
func CreatePRBodyFooterWithOptions ¶
func CreatePRBodyFooterWithOptions(branch string, eng engine.BranchReader, opts NavigationOptions) string
CreatePRBodyFooterWithOptions creates a PR body footer with dependency tree using custom options. Returns empty string if neither navigation nor description should be shown. The footer includes both the stack description and the navigation tree in a combined section.
func FormatMergeBody ¶
func FormatMergeBody(params MergeBodyParams) string
FormatMergeBody formats the body for a merge PR. This unified format works for both consolidation and multi-stack merges.
func FormatMergeTitle ¶
FormatMergeTitle formats a unified title for merge PRs (both multi-stack and consolidation). scopes contains the scope values for each branch (may include empty strings for unscoped branches). totalCount is the total number of PRs/branches being merged.
Examples:
- Merging PROJ-123, PROJ-124 (all scoped)
- Merging PROJ-123 (+2) (1 scoped, 2 unscoped)
- Merging 3 PRs (no scopes)
func FormatMergeTitleWithDescription ¶
func FormatMergeTitleWithDescription(desc *git.StackDescription, scopes []string, totalCount int) string
FormatMergeTitleWithDescription formats a merge PR title, using the stack description if present. If the description has a title, it is used directly. Otherwise, falls back to FormatMergeTitle.
func FormatStackTrailers ¶
FormatStackTrailers is a compatibility wrapper around StackMetadata.ToTrailers.
func FormatStackTree ¶
func FormatStackTree(params StackTreeParams) string
FormatStackTree creates an ASCII tree representation of the stack.
func GenerateBody ¶
GenerateBody creates a PR body from branch commits. If existingBody is provided and non-empty, it's returned as-is. Otherwise, the branch's default PR body is used.
func GenerateTitle ¶
GenerateTitle creates a PR title from branch commits. If existingTitle is provided and non-empty, it's used as the base. Otherwise, the branch's default PR title is used. The scope is applied to the title.
func IsStackitComment ¶
IsStackitComment checks if a comment body is a stackit navigation comment.
func ResolveUnifiedScope ¶
ResolveUnifiedScope returns a scope only when all non-empty scopes match. This avoids mislabeling mixed-scope merge metadata.
func ShouldShowNavigation ¶
func ShouldShowNavigation(opts NavigationOptions, branch string, eng engine.BranchReader) bool
ShouldShowNavigation determines if navigation should be displayed based on options.
func StripFooter ¶
StripFooter removes the stackit-generated footer from a PR body. This also strips the <hr/> separator that precedes the footer.
func StripLockSection ¶
StripLockSection removes the lock status section from a PR body.
func UpdatePRBodyFooter ¶
UpdatePRBodyFooter updates an existing PR body with a new footer.
func UpdatePRBodyLockSection ¶
UpdatePRBodyLockSection adds, updates, or removes the lock section at the TOP of a PR body. If lockSection is empty, any existing lock section is removed. The lock section always appears at the very top of the body.
Types ¶
type ExcludedBranch ¶
ExcludedBranch represents a branch or stack excluded from the merge.
type MergeBodyParams ¶
type MergeBodyParams struct {
// Branches contains all branches being merged, with their PR info.
Branches []MergeBranch
// Excluded contains branches/stacks that were excluded from the merge.
// Optional - only populated for multi-stack merges with conflicts.
Excluded []ExcludedBranch
// StackTree is the ASCII tree representation of the stack structure.
// Optional - if empty, no tree section is rendered.
StackTree string
// StackDescription is the description of the stack being merged.
// Optional - if present, it appears at the top of the body.
StackDescription *git.StackDescription
// Metadata is stack metadata for trailers.
// Optional - if StackSize is zero, metadata is derived from Branches.
Metadata StackMetadata
}
MergeBodyParams contains all parameters for generating a merge PR body. This unified structure handles both single-stack and multi-stack merges.
type MergeBranch ¶
type MergeBranch struct {
Name string
PRNumber int // 0 if no PR exists
PRTitle string // Empty if no PR exists
}
MergeBranch represents a branch being merged.
type NavigationOptions ¶
NavigationOptions controls how the stack navigation is displayed in PRs.
func DefaultNavigationOptions ¶
func DefaultNavigationOptions() NavigationOptions
DefaultNavigationOptions returns the default navigation options.
type StackMetadata ¶
StackMetadata contains stack metadata embedded in git trailers.
func BuildStackMetadata ¶
func BuildStackMetadata(branches []MergeBranch, scope string) StackMetadata
BuildStackMetadata derives stack metadata from merge branches.
func NewStackMetadata ¶
func NewStackMetadata(stackSize int, prNumbers []int, scope string) StackMetadata
NewStackMetadata constructs stack metadata from explicit fields.
func ParseStackMetadataTrailers ¶
func ParseStackMetadataTrailers(body string) *StackMetadata
ParseStackMetadataTrailers extracts stack trailer values from a commit message body. Returns nil if no stack trailers are found.
func (StackMetadata) ToTrailers ¶
func (m StackMetadata) ToTrailers() string
ToTrailers builds a git trailer block for this metadata. The trailers follow the standard git trailer format (key: value) and can be parsed by git log's %(trailers) format specifier.
type StackTrailerInfo ¶
type StackTrailerInfo = StackMetadata
StackTrailerInfo is an alias kept for backwards compatibility.
func ParseStackTrailers ¶
func ParseStackTrailers(body string) *StackTrailerInfo
ParseStackTrailers is a compatibility wrapper around ParseStackMetadataTrailers.
type StackTreeBranch ¶
type StackTreeBranch struct {
Name string
Depth int // 0 for branches directly off trunk
PRNumber int // 0 if no PR
}
StackTreeBranch represents a branch in the stack tree.
type StackTreeParams ¶
type StackTreeParams struct {
TrunkName string
Branches []StackTreeBranch
}
StackTreeParams contains parameters for generating a stack tree visualization.