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

[WIP] cascades the maintainers team from the configuration #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions cache/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func GetPerm(c context.Context, user *model.User, owner, name string) (*model.Pe
}

// GetMembers returns the team members from the cache.
func GetMembers(c context.Context, user *model.User, team string) ([]*model.Member, error) {
func GetMembers(c context.Context, user *model.User, owner string, maintainers string) ([]*model.Member, error) {
key := fmt.Sprintf("members:%s",
team,
owner,
)
// if we fetch from the cache we can return immediately
val, err := FromContext(c).Get(key)
Expand All @@ -86,7 +86,7 @@ func GetMembers(c context.Context, user *model.User, team string) ([]*model.Memb
}
// else we try to grab from the remote system and
// populate our cache.
members, err := remote.GetMembers(c, user, team)
members, err := remote.GetMembers(c, user, owner, maintainers)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions cache/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func TestHelper(t *testing.T) {
})

g.It("Should set and get members", func() {
r.On("GetMembers", fakeUser, "drone").Return(fakeMembers, nil).Once()
p, err := GetMembers(c, fakeUser, "drone")
r.On("GetMembers", fakeUser, "drone", "maintainers").Return(fakeMembers, nil).Once()
p, err := GetMembers(c, fakeUser, "drone", "maintainers")
g.Assert(p).Equal(fakeMembers)
g.Assert(err).Equal(nil)
})
Expand All @@ -122,15 +122,15 @@ func TestHelper(t *testing.T) {
key := "members:drone"

Set(c, key, fakeMembers)
r.On("GetMembers", fakeUser, "drone").Return(nil, fakeErr).Once()
p, err := GetMembers(c, fakeUser, "drone")
r.On("GetMembers", fakeUser, "drone", "maintainers").Return(nil, fakeErr).Once()
p, err := GetMembers(c, fakeUser, "drone", "maintainers")
g.Assert(p).Equal(fakeMembers)
g.Assert(err).Equal(nil)
})

g.It("Should get member error", func() {
r.On("GetMembers", fakeUser, "drone").Return(nil, fakeErr).Once()
p, err := GetMembers(c, fakeUser, "drone")
r.On("GetMembers", fakeUser, "drone", "maintainers").Return(nil, fakeErr).Once()
p, err := GetMembers(c, fakeUser, "drone", "maintainers")
g.Assert(p == nil).IsTrue()
g.Assert(err).Equal(fakeErr)
})
Expand Down
6 changes: 3 additions & 3 deletions remote/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (g *Github) GetTeams(user *model.User) ([]*model.Team, error) {
return teams, nil
}

func (g *Github) GetMembers(user *model.User, team string) ([]*model.Member, error) {
func (g *Github) GetMembers(user *model.User, owner string, maintainers string) ([]*model.Member, error) {
client := setupClient(g.API, user.Token)
teams, _, err := client.Organizations.ListTeams(team, &github.ListOptions{PerPage: 100})
teams, _, err := client.Organizations.ListTeams(owner, &github.ListOptions{PerPage: 100})
if err != nil {
return nil, fmt.Errorf("Error accessing team list. %s", err)
}
var id int
for _, team := range teams {
if strings.ToLower(*team.Name) == "maintainers" {
if strings.ToLower(*team.Name) == strings.ToLower(maintainers) {
id = *team.ID
break
}
Expand Down
12 changes: 6 additions & 6 deletions remote/mock/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ func (_m *Remote) GetHook(r *http.Request) (*model.Hook, error) {
}

// 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)
func (_m *Remote) GetMembers(_a0 *model.User, _a1 string, _a2 string) ([]*model.Member, error) {
ret := _m.Called(_a0, _a1, _a2)

var r0 []*model.Member
if rf, ok := ret.Get(0).(func(*model.User, string) []*model.Member); ok {
r0 = rf(_a0, _a1)
if rf, ok := ret.Get(0).(func(*model.User, string, string) []*model.Member); ok {
r0 = rf(_a0, _a1, _a2)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Member)
}
}

var r1 error
if rf, ok := ret.Get(1).(func(*model.User, string) error); ok {
r1 = rf(_a0, _a1)
if rf, ok := ret.Get(1).(func(*model.User, string, string) error); ok {
r1 = rf(_a0, _a1, _a2)
} else {
r1 = ret.Error(1)
}
Expand Down
2 changes: 1 addition & 1 deletion web/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Hook(c *gin.Context) {
file, err := remote.GetContents(c, user, repo, "MAINTAINERS")
if err != nil {
log.Debugf("no MAINTAINERS file for %s. Checking for team members.", repo.Slug)
members, merr := cache.GetMembers(c, user, repo.Owner)
members, merr := cache.GetMembers(c, user, repo.Owner, rcfile.Team)
if merr != nil {
log.Errorf("Error getting repository %s. %s", repo.Slug, err)
log.Errorf("Error getting org members %s. %s", repo.Owner, merr)
Expand Down