| 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)
|
| }
|
|
|