ability to get team list from Gogs

This commit is contained in:
Brad Rydzewski 2016-05-11 12:32:18 -07:00
parent 09f7a5f804
commit 2e709fb6a9
4 changed files with 32 additions and 6 deletions

View file

@ -113,8 +113,17 @@ func (c *client) Auth(token, secret string) (string, error) {
// Teams is not supported by the Gogs driver. // Teams is not supported by the Gogs driver.
func (c *client) Teams(u *model.User) ([]*model.Team, error) { func (c *client) Teams(u *model.User) ([]*model.Team, error) {
var empty []*model.Team client := c.newClientToken(u.Token)
return empty, nil orgs, err := client.ListMyOrgs()
if err != nil {
return nil, err
}
var teams []*model.Team
for _, org := range orgs {
teams = append(teams, toTeam(org, c.URL))
}
return teams, nil
} }
// Repo returns the named Gogs repository. // Repo returns the named Gogs repository.

View file

@ -143,13 +143,11 @@ func Test_gogs(t *testing.T) {
g.It("Should return no-op for usupporeted features", func() { g.It("Should return no-op for usupporeted features", func() {
_, err1 := c.Auth("octocat", "4vyW6b49Z") _, err1 := c.Auth("octocat", "4vyW6b49Z")
_, err2 := c.Teams(nil) err2 := c.Status(nil, nil, nil, "")
err3 := c.Status(nil, nil, nil, "") err3 := c.Deactivate(nil, nil, "")
err4 := c.Deactivate(nil, nil, "")
g.Assert(err1 != nil).IsTrue() g.Assert(err1 != nil).IsTrue()
g.Assert(err2 == nil).IsTrue() g.Assert(err2 == nil).IsTrue()
g.Assert(err3 == nil).IsTrue() g.Assert(err3 == nil).IsTrue()
g.Assert(err4 == nil).IsTrue()
}) })
}) })
} }

View file

@ -56,6 +56,14 @@ func toPerm(from gogs.Permission) *model.Perm {
} }
} }
// helper function that converts a Gogs team to a Drone team.
func toTeam(from *gogs.Organization, link string) *model.Team {
return &model.Team{
Login: from.UserName,
Avatar: expandAvatar(link, from.AvatarUrl),
}
}
// helper function that extracts the Build data from a Gogs push hook // helper function that extracts the Build data from a Gogs push hook
func buildFromPush(hook *pushHook) *model.Build { func buildFromPush(hook *pushHook) *model.Build {
avatar := expandAvatar( avatar := expandAvatar(

View file

@ -76,6 +76,17 @@ func Test_parse(t *testing.T) {
} }
}) })
g.It("Should return a Team struct from a Gogs Org", func() {
from := &gogs.Organization{
UserName: "drone",
AvatarUrl: "/avatars/1",
}
to := toTeam(from, "http://localhost:80")
g.Assert(to.Login).Equal(from.UserName)
g.Assert(to.Avatar).Equal("http://localhost:80/avatars/1")
})
g.It("Should return a Repo struct from a Gogs Repo", func() { g.It("Should return a Repo struct from a Gogs Repo", func() {
from := gogs.Repository{ from := gogs.Repository{
FullName: "gophers/hello-world", FullName: "gophers/hello-world",