update listing

This commit is contained in:
Brad Rydzewski 2017-08-26 15:59:57 -07:00
parent cf549e47c3
commit 7826888729
6 changed files with 18 additions and 13 deletions

View file

@ -195,7 +195,7 @@ func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) {
if c.PrivateMode { if c.PrivateMode {
repo.Private = true repo.Private = true
} }
return toRepo(repo), nil return toRepo(repo, c.PrivateMode), nil
} }
// Repos returns a list of all repositories for the Gitea account, including // Repos returns a list of all repositories for the Gitea account, including
@ -210,7 +210,7 @@ func (c *client) Repos(u *model.User) ([]*model.Repo, error) {
} }
for _, repo := range all { for _, repo := range all {
repos = append(repos, toRepo(repo)) repos = append(repos, toRepo(repo, c.PrivateMode))
} }
return repos, err return repos, err
} }

View file

@ -13,12 +13,16 @@ import (
) )
// helper function that converts a Gitea repository to a Drone repository. // helper function that converts a Gitea repository to a Drone repository.
func toRepo(from *gitea.Repository) *model.Repo { func toRepo(from *gitea.Repository, privateMode bool) *model.Repo {
name := strings.Split(from.FullName, "/")[1] name := strings.Split(from.FullName, "/")[1]
avatar := expandAvatar( avatar := expandAvatar(
from.HTMLURL, from.HTMLURL,
from.Owner.AvatarURL, from.Owner.AvatarURL,
) )
private := from.Private
if privateMode {
private = true
}
return &model.Repo{ return &model.Repo{
Kind: model.RepoGit, Kind: model.RepoGit,
Name: name, Name: name,
@ -26,7 +30,7 @@ func toRepo(from *gitea.Repository) *model.Repo {
FullName: from.FullName, FullName: from.FullName,
Avatar: avatar, Avatar: avatar,
Link: from.HTMLURL, Link: from.HTMLURL,
IsPrivate: from.Private, IsPrivate: private,
Clone: from.CloneURL, Clone: from.CloneURL,
Branch: "master", Branch: "master",
} }

View file

@ -166,7 +166,7 @@ func Test_parse(t *testing.T) {
HTMLURL: "http://gitea.golang.org/gophers/hello-world", HTMLURL: "http://gitea.golang.org/gophers/hello-world",
Private: true, Private: true,
} }
repo := toRepo(&from) repo := toRepo(&from, false)
g.Assert(repo.FullName).Equal(from.FullName) g.Assert(repo.FullName).Equal(from.FullName)
g.Assert(repo.Owner).Equal(from.Owner.UserName) g.Assert(repo.Owner).Equal(from.Owner.UserName)
g.Assert(repo.Name).Equal("hello-world") g.Assert(repo.Name).Equal("hello-world")

View file

@ -134,10 +134,7 @@ func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if c.PrivateMode { return toRepo(repo, c.PrivateMode), nil
repo.Private = true
}
return toRepo(repo), nil
} }
// Repos returns a list of all repositories for the Gogs account, including // Repos returns a list of all repositories for the Gogs account, including
@ -152,7 +149,7 @@ func (c *client) Repos(u *model.User) ([]*model.Repo, error) {
} }
for _, repo := range all { for _, repo := range all {
repos = append(repos, toRepo(repo)) repos = append(repos, toRepo(repo, c.PrivateMode))
} }
return repos, err return repos, err
} }

View file

@ -13,12 +13,16 @@ import (
) )
// helper function that converts a Gogs repository to a Drone repository. // helper function that converts a Gogs repository to a Drone repository.
func toRepo(from *gogs.Repository) *model.Repo { func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
name := strings.Split(from.FullName, "/")[1] name := strings.Split(from.FullName, "/")[1]
avatar := expandAvatar( avatar := expandAvatar(
from.HtmlUrl, from.HtmlUrl,
from.Owner.AvatarUrl, from.Owner.AvatarUrl,
) )
private := from.Private
if privateMode {
private = true
}
return &model.Repo{ return &model.Repo{
Kind: model.RepoGit, Kind: model.RepoGit,
Name: name, Name: name,
@ -26,7 +30,7 @@ func toRepo(from *gogs.Repository) *model.Repo {
FullName: from.FullName, FullName: from.FullName,
Avatar: avatar, Avatar: avatar,
Link: from.HtmlUrl, Link: from.HtmlUrl,
IsPrivate: from.Private, IsPrivate: private,
Clone: from.CloneUrl, Clone: from.CloneUrl,
Branch: "master", Branch: "master",
} }

View file

@ -165,7 +165,7 @@ func Test_parse(t *testing.T) {
HtmlUrl: "http://gogs.golang.org/gophers/hello-world", HtmlUrl: "http://gogs.golang.org/gophers/hello-world",
Private: true, Private: true,
} }
repo := toRepo(&from) repo := toRepo(&from, false)
g.Assert(repo.FullName).Equal(from.FullName) g.Assert(repo.FullName).Equal(from.FullName)
g.Assert(repo.Owner).Equal(from.Owner.UserName) g.Assert(repo.Owner).Equal(from.Owner.UserName)
g.Assert(repo.Name).Equal("hello-world") g.Assert(repo.Name).Equal("hello-world")