You've already forked go-semantic-release
feat(config/releaserconfig): change git provider from several type structs to one for simplicity
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GITHUB identifer for github interface
|
// GITHUB identifer for github interface
|
||||||
const GITHUB = "github"
|
const GITHUB = "GitHub"
|
||||||
|
|
||||||
// GitHubReleaser type struct
|
// GitHubReleaser type struct
|
||||||
type GitHubReleaser struct {
|
type GitHubReleaser struct {
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ func New(c *config.ReleaseConfig) *Releasers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//GetReleaser returns an initialized releaser
|
//GetReleaser returns an initialized releaser
|
||||||
func (r *Releasers) GetReleaser(releaserType string) (Releaser, error) {
|
func (r *Releasers) GetReleaser() (Releaser, error) {
|
||||||
switch releaserType {
|
switch r.config.GitProvider.Name {
|
||||||
case GITHUB:
|
case GITHUB:
|
||||||
return NewGitHubReleaser(r.config), nil
|
return NewGitHubReleaser(r.config), nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Could not initialize a releaser from this type: %s", releaserType)
|
return nil, fmt.Errorf("Could not initialize a releaser from this type: %s", r.config.GitProvider.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tbd. http helper function
|
// tbd. http helper function
|
||||||
|
|||||||
@@ -2,12 +2,18 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// List of all supported git providers
|
||||||
|
var gitPorviders = map[string]string{"GitHub": "", "GitLab": ""}
|
||||||
|
|
||||||
// ChangelogConfig struct
|
// ChangelogConfig struct
|
||||||
type ChangelogConfig struct {
|
type ChangelogConfig struct {
|
||||||
PrintAll bool `yaml:"printAll,omitempty"`
|
PrintAll bool `yaml:"printAll,omitempty"`
|
||||||
@@ -15,15 +21,9 @@ type ChangelogConfig struct {
|
|||||||
TemplatePath string `yaml:"templatePath,omitempty"`
|
TemplatePath string `yaml:"templatePath,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GithubConfig struct
|
// GitProvider struct
|
||||||
type GithubConfig struct {
|
type GitProvider struct {
|
||||||
URL string `yaml:"url"`
|
Name string `yaml:"name"`
|
||||||
User string `yaml:"user"`
|
|
||||||
AccessToken string `yaml:"accessToken"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GitlabConfig struct
|
|
||||||
type GitlabConfig struct {
|
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
AccessToken string `yaml:"accessToken"`
|
AccessToken string `yaml:"accessToken"`
|
||||||
@@ -40,8 +40,7 @@ type ReleaseConfig struct {
|
|||||||
Branch map[string]string `yaml:"branch"`
|
Branch map[string]string `yaml:"branch"`
|
||||||
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
Changelog ChangelogConfig `yaml:"changelog,omitempty"`
|
||||||
Release string `yaml:"release,omitempty"`
|
Release string `yaml:"release,omitempty"`
|
||||||
Github GitlabConfig `yaml:"github,omitempty"`
|
GitProvider GitProvider `yaml:"provider,omitempty"`
|
||||||
Gitlab GitlabConfig `yaml:"gitlab,omitempty"`
|
|
||||||
Assets []Asset `yaml:"assets"`
|
Assets []Asset `yaml:"assets"`
|
||||||
IsPreRelease, IsDraft bool
|
IsPreRelease, IsDraft bool
|
||||||
}
|
}
|
||||||
@@ -62,5 +61,25 @@ func Read(configPath string) (*ReleaseConfig, error) {
|
|||||||
|
|
||||||
log.Debugf("Found config %+v", releaseConfig)
|
log.Debugf("Found config %+v", releaseConfig)
|
||||||
|
|
||||||
|
releaseConfig, err = checkProvider(releaseConfig)
|
||||||
|
if err != nil {
|
||||||
|
return &ReleaseConfig{}, err
|
||||||
|
}
|
||||||
return &releaseConfig, nil
|
return &releaseConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkProvider(config ReleaseConfig) (ReleaseConfig, error) {
|
||||||
|
if config.GitProvider != (GitProvider{}) {
|
||||||
|
if _, ok := gitPorviders[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)
|
||||||
|
}
|
||||||
|
config.GitProvider.AccessToken = token
|
||||||
|
}
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user