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

Side by Side Diff: 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 unified diff | Download patch
« no previous file with comments | « client/cmd/buildbucket/main.go ('k') | common/lhttp/utils.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "encoding/json"
9 "fmt"
10
11 "github.com/maruel/subcommands"
12
13 "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1"
14 "github.com/luci/luci-go/common/cli"
15 "github.com/luci/luci-go/common/logging"
16 )
17
18 var cmdPutBatch = &subcommands.Command{
19 UsageLine: `put [flags] <JSON request>...`,
20 ShortDesc: "schedule builds",
21 LongDesc: "Schedule builds. \n" +
22 "See https://godoc.org/github.com/luci/luci-go/common/api/" +
23 "buildbucket/buildbucket/v1#ApiPutBatchRequestMessage " +
24 "for JSON request message schema.",
25 CommandRun: func() subcommands.CommandRun {
26 c := &putBatchRun{}
27 c.SetDefaultFlags()
28 return c
29 },
30 }
31
32 type putBatchRun struct {
33 baseCommandRun
34 }
35
36 func (r *putBatchRun) Run(a subcommands.Application, args []string) int {
37 ctx := cli.GetContext(a, r)
38 if len(args) < 1 {
39 logging.Errorf(ctx, "missing parameter: <JSON Request>")
40 return 1
41 }
42
43 reqMessage := &buildbucket.ApiPutBatchRequestMessage{}
44
45 for i := range args {
46 build := &buildbucket.ApiPutRequestMessage{}
47 if err := json.Unmarshal([]byte(args[i]), build); err != nil {
48 logging.Errorf(ctx, "could not unmarshal %s: %s", args[i ], err)
49 return 1
50 }
51 reqMessage.Builds = append(reqMessage.Builds, build)
52 }
53
54 service, err := r.makeService(ctx, a)
55 if err != nil {
56 return 1
57 }
58
59 response, err := service.PutBatch(reqMessage).Do()
60 if err != nil {
61 logging.Errorf(ctx, "buildbucket.PutBatch failed: %s", err)
62 return 1
63 }
64
65 responseJSON, err := response.MarshalJSON()
66 if err != nil {
67 logging.Errorf(ctx, "could not marshal response: %s", err)
68 return 1
69 }
70 fmt.Println(string(responseJSON))
71 return 0
72 }
OLDNEW
« no previous file with comments | « client/cmd/buildbucket/main.go ('k') | common/lhttp/utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698