1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
19
type obj map[string]interface{}
21
// dash runs the given method and command on the dashboard.
22
// If args is non-nil it is encoded as the URL query string.
23
// If req is non-nil it is JSON-encoded and passed as the body of the HTTP POST.
24
// If resp is non-nil the server's response is decoded into the value pointed
25
// to by resp (resp must be a pointer).
26
func dash(meth, cmd string, args url.Values, req, resp interface{}) error {
30
log.Println("dash <-", meth, cmd, args, req)
32
cmd = "http://" + *dashboard + "/" + cmd
34
cmd += "?" + args.Encode()
39
log.Panicf("%s to %s with req", meth, cmd)
41
r, err = http.Get(cmd)
45
b, err := json.Marshal(req)
49
body = bytes.NewBuffer(b)
51
r, err = http.Post(cmd, "text/json", body)
53
log.Panicf("%s: invalid method %q", cmd, meth)
54
panic("invalid method: " + meth)
60
if r.StatusCode != http.StatusOK {
61
return fmt.Errorf("bad http response: %v", r.Status)
63
body := new(bytes.Buffer)
64
if _, err := body.ReadFrom(r.Body); err != nil {
68
// Read JSON-encoded Response into provided resp
69
// and return an error if present.
74
// Put the provided resp in here as it can be a pointer to
75
// some value we should unmarshal into.
78
if err = json.Unmarshal(body.Bytes(), &result); err != nil {
79
log.Printf("json unmarshal %#q: %s\n", body.Bytes(), err)
83
log.Println("dash ->", result)
85
if result.Error != "" {
86
return errors.New(result.Error)
92
// todo returns the next hash to build.
93
func (b *Builder) todo(kind, pkg, goHash string) (rev string, err error) {
106
if err = dash("GET", "todo", args, nil, &resp); err != nil {
112
if kind != resp.Kind {
113
return "", fmt.Errorf("expecting Kind %q, got %q", kind, resp.Kind)
115
return resp.Data.Hash, nil
118
// recordResult sends build results to the dashboard
119
func (b *Builder) recordResult(ok bool, pkg, hash, goHash, buildLog string, runTime time.Duration) error {
129
args := url.Values{"key": {b.key}, "builder": {b.name}}
130
return dash("POST", "result", args, req, nil)
133
func postCommit(key, pkg string, l *HgLog) error {
134
t, err := time.Parse(time.RFC3339, l.Date)
136
return fmt.Errorf("parsing %q: %v", l.Date, t)
138
return dash("POST", "commit", url.Values{"key": {key}}, obj{
141
"ParentHash": l.Parent,
142
"Time": t.Format(time.RFC3339),
148
func dashboardCommit(pkg, hash string) bool {
149
err := dash("GET", "commit", url.Values{
150
"packagePath": {pkg},
156
func dashboardPackages(kind string) []string {
157
args := url.Values{"kind": []string{kind}}
161
if err := dash("GET", "packages", args, nil, &resp); err != nil {
162
log.Println("dashboardPackages:", err)
166
for _, r := range resp {
167
pkgs = append(pkgs, r.Path)