Skip to content

Commit

Permalink
Get user (#133)
Browse files Browse the repository at this point in the history
* get user from gitea

* better output

* gogs use "token user"
  • Loading branch information
cooperspencer authored Feb 7, 2023
1 parent 9d4a2cd commit 7bffb8d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
29 changes: 24 additions & 5 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ func Get(conf *types.Conf) []types.Repo {
if repo.URL == "" {
repo.URL = "https://gitea.com"
}
log.Info().
Str("stage", "gitea").
Str("url", repo.URL).
Msgf("grabbing repositories from %s", repo.User)
if repo.User == "" {
log.Info().
Str("stage", "gitea").
Str("url", repo.URL).
Msg("grabbing my repositories")
} else {
log.Info().
Str("stage", "gitea").
Str("url", repo.URL).
Msgf("grabbing repositories from %s", repo.User)
}
opt := gitea.ListReposOptions{}
opt.PageSize = 50
opt.Page = 1
Expand All @@ -178,13 +185,25 @@ func Get(conf *types.Conf) []types.Repo {
client, err = gitea.NewClient(repo.URL)
}

for {
if token != "" && repo.User == "" {
user, _, err := client.GetMyUserInfo()
if err != nil {
log.Fatal().
Str("stage", "gitea").
Str("url", repo.URL).
Msg(err.Error())
}
repo.User = user.UserName
}

if err != nil {
log.Fatal().
Str("stage", "gitea").
Str("url", repo.URL).
Msg(err.Error())
}

for {
repos, _, err := client.ListUserRepos(repo.User, opt)
if err != nil {
log.Fatal().
Expand Down
15 changes: 11 additions & 4 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ func addWiki(r github.Repository, repo types.GenRepo, token string) types.Repo {
func Get(conf *types.Conf) []types.Repo {
repos := []types.Repo{}
for _, repo := range conf.Source.Github {
log.Info().
Str("stage", "github").
Str("url", "https://github.com").
Msgf("grabbing the repositories from %s", repo.User)
if repo.User == "" {
log.Info().
Str("stage", "github").
Str("url", "https://github.com").
Msg("grabbing my repositories")
} else {
log.Info().
Str("stage", "github").
Str("url", "https://github.com").
Msgf("grabbing the repositories from %s", repo.User)
}

opt := &github.RepositoryListOptions{
ListOptions: github.ListOptions{
Expand Down
33 changes: 27 additions & 6 deletions gogs/gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,28 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
func Get(conf *types.Conf) []types.Repo {
repos := []types.Repo{}
for _, repo := range conf.Source.Gogs {
log.Info().
Str("stage", "gogs").
Str("url", repo.URL).
Msgf("grabbing repositories from %s", repo.User)
if repo.User == "" {
log.Info().
Str("stage", "gogs").
Str("url", repo.URL).
Msg("grabbing my repositories")
} else {
log.Info().
Str("stage", "gogs").
Str("url", repo.URL).
Msgf("grabbing repositories from %s", repo.User)
}

token := repo.GetToken()
client := gogs.NewClient(repo.URL, token)
gogsrepos, err := client.ListUserRepos(repo.User)
var gogsrepos []*gogs.Repository
var err error

if repo.User == "" {
gogsrepos, err = client.ListMyRepos()
} else {
gogsrepos, err = client.ListUserRepos(repo.User)
}
if err != nil {
log.Fatal().
Str("stage", "gogs").
Expand Down Expand Up @@ -203,7 +217,14 @@ func Get(conf *types.Conf) []types.Repo {
}
}
}
orgs, err := client.ListUserOrgs(repo.User)

var orgs []*gogs.Organization

if repo.User == "" {
orgs, err = client.ListMyOrgs()
} else {
orgs, err = client.ListUserOrgs(repo.User)
}
if err != nil {
log.Fatal().
Str("stage", "gogs").
Expand Down

0 comments on commit 7bffb8d

Please sign in to comment.