Skip to content

Commit 952e802

Browse files
committed
Add generate-release-notes flag to release subcommand
The GitHub REST API for releases has the option to generate the name and description from the merged PRs since the last release. This commit also adds the option to the release subcommand. This should not be a backwards breaking change, because the name and the description still defaults to the tag, if the -g argument is not given. If the -g argument is given, the name will be empty and GitHub will display the tag in the web interface and the description will be the automatically created description by GitHub.
1 parent 100e855 commit 952e802

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

cmd.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,16 @@ func releasecmd(opt Options) error {
317317
repo := nvls(cmdopt.Repo, EnvRepo)
318318
token := nvls(cmdopt.Token, EnvToken)
319319
tag := cmdopt.Tag
320-
name := nvls(cmdopt.Name, tag)
321-
desc := nvls(cmdopt.Desc, tag)
320+
name := cmdopt.Name
321+
desc := cmdopt.Desc
322322
target := nvls(cmdopt.Target)
323323
draft := cmdopt.Draft
324324
prerelease := cmdopt.Prerelease
325+
generateReleaseNotes := cmdopt.GenerateReleaseNotes
326+
if !generateReleaseNotes {
327+
name = nvls(name, tag)
328+
desc = nvls(desc, tag)
329+
}
325330

326331
vprintln("releasing...")
327332

@@ -339,12 +344,13 @@ func releasecmd(opt Options) error {
339344
}
340345

341346
params := ReleaseCreate{
342-
TagName: tag,
343-
TargetCommitish: target,
344-
Name: name,
345-
Body: desc,
346-
Draft: draft,
347-
Prerelease: prerelease,
347+
TagName: tag,
348+
TargetCommitish: target,
349+
Name: name,
350+
Body: desc,
351+
Draft: draft,
352+
Prerelease: prerelease,
353+
GenerateReleaseNotes: generateReleaseNotes,
348354
}
349355

350356
/* encode params as json */

github-release.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ type Options struct {
3838
Replace bool `goptions:"-R, --replace, description='Replace asset with same name if it already exists (WARNING: not atomic, failure to upload will remove the original asset too)'"`
3939
} `goptions:"upload"`
4040
Release struct {
41-
Token string `goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
42-
User string `goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
43-
Repo string `goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
44-
Tag string `goptions:"-t, --tag, obligatory, description='Git tag to create a release from'"`
45-
Name string `goptions:"-n, --name, description='Name of the release (defaults to tag)'"`
46-
Desc string `goptions:"-d, --description, description='Release description, use - for reading a description from stdin (defaults to tag)'"`
47-
Target string `goptions:"-c, --target, description='Commit SHA or branch to create release of (defaults to the repository default branch)'"`
48-
Draft bool `goptions:"--draft, description='The release is a draft'"`
49-
Prerelease bool `goptions:"-p, --pre-release, description='The release is a pre-release'"`
41+
Token string `goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
42+
User string `goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
43+
Repo string `goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
44+
Tag string `goptions:"-t, --tag, obligatory, description='Git tag to create a release from'"`
45+
Name string `goptions:"-n, --name, description='Name of the release (defaults to tag)'"`
46+
Desc string `goptions:"-d, --description, description='Release description, use - for reading a description from stdin (defaults to tag)'"`
47+
Target string `goptions:"-c, --target, description='Commit SHA or branch to create release of (defaults to the repository default branch)'"`
48+
Draft bool `goptions:"--draft, description='The release is a draft'"`
49+
Prerelease bool `goptions:"-p, --pre-release, description='The release is a pre-release'"`
50+
GenerateReleaseNotes bool `goptions:"-g, --generate-release-notes, description='Generate name and description if not given'"`
5051
} `goptions:"release"`
5152
Edit struct {
5253
Token string `goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`

releases.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ func (r *Release) String() string {
5959
}
6060

6161
type ReleaseCreate struct {
62-
TagName string `json:"tag_name"`
63-
TargetCommitish string `json:"target_commitish,omitempty"`
64-
Name string `json:"name"`
65-
Body string `json:"body"`
66-
Draft bool `json:"draft"`
67-
Prerelease bool `json:"prerelease"`
62+
TagName string `json:"tag_name"`
63+
TargetCommitish string `json:"target_commitish,omitempty"`
64+
Name string `json:"name"`
65+
Body string `json:"body"`
66+
Draft bool `json:"draft"`
67+
Prerelease bool `json:"prerelease"`
68+
GenerateReleaseNotes bool `json:"generate_release_notes"`
6869
}
6970

7071
func Releases(user, repo, authUser, token string) ([]Release, error) {

0 commit comments

Comments
 (0)