Skip to content

Commit

Permalink
gRPC address and skip empty HEAD
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
  • Loading branch information
bzz committed Aug 23, 2018
1 parent a2fdeef commit ab80968
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
22 changes: 13 additions & 9 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ var _ lookout.AnalyzerServer = &Analyzer{}

func (a *Analyzer) NotifyReviewEvent(ctx context.Context, e *lookout.ReviewEvent) (
*lookout.EventResponse, error) {
tmp, err := ioutil.TempDir("", "gometalint")
if err != nil {
log.Errorf(err, "cannot create tmp dir in %s", os.TempDir())
return nil, err
}
defer os.RemoveAll(tmp)

changes, err := a.DataClient.GetChanges(ctx, &lookout.ChangesRequest{
Head: &e.Head,
Base: &e.Base,
WantContents: true,
WantLanguage: true,
})
if err != nil {
log.Errorf(err, "failed on GetChanges from the DataService")
log.Errorf(err, "failed to GetChanges from a DataService")
return nil, err
}

tmp, err := ioutil.TempDir("", "gometalint")
if err != nil {
log.Errorf(err, "cannot create tmp dir in %s", os.TempDir())
return nil, err
}
defer os.RemoveAll(tmp)

for changes.Next() {
// saveFileToTmp(change.Head.File, tmp)
change := changes.Change()
if change.Head == nil {
continue
}

file := path.Join(tmp, path.Base(change.Head.Path))
err = ioutil.WriteFile(file, change.Head.Content, 0644)
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions cmd/gometalint-analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var (
)

type config struct {
Host string `envconfig:"HOST" default:"0.0.0.0"`
Port int `envconfig:"PORT" default:"2001"`
DataServerURL string `envconfig:"DATA_SERVER_URL" default:"ipv4://localhost:10301"`
Host string `envconfig:"HOST" default:"0.0.0.0"`
Port int `envconfig:"PORT" default:"2001"`
DataServiceURL string `envconfig:"DATA_SERVICE_URL" default:"ipv4://localhost:10301"`
}

func main() {
Expand All @@ -54,14 +54,20 @@ func main() {
envconfig.MustProcess("GOMETALINT", &conf)
log.Infof("Starting %s, %s", name, litter.Sdump(conf))

grpcAddr, err := grpchelper.ToGoGrpcAddress(conf.DataServiceURL)
if err != nil {
log.Errorf(err, "failed to parse DataService addres %s", conf.DataServiceURL)
return
}

conn, err := grpchelper.DialContext(
context.Background(),
conf.DataServerURL,
grpcAddr,
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.FailFast(false)),
)
if err != nil {
log.Errorf(err, "cannot create connection to DataServer %s", conf.DataServerURL)
log.Errorf(err, "cannot create connection to DataService %s", grpcAddr)
return
}

Expand Down

0 comments on commit ab80968

Please sign in to comment.