Skip to content

Latest commit

 

History

History

core

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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(config *GhRepoConfig, templates *TemplatesConfig) error

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

func BranchError(branch string, err error) error

func BranchProtectionError(index int, err error) error

func ComputationError(errList []error) error

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

func DefaultBranchError(err error) error

func EmptySchemaError(url string) error

func FileError(filepath string, err error) error

func FileGenerationError(msgList []string) error

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func NoTemplateAvailableError(tplType string) error

func RepositoryNameIsMandatoryForConfigIndexError(index int) error

func RepositoryNameIsMandatoryForRepoError(index int) error

func SchemaCompilationError(url string, msg string) error

func SchemaIsNilError(url string) error

func SchemaNotFoundError(url string) error

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

func TerraformFileWritingErrors(errList []error) error

func UnknownTemplateError(tplType string, tplName string) error

func ValidateBranchProtectionTemplateConfig(filePath string) error

func ValidateBranchTemplateConfig(filePath string) error

func ValidateRepositoryConfig(filePath string) error

func ValidateRepositoryConfigs(filePath string) error

func ValidateRepositoryTemplateConfig(filePath string) error

func WorkspacePathDoesntExistError(path string) error

func WorkspacePathIsExpectedToBeADirectoryError(path string) error

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

Types

type BaseGhBranchConfig struct { ... }

func (*BaseGhBranchConfig) Merge

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

type BaseGhBranchProtectionConfig struct { ... }

func (*BaseGhBranchProtectionConfig) Merge

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

type Config

type Config struct { ... }

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

func NewConfig() *Config

func (*Config) AppendRepo

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

func (*Config) GetRepo

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

type GhBranchConfig struct { ... }

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

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

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 struct { ... }

func (*GhBranchProtectPRReviewConfig) Merge

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

type GhBranchProtectPRReviewDismissalsConfig struct { ... }

func (*GhBranchProtectPRReviewDismissalsConfig) Merge

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

type GhBranchProtectPushesConfig struct { ... }

func (*GhBranchProtectPushesConfig) Merge

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

type GhBranchProtectStatusChecksConfig struct { ... }

func (*GhBranchProtectStatusChecksConfig) Merge

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

type GhBranchProtectionConfig struct { ... }

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

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

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 []*GhBranchProtectionConfig

func (*GhBranchProtectionsConfig) Merge

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

type GhBranchesConfig map[string]*GhBranchConfig

func (*GhBranchesConfig) Merge

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

type GhDefaultBranchConfig struct { ... }

func (*GhDefaultBranchConfig) Merge

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

type GhRepoConfig struct { ... }

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

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

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(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(filePath string, decoderOpts ...yaml.DecodeOption) ([]*GhRepoConfig, error)

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

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

func (*GhRepoConfig) Merge

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

type GhRepoFileTemplatesConfig struct { ... }

func (*GhRepoFileTemplatesConfig) Merge

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

type GhRepoMiscellaneousConfig struct { ... }

func (*GhRepoMiscellaneousConfig) Merge

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

type GhRepoPRBranchConfig struct { ... }

func (*GhRepoPRBranchConfig) Merge

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

type GhRepoPRCommitConfig struct { ... }

func (*GhRepoPRCommitConfig) Merge

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

type GhRepoPRMergeStrategyConfig struct { ... }

func (*GhRepoPRMergeStrategyConfig) Merge

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

type GhRepoPagesConfig struct { ... }

func (*GhRepoPagesConfig) Merge

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

type GhRepoPullRequestConfig struct { ... }

func (*GhRepoPullRequestConfig) Merge

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

type GhRepoSecurityConfig struct { ... }

func (*GhRepoSecurityConfig) Merge

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

type GhRepoTemplateConfig struct { ... }

func (*GhRepoTemplateConfig) Merge

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

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 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 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