-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpublish_release.go
More file actions
48 lines (39 loc) · 1.16 KB
/
publish_release.go
File metadata and controls
48 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gitreceive
import (
"bytes"
"encoding/json"
"net/http"
"github.com/deis/builder/pkg"
)
func publishRelease(conf *Config, builderKey string, buildHook *pkg.BuildHook) (*pkg.BuildHookResponse, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(buildHook); err != nil {
return nil, err
}
url := controllerURLStr(conf, "v2", "hooks", "build")
req, err := http.NewRequest("POST", url, &b)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
req.Header.Add("Accept", contentType)
req.Header.Add("User-Agent", userAgent)
req.Header.Add("X-Deis-Builder-Auth", builderKey)
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
return nil, errControllerNotFound
} else if res.StatusCode == http.StatusServiceUnavailable {
return nil, errControllerServiceUnavailable
} else if res.StatusCode != 200 {
return nil, unexpectedControllerStatusCode{expected: 200, actual: res.StatusCode}
}
ret := new(pkg.BuildHookResponse)
if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
return nil, err
}
return ret, nil
}