You've already forked go-semantic-release
ref(releasetype/draft): infomation about if release is a draft will now be set in the sharedVersion
This commit is contained in:
@@ -24,7 +24,7 @@ type Rule struct {
|
||||
}
|
||||
|
||||
type analyzeCommit interface {
|
||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, bool, error)
|
||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error)
|
||||
getRules() []Rule
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ type AnalyzedCommit struct {
|
||||
ParsedMessage string
|
||||
Scope string
|
||||
ParsedBreakingChangeMessage string
|
||||
ParsedDraftMessage string
|
||||
Tag string
|
||||
TagString string
|
||||
Print bool
|
||||
@@ -69,12 +68,11 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
||||
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["draft"] = make([]AnalyzedCommit, 0)
|
||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
||||
|
||||
for _, commit := range commits {
|
||||
for _, rule := range a.analyzeCommit.getRules() {
|
||||
analyzedCommit, hasBreakingChange, isDraft, err := a.analyzeCommit.analyze(commit, rule)
|
||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule)
|
||||
if err == nil {
|
||||
if a.Config.PrintAll {
|
||||
analyzedCommit.Print = true
|
||||
@@ -83,8 +81,6 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
||||
}
|
||||
if hasBreakingChange {
|
||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||
} else if isDraft {
|
||||
analyzedCommits["draft"] = append(analyzedCommits["draft"], analyzedCommit)
|
||||
} else {
|
||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (a *angular) getRules() []Rule {
|
||||
return a.rules
|
||||
}
|
||||
|
||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, bool, error) {
|
||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, error) {
|
||||
|
||||
analyzed := AnalyzedCommit{
|
||||
Commit: commit,
|
||||
@@ -92,35 +92,22 @@ func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, boo
|
||||
analyzed.Scope = matches[0][2]
|
||||
|
||||
message := strings.Join(matches[0][3:], "")
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
||||
draft := strings.SplitN(message, "DRAFT:", 1)
|
||||
if !strings.Contains(message, "BREAKING CHANGE:") {
|
||||
analyzed.ParsedMessage = message
|
||||
|
||||
if len(breakingChange) == 1 && len(draft) == 1 {
|
||||
analyzed.ParsedMessage = breakingChange[0]
|
||||
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||
return analyzed, false, false, nil
|
||||
|
||||
return analyzed, false, nil
|
||||
}
|
||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
|
||||
|
||||
if len(breakingChange) > 1 {
|
||||
|
||||
analyzed.ParsedMessage = breakingChange[0]
|
||||
analyzed.ParsedBreakingChangeMessage = breakingChange[1]
|
||||
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
|
||||
return analyzed, true, false, nil
|
||||
|
||||
} else if len(draft) > 1 {
|
||||
analyzed.ParsedMessage = draft[0]
|
||||
analyzed.ParsedDraftMessage = draft[1]
|
||||
log.Tracef(" %s, DRAFT found", commit.Message)
|
||||
|
||||
}
|
||||
analyzed.ParsedMessage = breakingChange[0]
|
||||
analyzed.ParsedBreakingChangeMessage = breakingChange[1]
|
||||
|
||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||
return analyzed, true, nil
|
||||
}
|
||||
}
|
||||
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||
return analyzed, false, false, fmt.Errorf("not found")
|
||||
return analyzed, false, fmt.Errorf("not found")
|
||||
|
||||
}
|
||||
|
||||
1
internal/cache/cache.go
vendored
1
internal/cache/cache.go
vendored
@@ -13,6 +13,7 @@ type ReleaseVersion struct {
|
||||
Last ReleaseVersionEntry `yaml:"last"`
|
||||
Next ReleaseVersionEntry `yaml:"next"`
|
||||
Branch string `yaml:"branch"`
|
||||
Draft bool `yaml:"draft"`
|
||||
}
|
||||
|
||||
//ReleaseVersionEntry struct
|
||||
|
||||
@@ -20,12 +20,11 @@ const GITHUB = "github"
|
||||
|
||||
// Client type struct
|
||||
type Client struct {
|
||||
config *config.GitHubProvider
|
||||
client *github.Client
|
||||
context context.Context
|
||||
release *github.RepositoryRelease
|
||||
draft, prerelease bool
|
||||
baseURL string
|
||||
config *config.GitHubProvider
|
||||
client *github.Client
|
||||
context context.Context
|
||||
release *github.RepositoryRelease
|
||||
baseURL string
|
||||
}
|
||||
|
||||
// New initialize a new GitHubRelease
|
||||
@@ -66,18 +65,6 @@ func (g Client) GetCompareURL(oldVersion, newVersion string) string {
|
||||
return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
//SetReleaseType sets the provider release type
|
||||
func (g Client) SetReleaseType(releaseVersion *shared.ReleaseVersion) {
|
||||
if releaseVersion.Next.Draft {
|
||||
log.Debugf("Set release as draft")
|
||||
g.draft = true
|
||||
}
|
||||
if releaseVersion.Next.Prerelease() != "" {
|
||||
log.Debugf("Set release as prerelease")
|
||||
g.prerelease = true
|
||||
}
|
||||
}
|
||||
|
||||
//ValidateConfig for github
|
||||
func (g Client) ValidateConfig() error {
|
||||
log.Debugf("validate GitHub provider config")
|
||||
@@ -97,16 +84,18 @@ func (g Client) ValidateConfig() error {
|
||||
// CreateRelease creates release on remote
|
||||
func (g Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
||||
|
||||
tag := releaseVersion.Next.String()
|
||||
tag := releaseVersion.Next.Version.String()
|
||||
log.Debugf("create release witth version %s", tag)
|
||||
|
||||
prerelease := releaseVersion.Next.Version.Prerelease() != ""
|
||||
|
||||
release, resp, err := g.client.Repositories.CreateRelease(g.context, g.config.User, g.config.Repo, &github.RepositoryRelease{
|
||||
TagName: &tag,
|
||||
TargetCommitish: &releaseVersion.Branch,
|
||||
Name: &generatedChangelog.Title,
|
||||
Body: &generatedChangelog.Content,
|
||||
Draft: &g.draft,
|
||||
Prerelease: &g.prerelease,
|
||||
Draft: &releaseVersion.Draft,
|
||||
Prerelease: &prerelease,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,6 @@ type Releaser interface {
|
||||
UploadAssets(assets []config.Asset) error
|
||||
GetCommitURL() string
|
||||
GetCompareURL(oldVersion, newVersion string) string
|
||||
SetReleaseType(*shared.ReleaseVersion)
|
||||
}
|
||||
|
||||
// New initialize a Relerser
|
||||
|
||||
@@ -9,13 +9,13 @@ type ReleaseVersion struct {
|
||||
Last ReleaseVersionEntry
|
||||
Next ReleaseVersionEntry
|
||||
Branch string
|
||||
Draft bool
|
||||
}
|
||||
|
||||
//ReleaseVersionEntry struct
|
||||
type ReleaseVersionEntry struct {
|
||||
Commit string
|
||||
Draft bool
|
||||
*semver.Version
|
||||
Commit string
|
||||
Version *semver.Version
|
||||
}
|
||||
|
||||
//GeneratedChangelog struct
|
||||
|
||||
@@ -100,13 +100,14 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
||||
return nil, err
|
||||
}
|
||||
result := a.Analyze(commits)
|
||||
var isDraft bool = false
|
||||
isDraft := false
|
||||
for branch, releaseType := range s.config.Branch {
|
||||
if currentBranch == branch || strings.HasPrefix(currentBranch, branch) {
|
||||
log.Debugf("Found branch config for branch %s with release type %s", currentBranch, releaseType)
|
||||
switch releaseType {
|
||||
case "rc", "beta", "alpha":
|
||||
newVersion = s.incPrerelease(releaseType, newVersion)
|
||||
isDraft = true
|
||||
case "release":
|
||||
if len(result["major"]) > 0 {
|
||||
newVersion = newVersion.IncMajor()
|
||||
@@ -115,9 +116,6 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
||||
} else if len(result["patch"]) > 0 {
|
||||
newVersion = newVersion.IncPatch()
|
||||
}
|
||||
if len(result["draft"]) > 0 {
|
||||
isDraft = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,13 +124,13 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
||||
Next: shared.ReleaseVersionEntry{
|
||||
Commit: hash,
|
||||
Version: &newVersion,
|
||||
Draft: isDraft,
|
||||
},
|
||||
Last: shared.ReleaseVersionEntry{
|
||||
Commit: lastVersionHash,
|
||||
Version: lastVersion,
|
||||
},
|
||||
Branch: currentBranch,
|
||||
Draft: isDraft,
|
||||
}
|
||||
|
||||
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
||||
@@ -242,8 +240,6 @@ func (s *SemanticRelease) Release(force bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
releaser.SetReleaseType(releaseVersion)
|
||||
|
||||
if err = releaser.CreateRelease(releaseVersion, generatedChanglog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user