Skip to content
This repository was archived by the owner on Jul 17, 2018. It is now read-only.

Commit dbe3cd2

Browse files
author
Dan Rees
committed
Mask req debug info by default and improve error info
1 parent 4f64739 commit dbe3cd2

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

ci/pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ jobs:
378378
- task: publish-draft-release
379379
file: devtools-boshrelease/ci/tasks/publish-draft-release/publish-draft-release.yml
380380
params:
381+
GITHUB_ACCESS_KEY: ((github_access_key))
381382
OWNER: finkit
382383
REPO: devtools-boshrelease
383384
VERSION: version/version

ci/tasks/publish-draft-release/publish-draft-release.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"io/ioutil"
99
"net/http"
1010
"os"
11+
"strconv"
1112
)
1213

1314
const (
1415
gitHubUrl string = "https://api.github.com/repos/"
1516
gitHubCredentialsVariable string = "GITHUB_ACCESS_KEY"
17+
debugMessagesVariable string = "DEBUG_MESSAGES_ENABLED"
1618
getReleasesMethodType string = "GET"
1719
editReleaseMethodType string = "PATCH"
1820
defaultVersion string = "latest"
@@ -21,12 +23,13 @@ const (
2123
)
2224

2325
var (
24-
owner string
25-
repo string
26-
branch string
27-
version string
28-
description string
29-
credentials string = os.Getenv(gitHubCredentialsVariable)
26+
owner string
27+
repo string
28+
branch string
29+
version string
30+
description string
31+
credentials string = os.Getenv(gitHubCredentialsVariable)
32+
debugMessages bool
3033
)
3134

3235
type IdAndTag struct {
@@ -63,10 +66,12 @@ func sendRequest(methodType string, url string, body io.Reader, bodySize int64)
6366
req.Header.Set("Accept", "application/vnd.github.v3+json")
6467
req.ContentLength = bodySize
6568

66-
if body == nil {
67-
os.Stdout.WriteString(fmt.Sprintf("Sending request to %s: %+v\n", url, req))
68-
} else {
69-
os.Stdout.WriteString(fmt.Sprintf("Sending request to %s with data %s: %+v\n", url, body, req))
69+
if debugMessages {
70+
if body == nil {
71+
os.Stdout.WriteString(fmt.Sprintf("Sending request to %s: %+v\n", url, req))
72+
} else {
73+
os.Stdout.WriteString(fmt.Sprintf("Sending request to %s with data %s: %+v\n", url, body, req))
74+
}
7075
}
7176

7277
resp, err := http.DefaultClient.Do(req)
@@ -83,7 +88,8 @@ func sendRequest(methodType string, url string, body io.Reader, bodySize int64)
8388
}
8489

8590
func getReleaseId() (int64, error) {
86-
code, bodyBytes, err := sendRequest(getReleasesMethodType, getReleaseApiUrl(), bytes.NewBuffer([]byte{}), 0)
91+
url := getReleaseApiUrl()
92+
code, bodyBytes, err := sendRequest(getReleasesMethodType, url, bytes.NewBuffer([]byte{}), 0)
8793

8894
if err != nil {
8995
return 0, err
@@ -92,20 +98,20 @@ func getReleaseId() (int64, error) {
9298
if code == http.StatusOK {
9399
fmt.Printf(fmt.Sprintf("Got releases on branch %s: %s\n", branch, string(bodyBytes)))
94100
} else {
95-
return 0, fmt.Errorf("error getting releases for version %s with response code %d", getReleaseApiUrl(), code)
101+
return 0, fmt.Errorf("error getting releases for version %s with response code %d", url, code)
96102
}
97103

98104
var releases []IdAndTag
99105
json.Unmarshal(bodyBytes, &releases)
100-
os.Stdout.WriteString(fmt.Sprintf("Response from %s: %v\n", getReleaseApiUrl(), releases))
106+
os.Stdout.WriteString(fmt.Sprintf("Response from %s: %v\n", url, releases))
101107

102108
for _, release := range releases {
103109
if release.TagName == version {
104110
return release.Id, err
105111
}
106112
}
107113

108-
return 0, err
114+
return 0, fmt.Errorf("No ID found from %s using version %s", url, version)
109115
}
110116

111117
func editRelease(id int64, body io.Reader, bodySize int64) (int, []byte, error) {
@@ -116,7 +122,11 @@ func publishDraftRelease() error {
116122
id, err := getReleaseId()
117123

118124
if err != nil {
119-
return fmt.Errorf("error getting releases on %s", getReleaseApiUrl())
125+
return fmt.Errorf("error getting releases: %s", err)
126+
}
127+
128+
if id == 0 {
129+
return fmt.Errorf("error getting releases - no ID found")
120130
}
121131

122132
release := Release{
@@ -197,7 +207,15 @@ func main() {
197207
description = os.Args[5]
198208
}
199209

200-
err := publishDraftRelease()
210+
var err error
211+
212+
debugMessages, err = strconv.ParseBool(os.Getenv(debugMessagesVariable))
213+
214+
if err != nil {
215+
debugMessages = false
216+
}
217+
218+
err = publishDraftRelease()
201219

202220
if err != nil {
203221
os.Stderr.WriteString(fmt.Sprintf("Failed to publish draft release - %s\n", err))

0 commit comments

Comments
 (0)