blob: 328d89a0489454721e6dd0e0a5c1c5f61abbfa0a [file] [log] [blame]
Brad Fitzpatrickc7891252015-02-10 20:25:37 -08001// 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
Russ Coxf539cd32021-02-19 18:54:48 -05005//go:build ignore
Brad Fitzpatrickc7891252015-02-10 20:25:37 -08006// +build ignore
7
8// The demo command shows and tests usage of the gerrit package.
9package main
10
11import (
Brad Fitzpatrickbce074b2017-04-18 03:12:13 +000012 "context"
Brad Fitzpatrickc7891252015-02-10 20:25:37 -080013 "encoding/json"
14 "io/ioutil"
15 "log"
16 "os"
17 "path/filepath"
18 "strings"
Kevin Burke84c3f712017-01-22 06:03:14 -080019 "time"
Brad Fitzpatrickc7891252015-02-10 20:25:37 -080020
21 "golang.org/x/build/gerrit"
22)
23
24func main() {
25 gobotPass, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), "keys", "gobot-golang-org.cookie"))
26 if err != nil {
27 log.Fatal(err)
28 }
Brad Fitzpatrick421541f2015-02-11 22:57:39 -080029 c := gerrit.NewClient("https://go-review.googlesource.com",
Brad Fitzpatrickc7891252015-02-10 20:25:37 -080030 gerrit.BasicAuth("git-gobot.golang.org", strings.TrimSpace(string(gobotPass))))
Kevin Burke84c3f712017-01-22 06:03:14 -080031 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
32 defer cancel()
33 cl, err := c.QueryChanges(ctx, "label:Run-TryBot=1 label:TryBot-Result=0 project:go status:open", gerrit.QueryChangesOpt{
Brad Fitzpatrickc7891252015-02-10 20:25:37 -080034 Fields: []string{"CURRENT_REVISION"},
35 })
36 if err != nil {
37 log.Fatal(err)
38 }
39 v, _ := json.MarshalIndent(cl, "", " ")
40 os.Stdout.Write(v)
Brad Fitzpatrick201fc262015-02-10 21:18:39 -080041
Kevin Burke84c3f712017-01-22 06:03:14 -080042 log.Printf("SetReview = %v", c.SetReview(ctx, "I2383397c056a9ffe174ac7c2c6e5bb334406fbf9", "current", gerrit.ReviewInput{
Brad Fitzpatrick201fc262015-02-10 21:18:39 -080043 Message: "test test",
44 Labels: map[string]int{
Brad Fitzpatrick421541f2015-02-11 22:57:39 -080045 "TryBot-Result": 0,
Brad Fitzpatrick201fc262015-02-10 21:18:39 -080046 },
47 }))
Brad Fitzpatrickc7891252015-02-10 20:25:37 -080048}