mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
cyclo complexity on git pipe
This commit is contained in:
parent
6c51f42871
commit
a5fe2e48c3
@ -67,28 +67,11 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
CurrentTag: tag,
|
||||
Commit: commit,
|
||||
}
|
||||
if ctx.ReleaseNotes == "" {
|
||||
var log string
|
||||
if tag != "" {
|
||||
log, err = getChangelog(tag)
|
||||
} else {
|
||||
log, err = getChangelog(commit)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log)
|
||||
if err = setLog(ctx, tag, commit); err != nil {
|
||||
return
|
||||
}
|
||||
if tag == "" || ctx.Snapshot {
|
||||
snapshotName, err := getSnapshotName(ctx, tag, commit)
|
||||
if err != nil {
|
||||
log.Printf("Failed to generate snapshot name: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
ctx.Version = snapshotName
|
||||
} else {
|
||||
// removes usual `v` prefix
|
||||
ctx.Version = strings.TrimPrefix(tag, "v")
|
||||
if err = setVersion(ctx, tag, commit); err != nil {
|
||||
return
|
||||
}
|
||||
if !ctx.Validate {
|
||||
log.Println("Skipped validations because --skip-validate is set")
|
||||
@ -97,6 +80,37 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
return validate(commit, tag, ctx.Version, ctx.Snapshot)
|
||||
}
|
||||
|
||||
func setVersion(ctx *context.Context, tag, commit string) (err error) {
|
||||
if ctx.Snapshot {
|
||||
snapshotName, err := getSnapshotName(ctx, tag, commit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to generate snapshot name: %s", err.Error())
|
||||
}
|
||||
ctx.Version = snapshotName
|
||||
return nil
|
||||
}
|
||||
// removes usual `v` prefix
|
||||
ctx.Version = strings.TrimPrefix(tag, "v")
|
||||
return
|
||||
}
|
||||
|
||||
func setLog(ctx *context.Context, tag, commit string) (err error) {
|
||||
if ctx.ReleaseNotes != "" {
|
||||
return
|
||||
}
|
||||
var log string
|
||||
if tag == "" {
|
||||
log, err = getChangelog(commit)
|
||||
} else {
|
||||
log, err = getChangelog(tag)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log)
|
||||
return nil
|
||||
}
|
||||
|
||||
type snapshotNameData struct {
|
||||
Commit string
|
||||
Tag string
|
||||
@ -109,10 +123,13 @@ func getSnapshotName(ctx *context.Context, tag, commit string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := tmpl.Execute(&out, snapshotNameData{Commit: commit, Tag: tag, Timestamp: time.Now().Unix()}); err != nil {
|
||||
return "", err
|
||||
var data = snapshotNameData{
|
||||
Commit: commit,
|
||||
Tag: tag,
|
||||
Timestamp: time.Now().Unix(),
|
||||
}
|
||||
return out.String(), nil
|
||||
err = tmpl.Execute(&out, data)
|
||||
return out.String(), err
|
||||
}
|
||||
|
||||
func validate(commit, tag, version string, isSnapshot bool) error {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/pipeline/defaults"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -58,7 +59,9 @@ func TestNoTagsSnapshot(t *testing.T) {
|
||||
gitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{NameTemplate: "SNAPSHOT-{{.Commit}}"},
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: defaults.SnapshotNameTemplate,
|
||||
},
|
||||
},
|
||||
Snapshot: true,
|
||||
Publish: false,
|
||||
@ -75,7 +78,9 @@ func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
|
||||
gitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{NameTemplate: "{{"},
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: "{{",
|
||||
},
|
||||
},
|
||||
Snapshot: true,
|
||||
Publish: false,
|
||||
@ -94,7 +99,9 @@ func TestNoTagsNoSnapshot(t *testing.T) {
|
||||
gitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{NameTemplate: "SNAPSHOT-{{.Commit}}"},
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: defaults.SnapshotNameTemplate,
|
||||
},
|
||||
},
|
||||
Snapshot: false,
|
||||
Publish: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user