Skip to content

Commit

Permalink
Merge pull request #96 from Songmu/true-false
Browse files Browse the repository at this point in the history
true/false/draft for tapgr.release config
  • Loading branch information
Songmu authored Sep 17, 2022
2 parents 2bcadd8 + ba29a44 commit ae05bf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
20 changes: 13 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
`
Expand Down Expand Up @@ -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"
}
23 changes: 11 additions & 12 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ae05bf6

Please sign in to comment.