Skip to content

Commit

Permalink
get gitlab user (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer authored Jan 25, 2024
1 parent d1568d4 commit acbb331
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 15 additions & 4 deletions gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
}
ran = true

sub.Info().
Msgf("grabbing repositories from %s", repo.User)
gitlabrepos := []*gitlab.Project{}
gitlabgrouprepos := map[string][]*gitlab.Project{}
token := repo.GetToken()
client, err := gitlab.NewClient(token, gitlab.WithBaseURL(repo.URL))
if err != nil {
Expand All @@ -124,6 +120,21 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
continue
}

if repo.User == "" {
user, _, err := client.Users.CurrentUser()
if err != nil {
sub.Error().
Msg(err.Error())
continue
}
repo.User = user.Username
}

sub.Info().
Msgf("grabbing repositories from %s", repo.User)
gitlabrepos := []*gitlab.Project{}
gitlabgrouprepos := map[string][]*gitlab.Project{}

opt := &gitlab.ListProjectsOptions{}
users, _, err := client.Users.ListUsers(&gitlab.ListUsersOptions{Username: &repo.User})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
if err != nil {
if err == git.NoErrAlreadyUpToDate {
log.Info().
Str("stage", "onedev").
Str("stage", "github").
Str("url", r.URL).
Msg(err.Error())
} else {
Expand Down Expand Up @@ -401,7 +401,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
if err != nil {
if err == git.NoErrAlreadyUpToDate {
log.Info().
Str("stage", "onedev").
Str("stage", "sourcehut").
Str("url", r.URL).
Msg(err.Error())
} else {
Expand All @@ -428,7 +428,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
if err != nil {
if err == git.NoErrAlreadyUpToDate {
log.Info().
Str("stage", "onedev").
Str("stage", "sourcehut").
Str("url", r.URL).
Msg(err.Error())
} else {
Expand Down

0 comments on commit acbb331

Please sign in to comment.