diff --git a/Dockerfile b/Dockerfile index befcf14..bf36e3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,12 +5,24 @@ # Build the docker image: # # docker build --rm=true -t lgtm/lgtm . +# +# Push to Heroku +# +# heroku container:push web + +FROM golang:1.6 -FROM centurylink/ca-certs EXPOSE 8000 ENV DATABASE_DRIVER=sqlite3 ENV DATABASE_DATASOURCE=/var/lib/lgtm/lgtm.sqlite +ENV GO15VENDOREXPERIMENT=1 + +COPY . /go/src/github.com/lgtmco/lgtm +WORKDIR /go/src/github.com/lgtmco/lgtm + +RUN make deps +RUN make gen +RUN make build -ADD lgtm /lgtm -ENTRYPOINT ["/lgtm"] +CMD ["/go/src/github.com/lgtmco/lgtm/lgtm"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..62b4dc4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '2' +services: + app: + build: . + ports: + - 8000:8000 + depends_on: + - mysql + links: + - mysql + env_file: .env + environment: + - DATABASE_DRIVER=mysql + - DATABASE_DATASOURCE=root:lgtm@tcp(mysql:3306)/lgtm?parseTime=true + - GITHUB_URL=https://github.com + - GITHUB_SCOPE=user:email,read:org,repo + - DEBUG=1 + mysql: + image: mysql + environment: + MYSQL_ROOT_PASSWORD: lgtm + MYSQL_DATABASE: lgtm \ No newline at end of file diff --git a/main.go b/main.go index e63e57c..6282d40 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,8 @@ import ( ) var ( - addr = envflag.String("SERVER_ADDR", ":8000", "") + port = envflag.String("PORT", "8000", "") + addr = envflag.String("SERVER_ADDR", "", "") cert = envflag.String("SERVER_CERT", "", "") key = envflag.String("SERVER_KEY", "", "") @@ -40,11 +41,11 @@ func main() { if *cert != "" { logrus.Fatal( - http.ListenAndServeTLS(*addr, *cert, *key, handler), + http.ListenAndServeTLS(*addr + ":" + *port, *cert, *key, handler), ) } else { logrus.Fatal( - http.ListenAndServe(*addr, handler), + http.ListenAndServe(*addr + ":" + *port, handler), ) } } diff --git a/remote/mock/remote.go b/remote/mock/remote.go index 98d361f..3b42de9 100644 --- a/remote/mock/remote.go +++ b/remote/mock/remote.go @@ -1,75 +1,101 @@ -package mock +package mocks -import "github.com/stretchr/testify/mock" +import ( + "net/http" -import "net/http" -import "github.com/lgtmco/lgtm/model" + "github.com/lgtmco/lgtm/model" + "github.com/stretchr/testify/mock" +) +// Remote is an autogenerated mock type for the Remote type type Remote struct { mock.Mock } -func (_m *Remote) GetUser(_a0 http.ResponseWriter, _a1 *http.Request) (*model.User, error) { - ret := _m.Called(_a0, _a1) +// DelHook provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) DelHook(_a0 *model.User, _a1 *model.Repo, _a2 string) error { + ret := _m.Called(_a0, _a1, _a2) - var r0 *model.User - if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) *model.User); ok { - r0 = rf(_a0, _a1) + var r0 error + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetComments provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) GetComments(_a0 *model.User, _a1 *model.Repo, _a2 int) ([]*model.Comment, error) { + ret := _m.Called(_a0, _a1, _a2) + + var r0 []*model.Comment + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, int) []*model.Comment); ok { + r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.User) + r0 = ret.Get(0).([]*model.Comment) } } var r1 error - if rf, ok := ret.Get(1).(func(http.ResponseWriter, *http.Request) error); ok { - r1 = rf(_a0, _a1) + if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, int) error); ok { + r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Remote) GetUserToken(_a0 string) (string, error) { - ret := _m.Called(_a0) - var r0 string - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(_a0) +// GetContents provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) GetContents(_a0 *model.User, _a1 *model.Repo, _a2 string) ([]byte, error) { + ret := _m.Called(_a0, _a1, _a2) + + var r0 []byte + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) []byte); ok { + r0 = rf(_a0, _a1, _a2) } else { - r0 = ret.Get(0).(string) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } } var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, string) error); ok { + r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Remote) GetTeams(_a0 *model.User) ([]*model.Team, error) { - ret := _m.Called(_a0) - var r0 []*model.Team - if rf, ok := ret.Get(0).(func(*model.User) []*model.Team); ok { - r0 = rf(_a0) +// GetHook provides a mock function with given fields: r +func (_m *Remote) GetHook(r *http.Request) (*model.Hook, error) { + ret := _m.Called(r) + + var r0 *model.Hook + if rf, ok := ret.Get(0).(func(*http.Request) *model.Hook); ok { + r0 = rf(r) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Team) + r0 = ret.Get(0).(*model.Hook) } } var r1 error - if rf, ok := ret.Get(1).(func(*model.User) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(*http.Request) error); ok { + r1 = rf(r) } else { r1 = ret.Error(1) } return r0, r1 } + +// GetMembers provides a mock function with given fields: _a0, _a1 func (_m *Remote) GetMembers(_a0 *model.User, _a1 string) ([]*model.Member, error) { ret := _m.Called(_a0, _a1) @@ -91,15 +117,17 @@ func (_m *Remote) GetMembers(_a0 *model.User, _a1 string) ([]*model.Member, erro return r0, r1 } -func (_m *Remote) GetRepo(_a0 *model.User, _a1 string, _a2 string) (*model.Repo, error) { + +// GetPerm provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) GetPerm(_a0 *model.User, _a1 string, _a2 string) (*model.Perm, error) { ret := _m.Called(_a0, _a1, _a2) - var r0 *model.Repo - if rf, ok := ret.Get(0).(func(*model.User, string, string) *model.Repo); ok { + var r0 *model.Perm + if rf, ok := ret.Get(0).(func(*model.User, string, string) *model.Perm); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Repo) + r0 = ret.Get(0).(*model.Perm) } } @@ -112,15 +140,17 @@ func (_m *Remote) GetRepo(_a0 *model.User, _a1 string, _a2 string) (*model.Repo, return r0, r1 } -func (_m *Remote) GetPerm(_a0 *model.User, _a1 string, _a2 string) (*model.Perm, error) { + +// GetRepo provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) GetRepo(_a0 *model.User, _a1 string, _a2 string) (*model.Repo, error) { ret := _m.Called(_a0, _a1, _a2) - var r0 *model.Perm - if rf, ok := ret.Get(0).(func(*model.User, string, string) *model.Perm); ok { + var r0 *model.Repo + if rf, ok := ret.Get(0).(func(*model.User, string, string) *model.Repo); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Perm) + r0 = ret.Get(0).(*model.Repo) } } @@ -133,6 +163,8 @@ func (_m *Remote) GetPerm(_a0 *model.User, _a1 string, _a2 string) (*model.Perm, return r0, r1 } + +// GetRepos provides a mock function with given fields: _a0 func (_m *Remote) GetRepos(_a0 *model.User) ([]*model.Repo, error) { ret := _m.Called(_a0) @@ -154,102 +186,98 @@ func (_m *Remote) GetRepos(_a0 *model.User) ([]*model.Repo, error) { return r0, r1 } -func (_m *Remote) SetHook(_a0 *model.User, _a1 *model.Repo, _a2 string) error { - ret := _m.Called(_a0, _a1, _a2) - var r0 error - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) error); ok { - r0 = rf(_a0, _a1, _a2) +// GetTeams provides a mock function with given fields: _a0 +func (_m *Remote) GetTeams(_a0 *model.User) ([]*model.Team, error) { + ret := _m.Called(_a0) + + var r0 []*model.Team + if rf, ok := ret.Get(0).(func(*model.User) []*model.Team); ok { + r0 = rf(_a0) } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.Team) + } } - return r0 -} -func (_m *Remote) DelHook(_a0 *model.User, _a1 *model.Repo, _a2 string) error { - ret := _m.Called(_a0, _a1, _a2) - - var r0 error - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) error); ok { - r0 = rf(_a0, _a1, _a2) + var r1 error + if rf, ok := ret.Get(1).(func(*model.User) error); ok { + r1 = rf(_a0) } else { - r0 = ret.Error(0) + r1 = ret.Error(1) } - return r0 + return r0, r1 } -func (_m *Remote) GetComments(_a0 *model.User, _a1 *model.Repo, _a2 int) ([]*model.Comment, error) { - ret := _m.Called(_a0, _a1, _a2) - var r0 []*model.Comment - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, int) []*model.Comment); ok { - r0 = rf(_a0, _a1, _a2) +// GetUser provides a mock function with given fields: _a0, _a1 +func (_m *Remote) GetUser(_a0 http.ResponseWriter, _a1 *http.Request) (*model.User, error) { + ret := _m.Called(_a0, _a1) + + var r0 *model.User + if rf, ok := ret.Get(0).(func(http.ResponseWriter, *http.Request) *model.User); ok { + r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Comment) + r0 = ret.Get(0).(*model.User) } } var r1 error - if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, int) error); ok { - r1 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(1).(func(http.ResponseWriter, *http.Request) error); ok { + r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Remote) GetContents(_a0 *model.User, _a1 *model.Repo, _a2 string) ([]byte, error) { - ret := _m.Called(_a0, _a1, _a2) - var r0 []byte - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) []byte); ok { - r0 = rf(_a0, _a1, _a2) +// GetUserToken provides a mock function with given fields: _a0 +func (_m *Remote) GetUserToken(_a0 string) (string, error) { + ret := _m.Called(_a0) + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(_a0) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } + r0 = ret.Get(0).(string) } var r1 error - if rf, ok := ret.Get(1).(func(*model.User, *model.Repo, string) error); ok { - r1 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Remote) SetStatus(_a0 *model.User, _a1 *model.Repo, _a2 int, _a3 bool) error { - ret := _m.Called(_a0, _a1, _a2, _a3) + +// SetHook provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Remote) SetHook(_a0 *model.User, _a1 *model.Repo, _a2 string) error { + ret := _m.Called(_a0, _a1, _a2) var r0 error - if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, int, bool) error); ok { - r0 = rf(_a0, _a1, _a2, _a3) + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, string) error); ok { + r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) } return r0 } -func (_m *Remote) GetHook(r *http.Request) (*model.Hook, error) { - ret := _m.Called(r) - var r0 *model.Hook - if rf, ok := ret.Get(0).(func(*http.Request) *model.Hook); ok { - r0 = rf(r) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Hook) - } - } +// SetStatus provides a mock function with given fields: _a0, _a1, _a2, _a3 +func (_m *Remote) SetStatus(_a0 *model.User, _a1 *model.Repo, _a2 int, _a3 bool) error { + ret := _m.Called(_a0, _a1, _a2, _a3) - var r1 error - if rf, ok := ret.Get(1).(func(*http.Request) error); ok { - r1 = rf(r) + var r0 error + if rf, ok := ret.Get(0).(func(*model.User, *model.Repo, int, bool) error); ok { + r0 = rf(_a0, _a1, _a2, _a3) } else { - r1 = ret.Error(1) + r0 = ret.Error(0) } - return r0, r1 + return r0 } diff --git a/store/mock/store.go b/store/mock/store.go index 506f50e..6a3d49e 100644 --- a/store/mock/store.go +++ b/store/mock/store.go @@ -1,55 +1,30 @@ -package mock +package mocks -import "github.com/stretchr/testify/mock" - -import "github.com/lgtmco/lgtm/model" +import ( + "github.com/lgtmco/lgtm/model" + "github.com/stretchr/testify/mock" +) +// Store is an autogenerated mock type for the Store type type Store struct { mock.Mock } -func (_m *Store) GetUser(_a0 int64) (*model.User, error) { +// CreateRepo provides a mock function with given fields: _a0 +func (_m *Store) CreateRepo(_a0 *model.Repo) error { ret := _m.Called(_a0) - var r0 *model.User - if rf, ok := ret.Get(0).(func(int64) *model.User); ok { + var r0 error + if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { r0 = rf(_a0) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.User) - } - } - - var r1 error - if rf, ok := ret.Get(1).(func(int64) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) + r0 = ret.Error(0) } - return r0, r1 + return r0 } -func (_m *Store) GetUserLogin(_a0 string) (*model.User, error) { - ret := _m.Called(_a0) - - var r0 *model.User - if rf, ok := ret.Get(0).(func(string) *model.User); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.User) - } - } - var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} +// CreateUser provides a mock function with given fields: _a0 func (_m *Store) CreateUser(_a0 *model.User) error { ret := _m.Called(_a0) @@ -62,11 +37,13 @@ func (_m *Store) CreateUser(_a0 *model.User) error { return r0 } -func (_m *Store) UpdateUser(_a0 *model.User) error { + +// DeleteRepo provides a mock function with given fields: _a0 +func (_m *Store) DeleteRepo(_a0 *model.Repo) error { ret := _m.Called(_a0) var r0 error - if rf, ok := ret.Get(0).(func(*model.User) error); ok { + if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { r0 = rf(_a0) } else { r0 = ret.Error(0) @@ -74,6 +51,8 @@ func (_m *Store) UpdateUser(_a0 *model.User) error { return r0 } + +// DeleteUser provides a mock function with given fields: _a0 func (_m *Store) DeleteUser(_a0 *model.User) error { ret := _m.Called(_a0) @@ -86,6 +65,8 @@ func (_m *Store) DeleteUser(_a0 *model.User) error { return r0 } + +// GetRepo provides a mock function with given fields: _a0 func (_m *Store) GetRepo(_a0 int64) (*model.Repo, error) { ret := _m.Called(_a0) @@ -107,33 +88,37 @@ func (_m *Store) GetRepo(_a0 int64) (*model.Repo, error) { return r0, r1 } -func (_m *Store) GetRepoSlug(_a0 string) (*model.Repo, error) { + +// GetRepoMulti provides a mock function with given fields: _a0 +func (_m *Store) GetRepoMulti(_a0 ...string) ([]*model.Repo, error) { ret := _m.Called(_a0) - var r0 *model.Repo - if rf, ok := ret.Get(0).(func(string) *model.Repo); ok { - r0 = rf(_a0) + var r0 []*model.Repo + if rf, ok := ret.Get(0).(func(...string) []*model.Repo); ok { + r0 = rf(_a0...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.Repo) + r0 = ret.Get(0).([]*model.Repo) } } var r1 error - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(_a0) + if rf, ok := ret.Get(1).(func(...string) error); ok { + r1 = rf(_a0...) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Store) GetRepoMulti(_a0 ...string) ([]*model.Repo, error) { + +// GetRepoOwner provides a mock function with given fields: _a0 +func (_m *Store) GetRepoOwner(_a0 string) ([]*model.Repo, error) { ret := _m.Called(_a0) var r0 []*model.Repo - if rf, ok := ret.Get(0).(func(...string) []*model.Repo); ok { - r0 = rf(_a0...) + if rf, ok := ret.Get(0).(func(string) []*model.Repo); ok { + r0 = rf(_a0) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]*model.Repo) @@ -141,23 +126,25 @@ func (_m *Store) GetRepoMulti(_a0 ...string) ([]*model.Repo, error) { } var r1 error - if rf, ok := ret.Get(1).(func(...string) error); ok { - r1 = rf(_a0...) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) } else { r1 = ret.Error(1) } return r0, r1 } -func (_m *Store) GetRepoOwner(_a0 string) ([]*model.Repo, error) { + +// GetRepoSlug provides a mock function with given fields: _a0 +func (_m *Store) GetRepoSlug(_a0 string) (*model.Repo, error) { ret := _m.Called(_a0) - var r0 []*model.Repo - if rf, ok := ret.Get(0).(func(string) []*model.Repo); ok { + var r0 *model.Repo + if rf, ok := ret.Get(0).(func(string) *model.Repo); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*model.Repo) + r0 = ret.Get(0).(*model.Repo) } } @@ -170,18 +157,54 @@ func (_m *Store) GetRepoOwner(_a0 string) ([]*model.Repo, error) { return r0, r1 } -func (_m *Store) CreateRepo(_a0 *model.Repo) error { + +// GetUser provides a mock function with given fields: _a0 +func (_m *Store) GetUser(_a0 int64) (*model.User, error) { ret := _m.Called(_a0) - var r0 error - if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { + var r0 *model.User + if rf, ok := ret.Get(0).(func(int64) *model.User); ok { r0 = rf(_a0) } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.User) + } } - return r0 + var r1 error + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserLogin provides a mock function with given fields: _a0 +func (_m *Store) GetUserLogin(_a0 string) (*model.User, error) { + ret := _m.Called(_a0) + + var r0 *model.User + if rf, ok := ret.Get(0).(func(string) *model.User); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.User) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } + +// UpdateRepo provides a mock function with given fields: _a0 func (_m *Store) UpdateRepo(_a0 *model.Repo) error { ret := _m.Called(_a0) @@ -194,11 +217,13 @@ func (_m *Store) UpdateRepo(_a0 *model.Repo) error { return r0 } -func (_m *Store) DeleteRepo(_a0 *model.Repo) error { + +// UpdateUser provides a mock function with given fields: _a0 +func (_m *Store) UpdateUser(_a0 *model.User) error { ret := _m.Called(_a0) var r0 error - if rf, ok := ret.Get(0).(func(*model.Repo) error); ok { + if rf, ok := ret.Get(0).(func(*model.User) error); ok { r0 = rf(_a0) } else { r0 = ret.Error(0)