2019-05-28 18:44:27 +02:00
|
|
|
package releaser
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2019-06-15 23:03:27 +02:00
|
|
|
|
2020-03-21 15:47:03 +01:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
2020-01-05 18:41:44 +01:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
|
|
|
|
"github.com/Nightapes/go-semantic-release/internal/releaser/git"
|
2019-06-15 23:03:27 +02:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
2019-08-07 23:24:13 +02:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
2019-06-15 23:03:27 +02:00
|
|
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
|
|
|
|
|
|
|
|
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
2019-06-17 22:45:49 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2019-05-28 18:44:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Releasers struct type
|
|
|
|
|
type Releasers struct {
|
|
|
|
|
config *config.ReleaseConfig
|
2020-01-05 18:41:44 +01:00
|
|
|
git *gitutil.GitUtil
|
2019-05-28 18:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Releaser interface for providers
|
|
|
|
|
type Releaser interface {
|
2020-03-24 19:56:57 +01:00
|
|
|
CreateRelease(*shared.ReleaseVersion, *shared.GeneratedChangelog, *assets.Set) error
|
2019-06-15 23:03:27 +02:00
|
|
|
GetCommitURL() string
|
|
|
|
|
GetCompareURL(oldVersion, newVersion string) string
|
2019-05-28 18:44:27 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 18:41:44 +01:00
|
|
|
// New initialize a releaser
|
|
|
|
|
func New(c *config.ReleaseConfig, git *gitutil.GitUtil) *Releasers {
|
2019-05-28 18:44:27 +02:00
|
|
|
return &Releasers{
|
|
|
|
|
config: c,
|
2020-01-05 18:41:44 +01:00
|
|
|
git: git,
|
2019-05-28 18:44:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//GetReleaser returns an initialized releaser
|
2020-01-05 18:41:44 +01:00
|
|
|
func (r *Releasers) GetReleaser(checkConfig bool) (Releaser, error) {
|
2019-06-15 23:03:27 +02:00
|
|
|
switch r.config.Release {
|
|
|
|
|
case github.GITHUB:
|
2019-06-17 22:45:49 +02:00
|
|
|
log.Debugf("initialize new %s-provider", github.GITHUB)
|
2020-01-05 18:41:44 +01:00
|
|
|
return github.New(&r.config.GitHubProvider, checkConfig)
|
2019-08-07 23:24:13 +02:00
|
|
|
case gitlab.GITLAB:
|
|
|
|
|
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
2020-01-05 18:41:44 +01:00
|
|
|
return gitlab.New(&r.config.GitLabProvider, checkConfig)
|
|
|
|
|
case git.GITONLY:
|
|
|
|
|
log.Debugf("initialize new %s-provider", git.GITONLY)
|
|
|
|
|
return git.New(&r.config.GitProvider, r.git, checkConfig)
|
2019-05-28 18:44:27 +02:00
|
|
|
}
|
2019-06-15 23:16:30 +02:00
|
|
|
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
2019-05-28 22:12:45 +02:00
|
|
|
}
|