Skip to content

Commit 89f94d9

Browse files
authored
Revert "validate bitbucket api url (#138)"
This reverts commit 5bccfc3.
1 parent 5bccfc3 commit 89f94d9

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

client.go

+11-19
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ const DEFAULT_PAGE_LENGTH = 10
2525
const DEFAULT_MAX_DEPTH = 1
2626
const DEFAULT_BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0"
2727

28-
func apiBaseUrl() (*url.URL, error) {
28+
func apiBaseUrl() string {
2929
ev := os.Getenv("BITBUCKET_API_BASE_URL")
30-
if ev == "" {
31-
ev = DEFAULT_BITBUCKET_API_BASE_URL
30+
if ev != "" {
31+
return ev
3232
}
3333

34-
return url.Parse(ev)
34+
return DEFAULT_BITBUCKET_API_BASE_URL
3535
}
3636

3737
type Client struct {
@@ -43,7 +43,7 @@ type Client struct {
4343
Workspaces *Workspace
4444
Pagelen uint64
4545
MaxDepth uint64
46-
apiBaseURL *url.URL
46+
apiBaseURL string
4747

4848
HttpClient *http.Client
4949
}
@@ -135,11 +135,7 @@ func NewBasicAuth(u, p string) *Client {
135135
}
136136

137137
func injectClient(a *auth) *Client {
138-
bitbucketUrl, err := apiBaseUrl()
139-
if err != nil {
140-
log.Fatalf("invalid bitbucket url")
141-
}
142-
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH, MaxDepth: DEFAULT_MAX_DEPTH, apiBaseURL: bitbucketUrl}
138+
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH, MaxDepth: DEFAULT_MAX_DEPTH, apiBaseURL: apiBaseUrl()}
143139
c.Repositories = &Repositories{
144140
c: c,
145141
PullRequests: &PullRequests{c: c},
@@ -161,15 +157,11 @@ func injectClient(a *auth) *Client {
161157
}
162158

163159
func (c *Client) GetApiBaseURL() string {
164-
return fmt.Sprintf("%s%s", c.apiBaseURL.GetApiHostnameURL(), c.apiBaseURL.Path)
165-
}
166-
167-
func (c *Client) GetApiHostnameURL() string {
168-
return fmt.Sprintf("%s://%s", c.apiBaseURL.Scheme, c.apiBaseURL.Host)
160+
return c.apiBaseURL
169161
}
170162

171-
func (c *Client) SetApiBaseURL(urlStr url.URL) {
172-
c.apiBaseURL = &urlStr
163+
func (c *Client) SetApiBaseURL(urlStr string) {
164+
c.apiBaseURL = urlStr
173165
}
174166

175167
func (c *Client) executeRaw(method string, urlStr string, text string) (io.ReadCloser, error) {
@@ -387,7 +379,7 @@ func unexpectedHttpStatusCode(statusCode int) bool {
387379
func (c *Client) requestUrl(template string, args ...interface{}) string {
388380

389381
if len(args) == 1 && args[0] == "" {
390-
return c.GetApiBaseURL() + template
382+
return c.apiBaseURL + template
391383
}
392-
return c.GetApiBaseURL() + fmt.Sprintf(template, args...)
384+
return c.apiBaseURL + fmt.Sprintf(template, args...)
393385
}

0 commit comments

Comments
 (0)