Skip to content

Commit efc7eef

Browse files
committed
Add support for -prerelease flag
Allows users to mark a Github Release as a prerelease. As `CreateRelease` was part of the public API I have introduced a new private func (`publishRelease`) which allows this change to be introduced in a non-breaking fashion.
1 parent 8bdab49 commit efc7eef

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Parameters:
1919
2020
Options:
2121
-version: Displays version
22+
-prerelease: Identify the release as a prerelease
2223
2324
Environment variables:
2425
DEBUG: Allows you to run github-release in debugging mode. DO NOT do this if you are attempting to upload big files.
@@ -42,4 +43,4 @@ Feel free to inspect this project's [Makefile](https://github.com/c4milo/github-
4243

4344
![](https://cldup.com/6Slplyys6X.png)
4445

45-
46+

main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Release struct {
4343
}
4444

4545
var verFlag bool
46+
var prereleaseFlag bool
4647

4748
func init() {
4849
log.SetFlags(0)
@@ -59,6 +60,7 @@ func init() {
5960
}
6061

6162
flag.BoolVar(&verFlag, "version", false, "-version")
63+
flag.BoolVar(&prereleaseFlag, "prerelease", false, "-prerelease")
6264
flag.Parse()
6365
}
6466

@@ -77,6 +79,7 @@ Parameters:
7779
7880
Options:
7981
-version: Displays version
82+
-prerelease: Identify the release as a prerelease
8083
8184
Environment variables:
8285
DEBUG: Allows you to run github-release in debugging mode. DO NOT do this if you are attempting to upload big files.
@@ -139,7 +142,15 @@ Please refer to https://help.github.com/articles/creating-an-access-token-for-co
139142
branch := flag.Arg(2)
140143
desc := flag.Arg(3)
141144

142-
CreateRelease(tag, branch, desc, filepaths)
145+
release := Release{
146+
TagName: tag,
147+
Name: tag,
148+
Prerelease: prereleaseFlag,
149+
Draft: false,
150+
Branch: branch,
151+
Body: desc,
152+
}
153+
publishRelease(release, filepaths)
143154
log.Println("Done")
144155
}
145156

@@ -173,8 +184,6 @@ func uploadFile(uploadURL, path string) {
173184
// CreateRelease creates a Github Release, attaching the given files as release assets
174185
// If a release already exist, up in Github, this function will attempt to attach the given files to it.
175186
func CreateRelease(tag, branch, desc string, filepaths []string) {
176-
endpoint := fmt.Sprintf("%s/releases", githubAPIEndpoint)
177-
178187
release := Release{
179188
TagName: tag,
180189
Name: tag,
@@ -183,7 +192,11 @@ func CreateRelease(tag, branch, desc string, filepaths []string) {
183192
Branch: branch,
184193
Body: desc,
185194
}
195+
publishRelease(release, filepaths)
196+
}
186197

198+
func publishRelease(release Release, filepaths []string) {
199+
endpoint := fmt.Sprintf("%s/releases", githubAPIEndpoint)
187200
releaseData, err := json.Marshal(release)
188201
if err != nil {
189202
log.Fatalln(err)
@@ -196,7 +209,7 @@ func CreateRelease(tag, branch, desc string, filepaths []string) {
196209
if err != nil && data != nil {
197210
log.Println(err)
198211
log.Println("Trying again assuming release already exists.")
199-
endpoint = fmt.Sprintf("%s/releases/tags/%s", githubAPIEndpoint, tag)
212+
endpoint = fmt.Sprintf("%s/releases/tags/%s", githubAPIEndpoint, release.TagName)
200213
data, err = doRequest("GET", endpoint, "application/json", nil, int64(0))
201214
}
202215

0 commit comments

Comments
 (0)