ability to pull list of orgs and verify membership

This commit is contained in:
Brad Rydzewski
2015-04-15 00:20:00 -07:00
parent 0c3f9e5bde
commit c324d66872
3 changed files with 49 additions and 5 deletions

View File

@@ -26,8 +26,6 @@ type GitHub struct {
Secret string
PrivateMode bool
SkipVerify bool
Orgs []string
Open bool
cache *lru.Cache
}
@@ -40,8 +38,6 @@ func New(service *settings.Service) *GitHub {
Secret: service.OAuth.Secret,
PrivateMode: service.PrivateMode,
SkipVerify: service.SkipVerify,
Orgs: service.Orgs,
Open: service.Open,
}
var err error
github.cache, err = lru.New(1028)
@@ -81,6 +77,20 @@ func (g *GitHub) Login(token, secret string) (*common.User, error) {
return &user, nil
}
// Orgs fetches the organizations for the given user.
func (g *GitHub) Orgs(u *common.User) ([]string, error) {
client := NewClient(g.API, u.Token, g.SkipVerify)
orgs_ := []string{}
orgs, err := GetOrgs(client)
if err != nil {
return orgs_, err
}
for _, org := range orgs {
orgs_ = append(orgs_, *org.Login)
}
return orgs_, nil
}
// Repo fetches the named repository from the remote system.
func (g *GitHub) Repo(u *common.User, owner, name string) (*common.Repo, error) {
client := NewClient(g.API, u.Token, g.SkipVerify)