2019-11-17 16:17:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-02-14 22:42:22 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2019-11-17 16:17:24 +00:00
|
|
|
"log"
|
2021-02-14 22:42:22 +00:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"sv4git/sv"
|
2019-11-17 16:17:24 +00:00
|
|
|
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
2021-02-14 22:42:22 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2019-11-17 16:17:24 +00:00
|
|
|
)
|
|
|
|
|
2021-02-14 22:42:22 +00:00
|
|
|
// EnvConfig env vars for cli configuration
|
|
|
|
type EnvConfig struct {
|
|
|
|
Home string `envconfig:"SV4GIT_HOME" default:""`
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-14 22:42:22 +00:00
|
|
|
func loadEnvConfig() EnvConfig {
|
|
|
|
var c EnvConfig
|
2021-02-14 23:02:11 +00:00
|
|
|
err := envconfig.Process("", &c)
|
2019-11-17 16:17:24 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
2021-02-14 22:42:22 +00:00
|
|
|
|
|
|
|
// Config cli yaml config
|
|
|
|
type Config struct {
|
|
|
|
Version string `yaml:"version"`
|
|
|
|
Versioning sv.VersioningConfig `yaml:"versioning"`
|
|
|
|
Tag sv.TagConfig `yaml:"tag"`
|
|
|
|
ReleaseNotes sv.ReleaseNotesConfig `yaml:"release-notes"`
|
|
|
|
Branches sv.BranchesConfig `yaml:"branches"`
|
|
|
|
CommitMessage sv.CommitMessageConfig `yaml:"commit-message"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRepoPath() (string, error) {
|
|
|
|
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.New(string(out))
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(out)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfig(filepath string) (Config, error) {
|
|
|
|
content, rerr := ioutil.ReadFile(filepath)
|
|
|
|
if rerr != nil {
|
|
|
|
return Config{}, rerr
|
|
|
|
}
|
|
|
|
|
|
|
|
var cfg Config
|
|
|
|
cerr := yaml.Unmarshal(content, &cfg)
|
|
|
|
if cerr != nil {
|
|
|
|
return Config{}, fmt.Errorf("could not parse config from path: %s, error: %v", filepath, cerr)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfig() Config {
|
|
|
|
return Config{
|
|
|
|
Version: "1.0",
|
|
|
|
Versioning: sv.VersioningConfig{
|
|
|
|
UpdateMajor: []string{},
|
|
|
|
UpdateMinor: []string{"feat"},
|
|
|
|
UpdatePatch: []string{"build", "ci", "chore", "docs", "fix", "perf", "refactor", "style", "test"},
|
|
|
|
IgnoreUnknown: false,
|
|
|
|
},
|
|
|
|
Tag: sv.TagConfig{Pattern: "%d.%d.%d"},
|
|
|
|
ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"fix": "Bug Fixes", "feat": "Features", "breaking-change": "Breaking Changes"}},
|
|
|
|
Branches: sv.BranchesConfig{
|
|
|
|
PrefixRegex: "([a-z]+\\/)?",
|
|
|
|
SuffixRegex: "(-.*)?",
|
|
|
|
DisableIssue: false,
|
|
|
|
Skip: []string{"master", "main", "developer"},
|
|
|
|
},
|
|
|
|
CommitMessage: sv.CommitMessageConfig{
|
|
|
|
Types: []string{"build", "ci", "chore", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"},
|
|
|
|
Scope: sv.CommitMessageScopeConfig{},
|
|
|
|
Footer: map[string]sv.CommitMessageFooterConfig{
|
2021-02-15 03:05:43 +00:00
|
|
|
"issue": {Key: "jira", KeySynonyms: []string{"Jira", "JIRA"}},
|
2021-02-14 22:42:22 +00:00
|
|
|
},
|
|
|
|
Issue: sv.CommitMessageIssueConfig{Regex: "[A-Z]+-[0-9]+"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|