From ba29a4465b989b7fb0f5bd9431393f5b77810358 Mon Sep 17 00:00:00 2001 From: Songmu Date: Sat, 17 Sep 2022 17:08:23 +0900 Subject: [PATCH] true/false/draft for tapgr.release config --- config.go | 20 +++++++++++++------- tag.go | 23 +++++++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/config.go b/config.go index 39620fb..6792fa4 100644 --- a/config.go +++ b/config.go @@ -40,7 +40,7 @@ const ( # Pull request template in go template format # # tagpr.release (Optional) -# GitHub Release creation behavior after tagging [yes, draft, no] +# GitHub Release creation behavior after tagging [true, draft, false] # If this value is not set, the release is to be created. [tagpr] ` @@ -234,12 +234,18 @@ func (cfg *config) Template() string { return stringify(cfg.template) } -func (cfg *config) Release() string { +func (cfg *config) Release() bool { rel := strings.ToLower(stringify(cfg.release)) - switch rel { - case "yes", "draft", "no": - return rel - default: - return "yes" + if rel == "draft" || rel == "" { + return true } + b, err := strconv.ParseBool(rel) + if err != nil { + return true + } + return b +} + +func (cfg *config) ReleaseDraft() bool { + return strings.ToLower(stringify(cfg.release)) == "draft" } diff --git a/tag.go b/tag.go index 00b0a68..a81e8f7 100644 --- a/tag.go +++ b/tag.go @@ -95,18 +95,17 @@ func (tp *tagpr) tagRelease(ctx context.Context, pr *github.PullRequest, currVer return err } - if rel := tp.cfg.Release(); rel == "no" { + if !tp.cfg.Release() { return nil - } else { - // Don't use GenerateReleaseNote flag and use pre generated one - _, _, err = tp.gh.Repositories.CreateRelease( - ctx, tp.owner, tp.repo, &github.RepositoryRelease{ - TagName: &nextTag, - TargetCommitish: &releaseBranch, - Name: &releases.Name, - Body: &releases.Body, - Draft: github.Bool(rel == "draft"), - }) - return err } + // Don't use GenerateReleaseNote flag and use pre generated one + _, _, err = tp.gh.Repositories.CreateRelease( + ctx, tp.owner, tp.repo, &github.RepositoryRelease{ + TagName: &nextTag, + TargetCommitish: &releaseBranch, + Name: &releases.Name, + Body: &releases.Body, + Draft: github.Bool(tp.cfg.ReleaseDraft()), + }) + return err }