@@ -9,10 +9,14 @@ Notes:
https://godoc.org/github.com/andygrunwald/go-gerrit
https://gerrit-review.googlesource.com/Documentation/rest-api.html
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
https://gerrit-review.googlesource.com/Documentation/user-search.html#_search_operators
https://review.openstack.org/Documentation/config-hooks.html#_comment_added
Go CL <-> PR doc: https://docs.google.com/document/d/131IKF-SHY8cLwpXhkR46HVrKiIYJztZml3YyqECwrgk/edit
go-review / build / 80840 is a good simple CL with inline comments, replies, few revisions
*/
import (
"context"
"flag"
@@ -24,47 +28,27 @@ import (
"dmitri.shuralyov.com/changes"
"dmitri.shuralyov.com/changes/app"
"dmitri.shuralyov.com/changes/gerritapi"
"dmitri.shuralyov.com/changes/githubapi"
"dmitri.shuralyov.com/changes/maintner"
"github.com/andygrunwald/go-gerrit"
"github.com/google/go-github/github"
"github.com/gregjones/httpcache"
"github.com/shurcooL/githubql"
"github.com/shurcooL/httpgzip"
"github.com/shurcooL/reactions/emojis"
"golang.org/x/build/maintner/godata"
"golang.org/x/oauth2"
)
var httpFlag = flag.String("http", ":8080", "Listen for HTTP connections on this address.")
func main() {
flag.Parse()
var service changes.Service
switch 2 {
switch 0 {
case 0:
cacheTransport := httpcache.NewMemoryCacheTransport()
gerrit, err := gerrit.NewClient("https://go-review.googlesource.com/", &http.Client{Transport: cacheTransport})
//gerrit, err := gerrit.NewClient("https://upspin-review.googlesource.com/", &http.Client{Transport: cacheTransport})
if err != nil {
log.Fatalln(err)
}
service = gerritapi.NewService(gerrit)
case 1:
corpus, err := godata.Get(context.Background())
if err != nil {
log.Fatalln(err)
}
service = maintner.NewService(corpus)
case 2:
// Perform GitHub API authentication with provided token.
token := os.Getenv("CHANGES_GITHUB_TOKEN")
if token == "" {
log.Fatalln("CHANGES_GITHUB_TOKEN env var is empty")
}
@@ -82,17 +66,35 @@ func main() {
var err error
service, err = githubapi.NewService(ghV3, ghV4, nil)
if err != nil {
log.Fatalln(err)
}
case 1:
cacheTransport := httpcache.NewMemoryCacheTransport()
gerrit, err := gerrit.NewClient("https://go-review.googlesource.com/", &http.Client{Transport: cacheTransport})
//gerrit, err := gerrit.NewClient("https://upspin-review.googlesource.com/", &http.Client{Transport: cacheTransport})
if err != nil {
log.Fatalln(err)
}
service = gerritapi.NewService(gerrit)
case 2:
/*corpus, err := godata.Get(context.Background())
if err != nil {
log.Fatalln(err)
}
service = maintner.NewService(corpus)*/
}
changesOpt := changesapp.Options{
HeadPre: `<style type="text/css">
body {
margin: 20px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-family: Go;
font-size: 14px;
line-height: initial;
color: #373a3c;
}
.btn {
@@ -120,16 +122,18 @@ func main() {
}
req.URL.Path = req.URL.Path[prefixLen:]
if req.URL.Path == "" {
req.URL.Path = "/"
}
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/google/go-github"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/dustin/go-humanize"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/neugram/ng"))
req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/golang/scratch"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "go.googlesource.com/go"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "go.googlesource.com/tools"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "go.googlesource.com/build"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "upspin.googlesource.com/upspin"))
req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/google/go-github"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/dustin/go-humanize"))
//req = req.WithContext(context.WithValue(req.Context(), changesapp.RepoSpecContextKey, "github.com/neugram/ng"))
req = req.WithContext(context.WithValue(req.Context(), changesapp.BaseURIContextKey, "/changes"))
changesApp.ServeHTTP(w, req)
})
http.Handle("/changes", issuesHandler)
http.Handle("/changes/", issuesHandler)