var errHTTP = errors.New("no http in bootstrap go command")
+type httpError struct {
+ statusCode int
+}
+
+func (e *httpError) Error() string {
+ panic("unreachable")
+}
+
func httpGET(url string) ([]byte, error) {
return nil, errHTTP
}
// changed by tests, without modifying http.DefaultClient.
var httpClient = http.DefaultClient
+type httpError struct {
+ status string
+ statusCode int
+ url string
+}
+
+func (e *httpError) Error() string {
+ return fmt.Sprintf("%s: %s", e.url, e.status)
+}
+
// httpGET returns the data from an HTTP GET request for the given URL.
func httpGET(url string) ([]byte, error) {
resp, err := httpClient.Get(url)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
- return nil, fmt.Errorf("%s: %s", url, resp.Status)
+ err := &httpError{status: resp.Status, statusCode: resp.StatusCode, url: url}
+
+ return nil, err
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
url := expand(match, "https://api.bitbucket.org/1.0/repositories/{bitname}")
data, err := httpGET(url)
if err != nil {
- return err
- }
- if err := json.Unmarshal(data, &resp); err != nil {
- return fmt.Errorf("decoding %s: %v", url, err)
+ if httpErr, ok := err.(*httpError); ok && httpErr.statusCode == 403 {
+ // this may be a private repository. If so, attempt to determine which
+ // VCS it uses. See issue 5375.
+ root := match["root"]
+ for _, vcs := range []string{"git", "hg"} {
+ if vcsByCmd(vcs).ping("https", root) == nil {
+ resp.SCM = vcs
+ break
+ }
+ }
+ }
+
+ if resp.SCM == "" {
+ return err
+ }
+ } else {
+ if err := json.Unmarshal(data, &resp); err != nil {
+ return fmt.Errorf("decoding %s: %v", url, err)
+ }
}
if vcsByCmd(resp.SCM) != nil {