Skip to content

Commit

Permalink
add tagpr.release setting to adjust creating GitHub Release behavior (#…
Browse files Browse the repository at this point in the history
…95)

* add tagpr.release setting to adjust creating GitHub Release behavior

* update README.md
  • Loading branch information
Songmu authored Sep 16, 2022
1 parent 11e22ed commit 2bcadd8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 27 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tagpr
import (
"os"
"strconv"
"strings"

"github.com/Songmu/gitconfig"
"github.com/google/go-github/v47/github"
Expand Down Expand Up @@ -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"
Expand All @@ -45,19 +50,22 @@ 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 {
releaseBranch *string
versionFile *string
command *string
template *string
release *string
vPrefix *bool
changelog *bool

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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"
}
}
28 changes: 14 additions & 14 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 2bcadd8

Please sign in to comment.