config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config provides a toml-based config file parser and validation.

Index

Constants

View Source
const (
	DefaultConfigDir = ".stentor.d"
)

Variables

View Source
var (
	// ErrBadHosting is the error returned if a config file references an unsupported hosting provider.
	ErrBadHosting = errors.New("hosting must be one of 'github' or 'gitlab'")
	// ErrBadMarkup is the error returned if a config file references an unsupported style of markup.
	ErrBadMarkup = errors.New("markup must be one of 'markdown' or 'rst'")
	// ErrBadSections is the error returned if a config file contains an empty sections list.
	ErrBadSections = errors.New("must define at least one section")
	// ErrMissingRepository is the error returned if a config file does not declare a repository.
	ErrMissingRepository = errors.New("repository is required")
)

Functions

func ValidateConfig

func ValidateConfig(c Config) error

ValidateConfig returns an error if c is not a valid config file.

Types

type Config

type Config struct {
	// Repository is the name of your repository in <username>/<repo name> format.
	Repository string `toml:"repository,omitempty"`
	// FragmentDir is the path to the directory holding the project's news fragments.
	// Defaults to '.stentor.d'.
	FragmentDir string `toml:"fragment_dir,omitempty" yaml:"fragment_dir,omitempty"`
	// Hosting is the source repository host.
	// When Markup is set to markdown, this also determines the markdown flavor.
	// Currently, github and gitlab are supported.
	// Defaults to github.
	Hosting string `toml:"hosting,omitempty"`
	// Markup sets the format of your changelog.
	// Currently, markdown and rst (ReStructuredText) are supported.
	// Defaults to markdown
	Markup string `toml:"markup,omitempty"`
	// Sections define the different news sections.
	// Sections will be listed in the order in which they are defined here.
	Sections []Section `toml:"sections,omitempty"`
	// HeaderTemplate is the name of the template used to render the header of the news file.
	HeaderTemplate string `toml:"header_template,omitempty"`
	// SectionTemplate is the name of the template used to render the individual sections of the news file.
	SectionTemplate string `toml:"section_template,omitempty"`
	// NewsFile is the name of the file to update
	NewsFile string `toml:"news_file,omitempty"`
}

Config represents the project's configuration for stentor.

func ParseBytes

func ParseBytes(data []byte) (Config, error)

ParseBytes parses bytes data into a Config.

func (Config) FragmentFiles

func (c Config) FragmentFiles() ([]string, error)

FragmentFiles returns the names of all the fragment files.

func (Config) StartComment

func (c Config) StartComment() string

StartComment returns the markup-specific comment string stentor uses to separate the news file header from the releases.

type Section

type Section struct {
	// Name of the section.
	Name string `toml:"name,omitempty"`
	// ShorName is the string used in a fragment file to indicate what section the fragment is for.
	ShortName string `toml:"short_name,omitempty" yaml:"short_name,omitempty"`
	// ShowAlways is a boolean indicating whether to show the section even if there are no news items.
	// This is a pointer so that we can use omitempty, and still render false values.
	ShowAlways *bool `toml:"show_always,omitempty" yaml:"show_always,omitempty"`
}

Section represents a group of news items in a release.

Jump to

Keyboard shortcuts

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