golang.org/x/build@v0.0.0-20240506185731-218518f32b70/gerrit/demo.go (about) 1 // Copyright 2015 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. 4 5 //go:build ignore 6 7 // The demo command shows and tests usage of the gerrit package. 8 package main 9 10 import ( 11 "context" 12 "encoding/json" 13 "log" 14 "os" 15 "path/filepath" 16 "strings" 17 "time" 18 19 "golang.org/x/build/gerrit" 20 ) 21 22 func main() { 23 gobotPass, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), "keys", "gobot-golang-org.cookie")) 24 if err != nil { 25 log.Fatal(err) 26 } 27 c := gerrit.NewClient("https://go-review.googlesource.com", 28 gerrit.BasicAuth("git-gobot.golang.org", strings.TrimSpace(string(gobotPass)))) 29 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 30 defer cancel() 31 cl, err := c.QueryChanges(ctx, "label:Run-TryBot=1 label:TryBot-Result=0 project:go status:open", gerrit.QueryChangesOpt{ 32 Fields: []string{"CURRENT_REVISION"}, 33 }) 34 if err != nil { 35 log.Fatal(err) 36 } 37 v, _ := json.MarshalIndent(cl, "", " ") 38 os.Stdout.Write(v) 39 40 log.Printf("SetReview = %v", c.SetReview(ctx, "I2383397c056a9ffe174ac7c2c6e5bb334406fbf9", "current", gerrit.ReviewInput{ 41 Message: "test test", 42 Labels: map[string]int{ 43 "TryBot-Result": 0, 44 }, 45 })) 46 }