Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Unified Diff: buildbucket/client/cmd/buildbucket/put.go

Issue 2227113002: Update bulidbucket client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « buildbucket/client/cmd/buildbucket/main.go ('k') | client/cmd/buildbucket/base_command.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: buildbucket/client/cmd/buildbucket/put.go
diff --git a/client/cmd/buildbucket/put.go b/buildbucket/client/cmd/buildbucket/put.go
similarity index 53%
rename from client/cmd/buildbucket/put.go
rename to buildbucket/client/cmd/buildbucket/put.go
index e05be3c3111be933a29b207304720a8018920b66..440a796d42329cec87e01490ef35e44f0eddf490 100644
--- a/client/cmd/buildbucket/put.go
+++ b/buildbucket/client/cmd/buildbucket/put.go
@@ -12,7 +12,6 @@ import (
"github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1"
"github.com/luci/luci-go/common/cli"
- "github.com/luci/luci-go/common/logging"
)
var cmdPutBatch = &subcommands.Command{
@@ -36,37 +35,20 @@ type putBatchRun struct {
func (r *putBatchRun) Run(a subcommands.Application, args []string) int {
ctx := cli.GetContext(a, r)
if len(args) < 1 {
- logging.Errorf(ctx, "missing parameter: <JSON Request>")
- return 1
+ return r.done(ctx, fmt.Errorf("missing parameter: <JSON Request>"))
}
- reqMessage := &buildbucket.ApiPutBatchRequestMessage{}
-
- for i := range args {
- build := &buildbucket.ApiPutRequestMessage{}
- if err := json.Unmarshal([]byte(args[i]), build); err != nil {
- logging.Errorf(ctx, "could not unmarshal %s: %s", args[i], err)
- return 1
- }
- reqMessage.Builds = append(reqMessage.Builds, build)
- }
-
- service, err := r.makeService(ctx, a)
- if err != nil {
- return 1
+ var reqBody struct {
+ Builds []json.RawMessage `json:"builds"`
}
-
- response, err := service.PutBatch(reqMessage).Do()
- if err != nil {
- logging.Errorf(ctx, "buildbucket.PutBatch failed: %s", err)
- return 1
+ for i, a := range args {
+ aBytes := []byte(a)
+ // verify that args are valid here before sending the request.
+ if err := json.Unmarshal(aBytes, &buildbucket.ApiPutRequestMessage{}); err != nil {
+ return r.done(ctx, fmt.Errorf("invalid build request #%d: %s", i, err))
+ }
+ reqBody.Builds = append(reqBody.Builds, json.RawMessage(aBytes))
}
- responseJSON, err := response.MarshalJSON()
- if err != nil {
- logging.Errorf(ctx, "could not marshal response: %s", err)
- return 1
- }
- fmt.Println(string(responseJSON))
- return 0
+ return r.callAndDone(ctx, "PUT", "builds/batch", reqBody)
}
« no previous file with comments | « buildbucket/client/cmd/buildbucket/main.go ('k') | client/cmd/buildbucket/base_command.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698