Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
pullrequester
.test

testing
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: go

go:
- 1.9

branches:
only:
- master

before_install:
- ./look_for_logs.sh
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/lint/golint
- go get github.com/GeertJohan/fgt
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover;
fi

script:
- fgt golint $(find . | grep .go$ | grep -v pullrequester.pb.go)
- $HOME/gopath/bin/goveralls -service=travis-ci -ignore=pullrequester.go -package github.com/brotherlogic/pullrequester
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
protoc --proto_path ../../../ -I=./proto --go_out=plugins=grpc:./proto proto/pullrequester.proto
20 changes: 20 additions & 0 deletions look_for_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
grep log.Print * -Rl | grep .go$ | grep -v _test.go
RESULT=$?
if [ $RESULT != 1 ]; then
exit 1
fi

grep context.Background * -Rl | grep .go$ | grep -v _test.go
RESULT=$?
if [ $RESULT != 1 ]; then
exit 1
fi

RESULT1=$(grep "conn, err" *.go -R | wc | awk '{print $1}')
RESULT2=$(grep "conn.Close" *.go -R | wc| awk '{print $1}')

if [ $RESULT1 != $RESULT2 ]; then
echo "Missing Closes!"
exit 1
fi
76 changes: 76 additions & 0 deletions proto/pullrequester.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions proto/pullrequester.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

package pullrequester;

message Config {
int64 last_run = 1;
}

114 changes: 114 additions & 0 deletions pullrequester.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"time"

"github.com/brotherlogic/goserver"
"github.com/brotherlogic/keystore/client"
"golang.org/x/net/context"
"google.golang.org/grpc"

pbg "github.com/brotherlogic/goserver/proto"
"github.com/brotherlogic/goserver/utils"
pb "github.com/brotherlogic/pullrequester/proto"
)

const (
// KEY - where we store sale info
KEY = "/github.com/brotherlogic/pullrequester/config"
)

//Server main server type
type Server struct {
*goserver.GoServer
config *pb.Config
}

// Init builds the server
func Init() *Server {
s := &Server{
GoServer: &goserver.GoServer{},
config: &pb.Config{},
}
return s
}

func (s *Server) save(ctx context.Context) {
s.KSclient.Save(ctx, KEY, s.config)
}

func (s *Server) load(ctx context.Context) error {
config := &pb.Config{}
data, _, err := s.KSclient.Read(ctx, KEY, config)

if err != nil {
return err
}

s.config = data.(*pb.Config)
return nil
}

// DoRegister does RPC registration
func (s *Server) DoRegister(server *grpc.Server) {
// Pass
}

// ReportHealth alerts if we're not healthy
func (s *Server) ReportHealth() bool {
return true
}

// Shutdown the server
func (s *Server) Shutdown(ctx context.Context) error {
s.save(ctx)
return nil
}

// Mote promotes/demotes this server
func (s *Server) Mote(ctx context.Context, master bool) error {
if master {
err := s.load(ctx)
return err
}

return nil
}

// GetState gets the state of the server
func (s *Server) GetState() []*pbg.State {
return []*pbg.State{
&pbg.State{Key: "last_run", Value: s.config.LastRun},
}
}

func main() {
var quiet = flag.Bool("quiet", false, "Show all output")
var init = flag.Bool("init", false, "Prep server")
flag.Parse()

//Turn off logging
if *quiet {
log.SetFlags(0)
log.SetOutput(ioutil.Discard)
}
server := Init()
server.GoServer.KSclient = *keystoreclient.GetClient(server.DialMaster)
server.PrepServer()
server.Register = server
server.RegisterServer("pullrequester", false)

if *init {
ctx, cancel := utils.BuildContext("pullrequester", "pullrequester")
defer cancel()
server.config.LastRun = time.Now().Unix()
server.save(ctx)
return
}

fmt.Printf("%v", server.Serve())
}
4 changes: 4 additions & 0 deletions pullrequesterutils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package main

func doNothing() {
}
7 changes: 7 additions & 0 deletions pullrequesterutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "testing"

func TestBasic(t *testing.T) {
doNothing()
}