diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index b4306a82..db467964 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -113,8 +113,17 @@ func (c *client) Auth(token, secret string) (string, error) { // Teams is not supported by the Gogs driver. func (c *client) Teams(u *model.User) ([]*model.Team, error) { - var empty []*model.Team - return empty, nil + client := c.newClientToken(u.Token) + 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. diff --git a/remote/gogs/gogs_test.go b/remote/gogs/gogs_test.go index 79293595..1d88d130 100644 --- a/remote/gogs/gogs_test.go +++ b/remote/gogs/gogs_test.go @@ -143,13 +143,11 @@ func Test_gogs(t *testing.T) { g.It("Should return no-op for usupporeted features", func() { _, err1 := c.Auth("octocat", "4vyW6b49Z") - _, err2 := c.Teams(nil) - err3 := c.Status(nil, nil, nil, "") - err4 := c.Deactivate(nil, nil, "") + err2 := c.Status(nil, nil, nil, "") + err3 := c.Deactivate(nil, nil, "") g.Assert(err1 != nil).IsTrue() g.Assert(err2 == nil).IsTrue() g.Assert(err3 == nil).IsTrue() - g.Assert(err4 == nil).IsTrue() }) }) } diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index c6941faa..32b1fb52 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -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 func buildFromPush(hook *pushHook) *model.Build { avatar := expandAvatar( diff --git a/remote/gogs/helper_test.go b/remote/gogs/helper_test.go index 9ec3d635..c203a856 100644 --- a/remote/gogs/helper_test.go +++ b/remote/gogs/helper_test.go @@ -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() { from := gogs.Repository{ FullName: "gophers/hello-world",