1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
package main
import (
"os"
"github.com/tweag/gerrit-queue/frontend"
"github.com/tweag/gerrit-queue/gerrit"
"github.com/tweag/gerrit-queue/submitqueue"
"github.com/gin-gonic/gin"
"github.com/urfave/cli"
"fmt"
log "github.com/sirupsen/logrus"
)
func main() {
// configure logging
log.SetFormatter(&log.TextFormatter{})
//log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.DebugLevel)
var URL, username, password, projectName, branchName, submitQueueTag string
var fetchOnly bool
app := cli.NewApp()
app.Name = "gerrit-queue"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "url",
Usage: "URL to the gerrit instance",
EnvVar: "GERRIT_URL",
Destination: &URL,
Required: true,
},
cli.StringFlag{
Name: "username",
Usage: "Username to use to login to gerrit",
EnvVar: "GERRIT_USERNAME",
Destination: &username,
Required: true,
},
cli.StringFlag{
Name: "password",
Usage: "Password to use to login to gerrit",
EnvVar: "GERRIT_PASSWORD",
Destination: &password,
Required: true,
},
cli.StringFlag{
Name: "project",
Usage: "Gerrit project name to run the submit queue for",
EnvVar: "GERRIT_PROJECT",
Destination: &projectName,
Required: true,
},
cli.StringFlag{
Name: "branch",
Usage: "Destination branch",
EnvVar: "GERRIT_BRANCH",
Destination: &branchName,
Value: "master",
},
cli.StringFlag{
Name: "submit-queue-tag",
Usage: "the tag used to submit something to the submit queue",
EnvVar: "SUBMIT_QUEUE_TAG",
Destination: &submitQueueTag,
Value: "submit_me",
},
cli.BoolFlag{
Name: "fetch-only",
Usage: "Only fetch changes and assemble queue, but don't actually write",
Destination: &fetchOnly,
},
}
app.Action = func(c *cli.Context) error {
gerritClient, err := gerrit.NewClient(URL, username, password)
if err != nil {
return err
}
log.Printf("Successfully connected to gerrit at %s", URL)
submitQueue := submitqueue.MakeSubmitQueue(gerritClient, projectName, branchName, submitQueueTag)
router := gin.Default()
frontend := frontend.MakeFrontend(router, &submitQueue)
err = submitQueue.LoadSeries()
if err != nil {
log.Errorf("Error loading submit queue: %s", err)
}
fmt.Println()
fmt.Println()
fmt.Println()
fmt.Println()
for _, serie := range submitQueue.Series {
fmt.Println(fmt.Sprintf("%s", serie))
for _, changeset := range serie.ChangeSets {
fmt.Println(fmt.Sprintf(" - %s", changeset.String()))
}
fmt.Println()
}
frontend.Run(":8080")
if fetchOnly {
//return backlog.Run()
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
// mux := http.NewServeMux()
// options := &gerrit.EventsLogOptions{}
// events, _, _, err := gerritClient.EventsLog.GetEvents(options)
// TODOS:
// - create submit queue user
// - handle event log, either by accepting webhooks, or by streaming events?
//n := negroni.Classic()
//n.UseHandler(mux)
//fmt.Println("Listening on :3000…")
//http.ListenAndServe(":3000", n)
}
|