chore(config): add providers default domains, git providers can now specify a custom provider url for supported providers, add releaseTitle in config

This commit is contained in:
Felix Wiedmann
2019-06-13 23:31:14 +02:00
parent 374548c454
commit cd362c63bd
2 changed files with 22 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ import (
)
// List of all supported git providers
var gitPorviders = map[string]string{"GitHub": "", "GitLab": ""}
var gitProviders = map[string]string{"GitHub": "https://github.com/", "GitLab": "https://gitlab.com/"}
// ChangelogConfig struct
type ChangelogConfig struct {
@@ -23,10 +23,11 @@ type ChangelogConfig struct {
// GitProvider struct
type GitProvider struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
User string `yaml:"user"`
AccessToken string
Name string `yaml:"name"`
Repo string `yaml:"repo"`
User string `yaml:"user"`
customProviderURL string `yaml:"customURL"`
AccessToken string
}
//Asset type struct
@@ -43,6 +44,7 @@ type ReleaseConfig struct {
Release string `yaml:"release,omitempty"`
GitProvider GitProvider `yaml:"provider,omitempty"`
Assets []Asset `yaml:"assets"`
ReleaseTitle string `yaml:"title"`
IsPreRelease, IsDraft bool
}
@@ -71,14 +73,14 @@ func Read(configPath string) (*ReleaseConfig, error) {
func checkProvider(config ReleaseConfig) (ReleaseConfig, error) {
if config.GitProvider != (GitProvider{}) {
if _, ok := gitPorviders[config.GitProvider.Name]; !ok {
if _, ok := gitProviders[config.GitProvider.Name]; !ok {
return ReleaseConfig{}, fmt.Errorf("config: provider: configured provider %s is not supported", config.GitProvider.Name)
}
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(config.GitProvider.Name))
token, isSet := os.LookupEnv(envName)
if !isSet {
return ReleaseConfig{}, fmt.Errorf("config: Can not find environment variable %s", token)
return ReleaseConfig{}, fmt.Errorf("config: Can not find environment variable %s", envName)
}
config.GitProvider.AccessToken = token
} else {
@@ -86,3 +88,12 @@ func checkProvider(config ReleaseConfig) (ReleaseConfig, error) {
}
return config, nil
}
// GetRepositoryURL returns the repo FQDN
func (c *ReleaseConfig) GetRepositoryURL() string {
if c.GitProvider.customProviderURL == "" {
return fmt.Sprintf("%s/%s/%s/", c.GitProvider.customProviderURL, c.GitProvider.User, c.GitProvider.Repo)
} else {
return fmt.Sprintf("%s/%s/%s/", gitProviders[c.GitProvider.Name], c.GitProvider.User, c.GitProvider.Repo)
}
}