Skip to content

Commit

Permalink
Updated to the real property JSON protocol...
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed Jan 15, 2016
1 parent 76c09b6 commit 6d8520e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@ func (c *Client) GetBuildProperties(buildID string) (map[string]string, error) {
path := fmt.Sprintf("/httpAuth/app/rest/builds/id:%s/resulting-properties", buildID)

var response struct {
Properties struct {
Property []oneProperty `json:"property,omitempty"`
} `json:"properties"`
Property []oneProperty `json:"property,omitempty"`
}
err := c.doRequest("GET", path, nil, &response)
if err != nil {
return nil, err
}

m := make(map[string]string)
for _, prop := range response.Properties.Property {
for _, prop := range response.Property {
m[prop.Name] = prop.Value
}
return m, nil
Expand Down Expand Up @@ -136,9 +134,9 @@ func (c *Client) CancelBuild(buildID int64, comment string) error {
}

func (c *Client) doRequest(method string, path string, data interface{}, v interface{}) error {
authlessUrl := fmt.Sprintf("%s%s", c.host, path)
authURL := fmt.Sprintf("https://%s%s", c.host, path)

fmt.Printf("Sending request to https://%s\n", authlessUrl)
fmt.Printf("Sending request to %s\n", authURL)

var body io.Reader
if data != nil {
Expand All @@ -150,7 +148,8 @@ func (c *Client) doRequest(method string, path string, data interface{}, v inter
body = bytes.NewBuffer(jsonReq)
}

req, _ := http.NewRequest(method, fmt.Sprintf("https://%s:%s@%s", c.username, c.password, authlessUrl), body)
req, _ := http.NewRequest(method, authURL, body)
req.SetBasicAuth(c.username, c.password)
req.Header.Add("Accept", "application/json")

if body != nil {
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package teamcity
import "testing"

func TestClientGetBuildProperties(t *testing.T) {
client := NewTestClient(newResponse(`{"properties":{"property": [{"name": "build.counter", "value": "12"}]}}`), nil)
client := NewTestClient(newResponse(`{"property":[{"name": "build.counter", "value": "12"}], "count": 1}`), nil)

props, err := client.GetBuildProperties("999999")

Expand Down

0 comments on commit 6d8520e

Please sign in to comment.