core

package
v0.0.0-...-3b66f18 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: MPL-2.0 Imports: 22 Imported by: 0

README

core

Package core provides core functionality for GitHub config to terraform file conversion

Constants

const (
    RepositoryTemplateType       = "repository"
    BranchTemplateType           = "branch"
    BranchProtectionTemplateType = "branch protection"

    TemplateMaxDepth = 10
    TemplateMaxCount = 10
)
const (
    DefaultBranchIdentifier = "default"
)

Variables

var (
    ErrRepositoryNameIsMandatory = errors.New("repository name is mandatory")

    ErrWorkspacePathDoesntExist              = errors.New("workspace path doesn't exist")
    ErrWorkspacePathIsExpectedToBeADirectory = errors.New("workspace path is expected to be a directory")

    ErrNoTemplateAvailable                 = errors.New("not found as none available")
    ErrNoRepositoryTemplateAvailable       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrNoTemplateAvailable)
    ErrNoBranchTemplateAvailable           = fmt.Errorf("%s template %w", BranchTemplateType, ErrNoTemplateAvailable)
    ErrNoBranchProtectionTemplateAvailable = fmt.Errorf(
        "%s template %w",
        BranchProtectionTemplateType,
        ErrNoTemplateAvailable,
    )

    ErrTemplateNotFound                 = errors.New("not found")
    ErrRepositoryTemplateNotFound       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrTemplateNotFound)
    ErrBranchTemplateNotFound           = fmt.Errorf("%s template %w", BranchTemplateType, ErrTemplateNotFound)
    ErrBranchProtectionTemplateNotFound = fmt.Errorf("%s template %w", BranchProtectionTemplateType, ErrTemplateNotFound)

    ErrMaxTemplateCount = errors.New("maximum template count reached")
    ErrMaxTemplateDepth = errors.New("maximum template depth reached")

    ErrDuringWriteTerraformFiles = errors.New("error while writing terraform files")
    ErrDuringFileGeneration      = errors.New("error while generating files")
    ErrDuringComputation         = errors.New("error during computation")

    ErrSchemaValidation        = errors.New("schema validation error")
    ErrEmptySchema             = errors.New("empty schema")
    ErrSchemaNotFound          = errors.New("schema not found")
    ErrSchemaIsNil             = errors.New("schema is nil")
    ErrDuringSchemaCompilation = errors.New("error during schema compilation")

    ErrFileError             = errors.New("file")
    ErrBranchError           = errors.New("branch")
    ErrDefaultBranchError    = errors.New("default branch")
    ErrBranchProtectionError = errors.New("branch protection")
)
var (
    //nolint:gochecknoglobals //Easier to manage it as exported variable
    YamlAnchorDirectory *string
    //nolint:gochecknoglobals //Easier to manage it as exported variable
    Schemas = &SchemaList{
        "map:///repo.json":                              {Content: &repositoryConfigSchema},
        "map:///repos.json":                             {Content: &repositoriesConfigSchema},
        "map:///branch-protection.json":                 {Content: &branchProtectionSchema},
        "map:///branch-protection-template.json":        {Content: &branchProtectionTemplateSchema},
        "map:///branch-branch-protection.json":          {Content: &branchBranchProtectionSchema},
        "map:///branch-branch-protection-template.json": {Content: &branchBranchProtectionTemplateSchema},
        "map:///branch-template.json":                   {Content: &branchTemplateSchema},
        "map:///branch.json":                            {Content: &branchSchema},
        "map:///default-branch.json":                    {Content: &defaultBranchSchema},
        "map:///repo-template.json":                     {Content: &repositoryTemplateSchema},
    }
)

Functions

func ApplyBranchProtectionsTemplate

func ApplyBranchProtectionsTemplate(config *GhRepoConfig, templates *TemplatesConfig) error

func ApplyBranchesTemplate

func ApplyBranchesTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) error

func BranchError

func BranchError(branch string, err error) error

func BranchProtectionError

func BranchProtectionError(index int, err error) error

func ComputationError

func ComputationError(errList []error) error

func ConfigTrace

func ConfigTrace[T GhRepoConfig | Config](header string, c *T)

func DefaultBranchError

func DefaultBranchError(err error) error

func EmptySchemaError

func EmptySchemaError(url string) error

func FileError

func FileError(filepath string, err error) error

func FileGenerationError

func FileGenerationError(msgList []string) error

func GenerateHclRepoFiles

func GenerateHclRepoFiles(configList []*GhRepoConfig) (map[string]*hclwrite.File, error)

func JoinErrors

func JoinErrors(errList []error, separator string) error

func LoadTemplate

func LoadTemplate[T any]( tplName string, loaderFn func(s string) *T, finderFn func(c *T) *[]string, tplType string, path ...string, ) ([]*T, error)

func LoadTemplateList

func LoadTemplateList[T any]( tplNameList *[]string, loaderFn func(s string) *T, finderFn func(c *T) *[]string, tplType string, path ...string, ) ([]*T, error)

func MapBranchToBranchProtectionRes

func MapBranchToBranchProtectionRes( pattern *string, protection *BaseGhBranchProtectionConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapDefaultBranchToBranchProtectionRes

func MapDefaultBranchToBranchProtectionRes( branchConfig *GhDefaultBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapToBranchProtectionRes

func MapToBranchProtectionRes( branchProtectionConfig *GhBranchProtectionConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchprotect.Config

func MapToBranchRes

func MapToBranchRes( name string, branchConfig *GhBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranch.Config

func MapToDefaultBranchRes

func MapToDefaultBranchRes( branchConfig *GhDefaultBranchConfig, valGen tfsig.ValueGenerator, repo *GhRepoConfig, repoTfId string, links ...MapperLink, ) *ghbranchdefault.Config

func MapToRepositoryRes

func MapToRepositoryRes(repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator, repoTfId string) *ghrepository.Config

func MapToSortedList

func MapToSortedList[T any](list map[string]T) []T

func MapToSortedListWithKeys

func MapToSortedListWithKeys[T any](list map[string]T) ([]string, []T)

func MaxTemplateCountReachedError

func MaxTemplateCountReachedError(tplType string, path []string) error

func MaxTemplateDepthReachedError

func MaxTemplateDepthReachedError(tplType string, path []string) error

func NewHclRepository

func NewHclRepository(repoTfId string, repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator) *hclwrite.File

func NoTemplateAvailableError

func NoTemplateAvailableError(tplType string) error

func RepositoryNameIsMandatoryForConfigIndexError

func RepositoryNameIsMandatoryForConfigIndexError(index int) error

func RepositoryNameIsMandatoryForRepoError

func RepositoryNameIsMandatoryForRepoError(index int) error

func SchemaCompilationError

func SchemaCompilationError(url string, msg string) error

func SchemaIsNilError

func SchemaIsNilError(url string) error

func SchemaNotFoundError

func SchemaNotFoundError(url string) error

func SchemaValidationError

func SchemaValidationError(path string, location string, msg string) error

func TerraformFileWritingErrors

func TerraformFileWritingErrors(errList []error) error

func UnknownTemplateError

func UnknownTemplateError(tplType string, tplName string) error

func ValidateBranchProtectionTemplateConfig

func ValidateBranchProtectionTemplateConfig(filePath string) error

func ValidateBranchTemplateConfig

func ValidateBranchTemplateConfig(filePath string) error

func ValidateRepositoryConfig

func ValidateRepositoryConfig(filePath string) error

func ValidateRepositoryConfigs

func ValidateRepositoryConfigs(filePath string) error

func ValidateRepositoryTemplateConfig

func ValidateRepositoryTemplateConfig(filePath string) error

func WorkspacePathDoesntExistError

func WorkspacePathDoesntExistError(path string) error

func WorkspacePathIsExpectedToBeADirectoryError

func WorkspacePathIsExpectedToBeADirectoryError(path string) error

func WriteTerraformFiles

func WriteTerraformFiles(rootPath string, files map[string]*hclwrite.File) error

Types

type BaseGhBranchConfig

type BaseGhBranchConfig struct { ... }

func (*BaseGhBranchConfig) Merge

func (to *BaseGhBranchConfig) Merge(from *BaseGhBranchConfig)

type BaseGhBranchProtectionConfig

type BaseGhBranchProtectionConfig struct { ... }

func (*BaseGhBranchProtectionConfig) Merge

func (to *BaseGhBranchProtectionConfig) Merge(from *BaseGhBranchProtectionConfig)

type Config

type Config struct { ... }

func ComputeConfig

func ComputeConfig(config *Config) (*Config, error)

func NewConfig

func NewConfig() *Config

func (*Config) AppendRepo

func (c *Config) AppendRepo(repo *GhRepoConfig)

func (*Config) GetRepo

func (c *Config) GetRepo(name string) *GhRepoConfig

type GhBranchConfig

type GhBranchConfig struct { ... }

func ApplyBranchTemplate

func ApplyBranchTemplate(branchConfig *GhBranchConfig, templates *TemplatesConfig) (*GhBranchConfig, error)

func LoadBranchTemplateFromFile

func LoadBranchTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhBranchConfig, error)

func LoadGhRepoBranchConfigFromFile

func LoadGhRepoBranchConfigFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchConfig, error)

LoadGhRepoBranchConfigFromFile loads the file content to GhBranchConfig struct No schema validation will be performed, use loadBranchTemplateFromFile instead !

func (*GhBranchConfig) Merge

func (to *GhBranchConfig) Merge(from *GhBranchConfig)

type GhBranchProtectPRReviewConfig

type GhBranchProtectPRReviewConfig struct { ... }

func (*GhBranchProtectPRReviewConfig) Merge

func (to *GhBranchProtectPRReviewConfig) Merge(from *GhBranchProtectPRReviewConfig)

type GhBranchProtectPRReviewDismissalsConfig

type GhBranchProtectPRReviewDismissalsConfig struct { ... }

func (*GhBranchProtectPRReviewDismissalsConfig) Merge

func (to *GhBranchProtectPRReviewDismissalsConfig) Merge(from *GhBranchProtectPRReviewDismissalsConfig)

type GhBranchProtectPushesConfig

type GhBranchProtectPushesConfig struct { ... }

func (*GhBranchProtectPushesConfig) Merge

func (to *GhBranchProtectPushesConfig) Merge(from *GhBranchProtectPushesConfig)

type GhBranchProtectStatusChecksConfig

type GhBranchProtectStatusChecksConfig struct { ... }

func (*GhBranchProtectStatusChecksConfig) Merge

func (to *GhBranchProtectStatusChecksConfig) Merge(from *GhBranchProtectStatusChecksConfig)

type GhBranchProtectionConfig

type GhBranchProtectionConfig struct { ... }

func ApplyBranchProtectionTemplate

func ApplyBranchProtectionTemplate( branchProtectionConfig *GhBranchProtectionConfig, templates *TemplatesConfig, ) (*GhBranchProtectionConfig, error)

func LoadBranchProtectionTemplateFromFile

func LoadBranchProtectionTemplateFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchProtectionConfig, error)

func LoadGhRepoBranchProtectionConfigFromFile

func LoadGhRepoBranchProtectionConfigFromFile( filePath string, decoderOpts ...yaml.DecodeOption, ) (*GhBranchProtectionConfig, error)

LoadGhRepoBranchProtectionConfigFromFile loads the file content to GhBranchProtectionConfig struct No schema validation will be performed, use loadBranchProtectionTemplateFromFile instead !

func (*GhBranchProtectionConfig) Merge

func (to *GhBranchProtectionConfig) Merge(from *GhBranchProtectionConfig)

type GhBranchProtectionsConfig

type GhBranchProtectionsConfig []*GhBranchProtectionConfig

func (*GhBranchProtectionsConfig) Merge

func (to *GhBranchProtectionsConfig) Merge(from *GhBranchProtectionsConfig)

type GhBranchesConfig

type GhBranchesConfig map[string]*GhBranchConfig

func (*GhBranchesConfig) Merge

func (to *GhBranchesConfig) Merge(from *GhBranchesConfig)

type GhDefaultBranchConfig

type GhDefaultBranchConfig struct { ... }

func (*GhDefaultBranchConfig) Merge

func (to *GhDefaultBranchConfig) Merge(from *GhDefaultBranchConfig)

type GhRepoConfig

type GhRepoConfig struct { ... }

func ApplyRepositoryTemplate

func ApplyRepositoryTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func ComputeRepoConfig

func ComputeRepoConfig(base *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func LoadGhRepoConfigFromFile

func LoadGhRepoConfigFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

LoadGhRepoConfigFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoryFromFile or loadRepositoryTemplateFromFile instead !

func LoadGhRepoConfigListFromFile

func LoadGhRepoConfigListFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

LoadGhRepoConfigListFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoriesFromFile instead !

func LoadRepositoriesFromFile

func LoadRepositoriesFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

func LoadRepositoryFromFile

func LoadRepositoryFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func LoadRepositoryTemplateFromFile

func LoadRepositoryTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func (*GhRepoConfig) Merge

func (to *GhRepoConfig) Merge(from *GhRepoConfig)

type GhRepoFileTemplatesConfig

type GhRepoFileTemplatesConfig struct { ... }

func (*GhRepoFileTemplatesConfig) Merge

func (to *GhRepoFileTemplatesConfig) Merge(from *GhRepoFileTemplatesConfig)

type GhRepoMiscellaneousConfig

type GhRepoMiscellaneousConfig struct { ... }

func (*GhRepoMiscellaneousConfig) Merge

func (to *GhRepoMiscellaneousConfig) Merge(from *GhRepoMiscellaneousConfig)

type GhRepoPRBranchConfig

type GhRepoPRBranchConfig struct { ... }

func (*GhRepoPRBranchConfig) Merge

func (to *GhRepoPRBranchConfig) Merge(from *GhRepoPRBranchConfig)

type GhRepoPRCommitConfig

type GhRepoPRCommitConfig struct { ... }

func (*GhRepoPRCommitConfig) Merge

func (to *GhRepoPRCommitConfig) Merge(from *GhRepoPRCommitConfig)

type GhRepoPRMergeStrategyConfig

type GhRepoPRMergeStrategyConfig struct { ... }

func (*GhRepoPRMergeStrategyConfig) Merge

func (to *GhRepoPRMergeStrategyConfig) Merge(from *GhRepoPRMergeStrategyConfig)

type GhRepoPagesConfig

type GhRepoPagesConfig struct { ... }

func (*GhRepoPagesConfig) Merge

func (to *GhRepoPagesConfig) Merge(from *GhRepoPagesConfig)

type GhRepoPullRequestConfig

type GhRepoPullRequestConfig struct { ... }

func (*GhRepoPullRequestConfig) Merge

func (to *GhRepoPullRequestConfig) Merge(from *GhRepoPullRequestConfig)

type GhRepoSecurityConfig

type GhRepoSecurityConfig struct { ... }

func (*GhRepoSecurityConfig) Merge

func (to *GhRepoSecurityConfig) Merge(from *GhRepoSecurityConfig)

type GhRepoTemplateConfig

type GhRepoTemplateConfig struct { ... }

func (*GhRepoTemplateConfig) Merge

func (to *GhRepoTemplateConfig) Merge(from *GhRepoTemplateConfig)

type GhRepoTerraformConfig

type GhRepoTerraformConfig struct { ... }

func (*GhRepoTerraformConfig) Merge

func (to *GhRepoTerraformConfig) Merge(from *GhRepoTerraformConfig)

type MapperLink int

Constants
const (
    LinkToRepository MapperLink = iota
    LinkToBranch
)
type Schema

type Schema struct { ... }

type SchemaList

type SchemaList map[string]*Schema

func (*SchemaList) Compile

func (s *SchemaList) Compile(url string) (*jsonschema.Schema, error)

func (*SchemaList) Find

func (s *SchemaList) Find(url string) (*Schema, error)

func (*SchemaList) FindCompiled

func (s *SchemaList) FindCompiled(url string) *jsonschema.Schema

func (*SchemaList) FindContent

func (s *SchemaList) FindContent(url string) (*string, error)

type TemplatesConfig

type TemplatesConfig struct { ... }

func (*TemplatesConfig) GetBranch

func (c *TemplatesConfig) GetBranch(name string) *GhBranchConfig

func (*TemplatesConfig) GetBranchProtection

func (c *TemplatesConfig) GetBranchProtection(name string) *GhBranchProtectionConfig

func (*TemplatesConfig) GetRepo

func (c *TemplatesConfig) GetRepo(name string) *GhRepoConfig


Readme created from Go doc with goreadme

Documentation

Overview

Package core provides core functionality for GitHub config to terraform file conversion

Index

Constants

View Source
const (
	RepositoryTemplateType       = "repository"
	BranchTemplateType           = "branch"
	BranchProtectionTemplateType = "branch protection"

	TemplateMaxDepth = 10
	TemplateMaxCount = 10
)
View Source
const (
	DefaultBranchIdentifier = "default"
)

Variables

View Source
var (
	ErrRepositoryNameIsMandatory = errors.New("repository name is mandatory")

	ErrWorkspacePathDoesntExist              = errors.New("workspace path doesn't exist")
	ErrWorkspacePathIsExpectedToBeADirectory = errors.New("workspace path is expected to be a directory")

	ErrNoTemplateAvailable                 = errors.New("not found as none available")
	ErrNoRepositoryTemplateAvailable       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrNoTemplateAvailable)
	ErrNoBranchTemplateAvailable           = fmt.Errorf("%s template %w", BranchTemplateType, ErrNoTemplateAvailable)
	ErrNoBranchProtectionTemplateAvailable = fmt.Errorf(
		"%s template %w",
		BranchProtectionTemplateType,
		ErrNoTemplateAvailable,
	)

	ErrTemplateNotFound                 = errors.New("not found")
	ErrRepositoryTemplateNotFound       = fmt.Errorf("%s template %w", RepositoryTemplateType, ErrTemplateNotFound)
	ErrBranchTemplateNotFound           = fmt.Errorf("%s template %w", BranchTemplateType, ErrTemplateNotFound)
	ErrBranchProtectionTemplateNotFound = fmt.Errorf("%s template %w", BranchProtectionTemplateType, ErrTemplateNotFound)

	ErrMaxTemplateCount = errors.New("maximum template count reached")
	ErrMaxTemplateDepth = errors.New("maximum template depth reached")

	ErrDuringWriteTerraformFiles = errors.New("error while writing terraform files")
	ErrDuringFileGeneration      = errors.New("error while generating files")
	ErrDuringComputation         = errors.New("error during computation")

	ErrSchemaValidation        = errors.New("schema validation error")
	ErrEmptySchema             = errors.New("empty schema")
	ErrSchemaNotFound          = errors.New("schema not found")
	ErrSchemaIsNil             = errors.New("schema is nil")
	ErrDuringSchemaCompilation = errors.New("error during schema compilation")

	ErrFileError             = errors.New("file")
	ErrBranchError           = errors.New("branch")
	ErrDefaultBranchError    = errors.New("default branch")
	ErrBranchProtectionError = errors.New("branch protection")
)
View Source
var (
	//nolint:gochecknoglobals //Easier to manage it as exported variable
	YamlAnchorDirectory *string
	//nolint:gochecknoglobals //Easier to manage it as exported variable
	Schemas = &SchemaList{
		"map:///repo.json":                              {Content: &repositoryConfigSchema},
		"map:///repos.json":                             {Content: &repositoriesConfigSchema},
		"map:///branch-protection.json":                 {Content: &branchProtectionSchema},
		"map:///branch-protection-template.json":        {Content: &branchProtectionTemplateSchema},
		"map:///branch-branch-protection.json":          {Content: &branchBranchProtectionSchema},
		"map:///branch-branch-protection-template.json": {Content: &branchBranchProtectionTemplateSchema},
		"map:///branch-template.json":                   {Content: &branchTemplateSchema},
		"map:///branch.json":                            {Content: &branchSchema},
		"map:///default-branch.json":                    {Content: &defaultBranchSchema},
		"map:///repo-template.json":                     {Content: &repositoryTemplateSchema},
	}
)

Functions

func ApplyBranchProtectionsTemplate

func ApplyBranchProtectionsTemplate(config *GhRepoConfig, templates *TemplatesConfig) error

func ApplyBranchesTemplate

func ApplyBranchesTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) error

func BranchError

func BranchError(branch string, err error) error

func BranchProtectionError

func BranchProtectionError(index int, err error) error

func ComputationError

func ComputationError(errList []error) error

func ConfigTrace

func ConfigTrace[T GhRepoConfig | Config](header string, c *T)

func DefaultBranchError

func DefaultBranchError(err error) error

func EmptySchemaError

func EmptySchemaError(url string) error

func FileError

func FileError(filepath string, err error) error

func FileGenerationError

func FileGenerationError(msgList []string) error

func GenerateHclRepoFiles

func GenerateHclRepoFiles(configList []*GhRepoConfig) (map[string]*hclwrite.File, error)

func JoinErrors

func JoinErrors(errList []error, separator string) error

func LoadTemplate

func LoadTemplate[T any](
	tplName string,
	loaderFn func(s string) *T,
	finderFn func(c *T) *[]string,
	tplType string,
	path ...string,
) ([]*T, error)

func LoadTemplateList

func LoadTemplateList[T any](
	tplNameList *[]string,
	loaderFn func(s string) *T,
	finderFn func(c *T) *[]string,
	tplType string,
	path ...string,
) ([]*T, error)

func MapBranchToBranchProtectionRes

func MapBranchToBranchProtectionRes(
	pattern *string,
	protection *BaseGhBranchProtectionConfig,
	valGen tfsig.ValueGenerator,
	repo *GhRepoConfig,
	repoTfId string,
	links ...MapperLink,
) *ghbranchprotect.Config

func MapDefaultBranchToBranchProtectionRes

func MapDefaultBranchToBranchProtectionRes(
	branchConfig *GhDefaultBranchConfig,
	valGen tfsig.ValueGenerator,
	repo *GhRepoConfig,
	repoTfId string,
	links ...MapperLink,
) *ghbranchprotect.Config

func MapToBranchProtectionRes

func MapToBranchProtectionRes(
	branchProtectionConfig *GhBranchProtectionConfig,
	valGen tfsig.ValueGenerator,
	repo *GhRepoConfig,
	repoTfId string,
	links ...MapperLink,
) *ghbranchprotect.Config

func MapToBranchRes

func MapToBranchRes(
	name string,
	branchConfig *GhBranchConfig,
	valGen tfsig.ValueGenerator,
	repo *GhRepoConfig,
	repoTfId string,
	links ...MapperLink,
) *ghbranch.Config

func MapToDefaultBranchRes

func MapToDefaultBranchRes(
	branchConfig *GhDefaultBranchConfig,
	valGen tfsig.ValueGenerator,
	repo *GhRepoConfig,
	repoTfId string,
	links ...MapperLink,
) *ghbranchdefault.Config

func MapToRepositoryRes

func MapToRepositoryRes(repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator, repoTfId string) *ghrepository.Config

func MapToSortedList

func MapToSortedList[T any](list map[string]T) []T

func MapToSortedListWithKeys

func MapToSortedListWithKeys[T any](list map[string]T) ([]string, []T)

func MaxTemplateCountReachedError

func MaxTemplateCountReachedError(tplType string, path []string) error

func MaxTemplateDepthReachedError

func MaxTemplateDepthReachedError(tplType string, path []string) error

func NewHclRepository

func NewHclRepository(repoTfId string, repoConfig *GhRepoConfig, valGen tfsig.ValueGenerator) *hclwrite.File

func NoTemplateAvailableError

func NoTemplateAvailableError(tplType string) error

func RepositoryNameIsMandatoryForConfigIndexError

func RepositoryNameIsMandatoryForConfigIndexError(index int) error

func RepositoryNameIsMandatoryForRepoError

func RepositoryNameIsMandatoryForRepoError(index int) error

func SchemaCompilationError

func SchemaCompilationError(url string, msg string) error

func SchemaIsNilError

func SchemaIsNilError(url string) error

func SchemaNotFoundError

func SchemaNotFoundError(url string) error

func SchemaValidationError

func SchemaValidationError(path string, location string, msg string) error

func TerraformFileWritingErrors

func TerraformFileWritingErrors(errList []error) error

func UnknownTemplateError

func UnknownTemplateError(tplType string, tplName string) error

func ValidateBranchProtectionTemplateConfig

func ValidateBranchProtectionTemplateConfig(filePath string) error

func ValidateBranchTemplateConfig

func ValidateBranchTemplateConfig(filePath string) error

func ValidateRepositoryConfig

func ValidateRepositoryConfig(filePath string) error

func ValidateRepositoryConfigs

func ValidateRepositoryConfigs(filePath string) error

func ValidateRepositoryTemplateConfig

func ValidateRepositoryTemplateConfig(filePath string) error

func WorkspacePathDoesntExistError

func WorkspacePathDoesntExistError(path string) error

func WorkspacePathIsExpectedToBeADirectoryError

func WorkspacePathIsExpectedToBeADirectoryError(path string) error

func WriteTerraformFiles

func WriteTerraformFiles(rootPath string, files map[string]*hclwrite.File) error

Types

type BaseGhBranchConfig

type BaseGhBranchConfig struct {
	//nolint:tagliatelle // yaml templates, not config templates => better to use underscore here
	ConfigTemplates *[]string `yaml:"_templates,omitempty,flow"`

	Protection *BaseGhBranchProtectionConfig `yaml:"protection,omitempty"`
}

func (*BaseGhBranchConfig) Merge

func (to *BaseGhBranchConfig) Merge(from *BaseGhBranchConfig)

type BaseGhBranchProtectionConfig

type BaseGhBranchProtectionConfig struct {
	//nolint:tagliatelle // yaml templates, not config templates => better to use underscore here
	ConfigTemplates *[]string `yaml:"_templates,omitempty,flow"`

	EnforceAdmins *string `yaml:"enforce-admins,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowDeletion *string `yaml:"deletion,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'require' prefix (as it's a boolean)
	RequireLinearHistory *string `yaml:"linear-history,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'require' prefix (as it's a boolean)
	RequireSignedCommits *string `yaml:"signed-commits,omitempty"`

	Pushes             *GhBranchProtectPushesConfig       `yaml:"pushes,omitempty"`
	StatusChecks       *GhBranchProtectStatusChecksConfig `yaml:"status-checks,omitempty"`
	PullRequestReviews *GhBranchProtectPRReviewConfig     `yaml:"pull-request-reviews,omitempty"`
}

func (*BaseGhBranchProtectionConfig) Merge

type Config

type Config struct {
	Templates *TemplatesConfig `yaml:"templates,omitempty"`
	Repos     []*GhRepoConfig  `yaml:"repos,omitempty"`
}

func ComputeConfig

func ComputeConfig(config *Config) (*Config, error)

func NewConfig

func NewConfig() *Config

func (*Config) AppendRepo

func (c *Config) AppendRepo(repo *GhRepoConfig)

func (*Config) GetRepo

func (c *Config) GetRepo(name string) *GhRepoConfig

type GhBranchConfig

type GhBranchConfig struct {
	SourceBranch       *string `yaml:"source-branch,omitempty"`
	SourceSha          *string `yaml:"source-sha,omitempty"`
	BaseGhBranchConfig `yaml:",inline"`
}

func ApplyBranchTemplate

func ApplyBranchTemplate(branchConfig *GhBranchConfig, templates *TemplatesConfig) (*GhBranchConfig, error)

func LoadBranchTemplateFromFile

func LoadBranchTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhBranchConfig, error)

func LoadGhRepoBranchConfigFromFile

func LoadGhRepoBranchConfigFromFile(
	filePath string,
	decoderOpts ...yaml.DecodeOption,
) (*GhBranchConfig, error)

LoadGhRepoBranchConfigFromFile loads the file content to GhBranchConfig struct No schema validation will be performed, use loadBranchTemplateFromFile instead !

func (*GhBranchConfig) Merge

func (to *GhBranchConfig) Merge(from *GhBranchConfig)

type GhBranchProtectPRReviewConfig

type GhBranchProtectPRReviewConfig struct {
	Bypassers             *[]string `yaml:"bypassers,omitempty,flow"`
	CodeownerApprovals    *string   `yaml:"codeowner-approvals,omitempty"`
	ResolvedConversations *string   `yaml:"resolved-conversations,omitempty"`
	ApprovalCount         *string   `yaml:"approval-count,omitempty"`

	Dismissals *GhBranchProtectPRReviewDismissalsConfig `yaml:"dismissals,omitempty"`
}

func (*GhBranchProtectPRReviewConfig) Merge

type GhBranchProtectPRReviewDismissalsConfig

type GhBranchProtectPRReviewDismissalsConfig struct {
	Staled     *string   `yaml:"staled,omitempty"`
	Restrict   *string   `yaml:"restrict,omitempty"`
	RestrictTo *[]string `yaml:"restrict-to,omitempty,flow"`
}

func (*GhBranchProtectPRReviewDismissalsConfig) Merge

type GhBranchProtectPushesConfig

type GhBranchProtectPushesConfig struct {
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowsForcePushes *string   `yaml:"force-push,omitempty"`
	RestrictTo        *[]string `yaml:"restrict-to,omitempty,flow"`
}

func (*GhBranchProtectPushesConfig) Merge

type GhBranchProtectStatusChecksConfig

type GhBranchProtectStatusChecksConfig struct {
	Strict   *string   `yaml:"strict,omitempty"`
	Required *[]string `yaml:"required,omitempty,flow"`
}

func (*GhBranchProtectStatusChecksConfig) Merge

type GhBranchProtectionConfig

type GhBranchProtectionConfig struct {
	Pattern                      *string `yaml:"pattern,omitempty"`
	Forbid                       *string `yaml:"forbid,omitempty"`
	BaseGhBranchProtectionConfig `yaml:",inline"`
}

func ApplyBranchProtectionTemplate

func ApplyBranchProtectionTemplate(
	branchProtectionConfig *GhBranchProtectionConfig,
	templates *TemplatesConfig,
) (*GhBranchProtectionConfig, error)

func LoadBranchProtectionTemplateFromFile

func LoadBranchProtectionTemplateFromFile(
	filePath string,
	decoderOpts ...yaml.DecodeOption,
) (*GhBranchProtectionConfig, error)

func LoadGhRepoBranchProtectionConfigFromFile

func LoadGhRepoBranchProtectionConfigFromFile(
	filePath string,
	decoderOpts ...yaml.DecodeOption,
) (*GhBranchProtectionConfig, error)

LoadGhRepoBranchProtectionConfigFromFile loads the file content to GhBranchProtectionConfig struct No schema validation will be performed, use loadBranchProtectionTemplateFromFile instead !

func (*GhBranchProtectionConfig) Merge

type GhBranchProtectionsConfig

type GhBranchProtectionsConfig []*GhBranchProtectionConfig

func (*GhBranchProtectionsConfig) Merge

type GhBranchesConfig

type GhBranchesConfig map[string]*GhBranchConfig

func (*GhBranchesConfig) Merge

func (to *GhBranchesConfig) Merge(from *GhBranchesConfig)

type GhDefaultBranchConfig

type GhDefaultBranchConfig struct {
	Name               *string `yaml:"name,omitempty"`
	BaseGhBranchConfig `yaml:",inline"`
}

func (*GhDefaultBranchConfig) Merge

type GhRepoConfig

type GhRepoConfig struct {
	Name *string `yaml:"name,omitempty"`
	//nolint:tagliatelle // yaml templates, not config templates => better to use underscore here
	ConfigTemplates   *[]string                  `yaml:"_templates,omitempty,flow"`
	Visibility        *string                    `yaml:"visibility,omitempty"`
	Description       *string                    `yaml:"description,omitempty"`
	DefaultBranch     *GhDefaultBranchConfig     `yaml:"default-branch,omitempty"`
	Branches          *GhBranchesConfig          `yaml:"branches,omitempty"`
	BranchProtections *GhBranchProtectionsConfig `yaml:"branch-protections,omitempty"`
	PullRequests      *GhRepoPullRequestConfig   `yaml:"pull-requests,omitempty"`
	Security          *GhRepoSecurityConfig      `yaml:"security,omitempty"`
	//nolint:tagliatelle // Long name, easier if it's just misc
	Miscellaneous *GhRepoMiscellaneousConfig `yaml:"misc,omitempty"`
	Terraform     *GhRepoTerraformConfig     `yaml:"terraform,omitempty"`
}

func ApplyRepositoryTemplate

func ApplyRepositoryTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func ComputeRepoConfig

func ComputeRepoConfig(base *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)

func LoadGhRepoConfigFromFile

func LoadGhRepoConfigFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

LoadGhRepoConfigFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoryFromFile or loadRepositoryTemplateFromFile instead !

func LoadGhRepoConfigListFromFile

func LoadGhRepoConfigListFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

LoadGhRepoConfigListFromFile loads the file content to GhRepoConfig struct No schema validation will be performed, use loadRepositoriesFromFile instead !

func LoadRepositoriesFromFile

func LoadRepositoriesFromFile(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

func LoadRepositoryFromFile

func LoadRepositoryFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func LoadRepositoryTemplateFromFile

func LoadRepositoryTemplateFromFile(filePath string, decoderOpts ...yaml.DecodeOption) (*GhRepoConfig, error)

func (*GhRepoConfig) Merge

func (to *GhRepoConfig) Merge(from *GhRepoConfig)

type GhRepoFileTemplatesConfig

type GhRepoFileTemplatesConfig struct {
	Gitignore *string `yaml:"gitignore,omitempty"`
	License   *string `yaml:"license,omitempty"`
}

func (*GhRepoFileTemplatesConfig) Merge

type GhRepoMiscellaneousConfig

type GhRepoMiscellaneousConfig struct {
	Topics      *[]string `yaml:"topics,omitempty,flow"`
	AutoInit    *string   `yaml:"auto-init,omitempty"`
	Archived    *string   `yaml:"archived,omitempty"`
	IsTemplate  *string   `yaml:"is-template,omitempty"`
	HomepageUrl *string   `yaml:"homepage-url,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'has' prefix (as it's a boolean)
	HasIssues *string `yaml:"issues,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'has' prefix (as it's a boolean)
	HasWiki *string `yaml:"wiki,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'has' prefix (as it's a boolean)
	HasProjects *string `yaml:"projects,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'has' prefix (as it's a boolean)
	HasDownloads  *string                    `yaml:"downloads,omitempty"`
	Template      *GhRepoTemplateConfig      `yaml:"template,omitempty"`
	Pages         *GhRepoPagesConfig         `yaml:"pages,omitempty"`
	FileTemplates *GhRepoFileTemplatesConfig `yaml:"file-templates,omitempty"`
}

func (*GhRepoMiscellaneousConfig) Merge

type GhRepoPRBranchConfig

type GhRepoPRBranchConfig struct {
	SuggestUpdate *string `yaml:"suggest-update,omitempty"`
	DeleteOnMerge *string `yaml:"delete-on-merge,omitempty"`
}

func (*GhRepoPRBranchConfig) Merge

func (to *GhRepoPRBranchConfig) Merge(from *GhRepoPRBranchConfig)

type GhRepoPRCommitConfig

type GhRepoPRCommitConfig struct {
	Title   *string `yaml:"title,omitempty"`
	Message *string `yaml:"message,omitempty"`
}

func (*GhRepoPRCommitConfig) Merge

func (to *GhRepoPRCommitConfig) Merge(from *GhRepoPRCommitConfig)

type GhRepoPRMergeStrategyConfig

type GhRepoPRMergeStrategyConfig struct {
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowMerge *string `yaml:"merge,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowRebase *string `yaml:"rebase,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowSquash *string `yaml:"squash,omitempty"`
	//nolint:tagliatelle // Already make sense for yaml config without the 'allow' prefix (as it's a boolean)
	AllowAutoMerge *string `yaml:"auto-merge,omitempty"`
}

func (*GhRepoPRMergeStrategyConfig) Merge

type GhRepoPagesConfig

type GhRepoPagesConfig struct {
	Domain       *string `yaml:"domain,omitempty"`
	SourceBranch *string `yaml:"source-branch,omitempty"`
	SourcePath   *string `yaml:"source-path,omitempty"`
}

func (*GhRepoPagesConfig) Merge

func (to *GhRepoPagesConfig) Merge(from *GhRepoPagesConfig)

type GhRepoPullRequestConfig

type GhRepoPullRequestConfig struct {
	MergeStrategy *GhRepoPRMergeStrategyConfig `yaml:"merge-strategy,omitempty"`
	MergeCommit   *GhRepoPRCommitConfig        `yaml:"merge-commit,omitempty"`
	SquashCommit  *GhRepoPRCommitConfig        `yaml:"squash-commit,omitempty"`
	Branch        *GhRepoPRBranchConfig        `yaml:"branch,omitempty"`
}

func (*GhRepoPullRequestConfig) Merge

type GhRepoSecurityConfig

type GhRepoSecurityConfig struct {
	VulnerabilityAlerts *string `yaml:"vulnerability-alerts,omitempty"`
}

func (*GhRepoSecurityConfig) Merge

func (to *GhRepoSecurityConfig) Merge(from *GhRepoSecurityConfig)

type GhRepoTemplateConfig

type GhRepoTemplateConfig struct {
	Source    *string `yaml:"source,omitempty"`
	FullClone *string `yaml:"full-clone,omitempty"`
}

func (*GhRepoTemplateConfig) Merge

func (to *GhRepoTemplateConfig) Merge(from *GhRepoTemplateConfig)

type GhRepoTerraformConfig

type GhRepoTerraformConfig struct {
	ArchiveOnDestroy                    *string `yaml:"archive-on-destroy,omitempty"`
	IgnoreVulnerabilityAlertsDuringRead *string `yaml:"ignore-vulnerability-alerts-during-read,omitempty"`
}

func (*GhRepoTerraformConfig) Merge

type MapperLink int
const (
	LinkToRepository MapperLink = iota
	LinkToBranch
)

type Schema

type Schema struct {
	Content *string
	// contains filtered or unexported fields
}

type SchemaList

type SchemaList map[string]*Schema

func (*SchemaList) Compile

func (s *SchemaList) Compile(url string) (*jsonschema.Schema, error)

func (*SchemaList) Find

func (s *SchemaList) Find(url string) (*Schema, error)

func (*SchemaList) FindCompiled

func (s *SchemaList) FindCompiled(url string) *jsonschema.Schema

func (*SchemaList) FindContent

func (s *SchemaList) FindContent(url string) (*string, error)

type TemplatesConfig

type TemplatesConfig struct {
	Repos             map[string]*GhRepoConfig             `yaml:"repos,omitempty"`
	Branches          map[string]*GhBranchConfig           `yaml:"branches,omitempty"`
	BranchProtections map[string]*GhBranchProtectionConfig `yaml:"branch-protections,omitempty"`
}

func (*TemplatesConfig) GetBranch

func (c *TemplatesConfig) GetBranch(name string) *GhBranchConfig

func (*TemplatesConfig) GetBranchProtection

func (c *TemplatesConfig) GetBranchProtection(name string) *GhBranchProtectionConfig

func (*TemplatesConfig) GetRepo

func (c *TemplatesConfig) GetRepo(name string) *GhRepoConfig

Jump to

Keyboard shortcuts

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