Skip to content
This repository has been archived by the owner on Jan 26, 2018. It is now read-only.

Commit

Permalink
Merge pull request #46 from marcinwyszynski/master
Browse files Browse the repository at this point in the history
Explicitly show the required number of approvals
  • Loading branch information
bradrydzewski authored Aug 30, 2016
2 parents ca1613a + ab2d153 commit c5f537d
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 161 deletions.
13 changes: 7 additions & 6 deletions remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,20 @@ func (g *Github) GetContents(u *model.User, r *model.Repo, path string) ([]byte,
return content.Decode()
}

func (g *Github) SetStatus(u *model.User, r *model.Repo, num int, ok bool) error {
func (g *Github) SetStatus(u *model.User, r *model.Repo, num, granted, required int) error {
client := setupClient(g.API, u.Token)

pr, _, err := client.PullRequests.Get(r.Owner, r.Name, num)
if err != nil {
return err
}

status := "pending"
desc := "this commit is pending approval"
if ok {
status = "success"
desc = "this commit looks good"
status := "success"
desc := "this commit looks good"

if granted < required {
status = "pending"
desc = fmt.Sprintf("%d of %d required approvals granted", granted, required)
}

data := github.RepoStatus{
Expand Down
204 changes: 116 additions & 88 deletions remote/mock/remote.go
Original file line number Diff line number Diff line change
@@ -1,75 +1,101 @@
package mock

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)

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)

Expand All @@ -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, _a4
func (_m *Remote) SetStatus(_a0 *model.User, _a1 *model.Repo, _a2 int, _a3 int, _a4 int) error {
ret := _m.Called(_a0, _a1, _a2, _a3, _a4)

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, int, int) error); ok {
r0 = rf(_a0, _a1, _a2, _a3, _a4)
} else {
r1 = ret.Error(1)
r0 = ret.Error(0)
}

return r0, r1
return r0
}
6 changes: 3 additions & 3 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Remote interface {
GetContents(*model.User, *model.Repo, string) ([]byte, error)

// SetStatus adds or updates the pull request status in the remote system.
SetStatus(*model.User, *model.Repo, int, bool) error
SetStatus(*model.User, *model.Repo, int, int, int) error

// GetHook gets the hook from the http Request.
GetHook(r *http.Request) (*model.Hook, error)
Expand Down Expand Up @@ -108,8 +108,8 @@ func DelHook(c context.Context, u *model.User, r *model.Repo, hook string) error
}

// SetStatus adds or updates the pull request status in the remote system.
func SetStatus(c context.Context, u *model.User, r *model.Repo, num int, ok bool) error {
return FromContext(c).SetStatus(u, r, num, ok)
func SetStatus(c context.Context, u *model.User, r *model.Repo, num, granted, required int) error {
return FromContext(c).SetStatus(u, r, num, granted, required)
}

// GetHook gets the hook from the http Request.
Expand Down
Loading

0 comments on commit c5f537d

Please sign in to comment.