Skip to content

Commit 0ff5993

Browse files
authored
Merge pull request #7 from paulthomson/feature/attach_files
Attach files if release exists. Useful when adding artifacts generated from different CI systems. Ex: Travis and AppVeyor
2 parents af78231 + e7b6d1f commit 0ff5993

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ func CreateRelease(tag, branch, desc string, filepaths []string) {
191191
releaseBuffer := bytes.NewBuffer(releaseData)
192192

193193
data, err := doRequest("POST", endpoint, "application/json", releaseBuffer, int64(releaseBuffer.Len()))
194+
195+
if err != nil && data != nil {
196+
log.Println(err)
197+
log.Println("Trying again assuming release already exists.")
198+
endpoint = fmt.Sprintf("%s/releases/tags/%s", githubAPIEndpoint, tag)
199+
data, err = doRequest("GET", endpoint, "application/json", nil, int64(0))
200+
}
201+
194202
if err != nil {
195203
log.Fatalln(err)
196204
}
@@ -268,7 +276,7 @@ func doRequest(method, url, contentType string, reqBody io.Reader, bodySize int6
268276
}
269277

270278
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
271-
return nil, fmt.Errorf("Github returned an error:\n Code: %s. \n Body: %s", resp.Status, respBody)
279+
return respBody, fmt.Errorf("Github returned an error:\n Code: %s. \n Body: %s", resp.Status, respBody)
272280
}
273281

274282
return respBody, nil

0 commit comments

Comments
 (0)