|
|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"net/url"
|
|
|
|
|
"strings"
|
|
|
|
@ -64,15 +65,16 @@ func (c *wrapper) do(ctx context.Context, method, path string, in, out interface
|
|
|
|
|
req := &scm.Request{
|
|
|
|
|
Method: method,
|
|
|
|
|
Path: path,
|
|
|
|
|
Header: map[string][]string{
|
|
|
|
|
"Accept": {"application/json"},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
// if we are posting or putting data, we need to
|
|
|
|
|
// write it to the body of the request.
|
|
|
|
|
if in != nil {
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
json.NewEncoder(buf).Encode(in)
|
|
|
|
|
req.Header = map[string][]string{
|
|
|
|
|
"Content-Type": {"application/json"},
|
|
|
|
|
}
|
|
|
|
|
req.Header["Content-Type"] = []string{"application/json"}
|
|
|
|
|
req.Body = buf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -121,7 +123,9 @@ type pagination struct {
|
|
|
|
|
|
|
|
|
|
// Error represents a Stash error.
|
|
|
|
|
type Error struct {
|
|
|
|
|
Errors []struct {
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
Status int `json:"status-code"`
|
|
|
|
|
Errors []struct {
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
ExceptionName string `json:"exceptionName"`
|
|
|
|
|
CurrentVersion int `json:"currentVersion"`
|
|
|
|
@ -131,6 +135,9 @@ type Error struct {
|
|
|
|
|
|
|
|
|
|
func (e *Error) Error() string {
|
|
|
|
|
if len(e.Errors) == 0 {
|
|
|
|
|
if len(e.Message) > 0 {
|
|
|
|
|
return fmt.Sprintf("bitbucket: status: %d message: %s", e.Status, e.Message)
|
|
|
|
|
}
|
|
|
|
|
return "bitbucket: undefined error"
|
|
|
|
|
}
|
|
|
|
|
return e.Errors[0].Message
|
|
|
|
|