diff --git a/README.md b/README.md index 3e011e1..cf1a8a5 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,10 @@ Command to change files just before release. ### tagpr.tmplate (Optional) Pull request template in go template format +### tagpr.release (Optional) +GitHub Release creation behavior after tagging `[yes, draft, no]` +If this value is not set, the release is to be created. + ## Author [Songmu](https://github.com/Songmu) diff --git a/config.go b/config.go index efe96cd..39620fb 100644 --- a/config.go +++ b/config.go @@ -3,6 +3,7 @@ package tagpr import ( "os" "strconv" + "strings" "github.com/Songmu/gitconfig" "github.com/google/go-github/v47/github" @@ -37,6 +38,10 @@ const ( # # tagpr.tmplate (Optional) # Pull request template in go template format +# +# tagpr.release (Optional) +# GitHub Release creation behavior after tagging [yes, draft, no] +# If this value is not set, the release is to be created. [tagpr] ` envReleaseBranch = "TAGPR_RELEASE_BRANCH" @@ -45,12 +50,14 @@ const ( envChangelog = "TAGPR_CHANGELOG" envCommand = "TAGPR_COMMAND" envTemplate = "TAGPR_TEMPLATE" + envRelease = "TAGPR_RELEASE" configReleaseBranch = "tagpr.releaseBranch" configVersionFile = "tagpr.versionFile" configVPrefix = "tagpr.vPrefix" configChangelog = "tagpr.changelog" configCommand = "tagpr.command" configTemplate = "tagpr.template" + configRelease = "tagpr.release" ) type config struct { @@ -58,6 +65,7 @@ type config struct { versionFile *string command *string template *string + release *string vPrefix *bool changelog *bool @@ -137,6 +145,15 @@ func (cfg *config) Reload() error { } } + if rel := os.Getenv(envRelease); rel != "" { + cfg.release = github.String(rel) + } else { + rel, err := cfg.gitconfig.Get(configRelease) + if err == nil { + cfg.release = github.String(rel) + } + } + return nil } @@ -216,3 +233,13 @@ func (cfg *config) Command() string { func (cfg *config) Template() string { return stringify(cfg.template) } + +func (cfg *config) Release() string { + rel := strings.ToLower(stringify(cfg.release)) + switch rel { + case "yes", "draft", "no": + return rel + default: + return "yes" + } +} diff --git a/tag.go b/tag.go index dfef6be..00b0a68 100644 --- a/tag.go +++ b/tag.go @@ -95,18 +95,18 @@ func (tp *tagpr) tagRelease(ctx context.Context, pr *github.PullRequest, currVer 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, - // I want to make it as a draft release by default, but it is difficult to get a draft release - // from another tool via API, and there is no tool supports it, so I will make it as a normal - // release. In the future, there may be an option to create it as a Draft, or conversely, - // an option not to create a release. - // Draft: github.Bool(true), - }) - return err + if rel := tp.cfg.Release(); rel == "no" { + 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 + } }