Skip to content

Commit

Permalink
fixed token and user, get repositories from workspaces too
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Aug 20, 2024
1 parent 67db501 commit d488482
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,24 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
repos := []types.Repo{}
for _, repo := range conf.Source.BitBucket {
ran = true
client := bitbucket.NewBasicAuth(repo.Username, repo.Password)
if repo.Token != "" && repo.Password == "" {
repo.Password = repo.Token
}
if repo.User == "" {
repo.User = repo.Username
}

if repo.Username == "" && repo.User != "" {
repo.Username = repo.User
}

include := types.GetMap(repo.Include)
exclude := types.GetMap(repo.Exclude)
includeorgs := types.GetMap(repo.IncludeOrgs)
excludeorgs := types.GetMap(repo.ExcludeOrgs)

client := bitbucket.NewBasicAuth(repo.Username, repo.Password)

if repo.URL == "" {
repo.URL = bitbucket.DEFAULT_BITBUCKET_API_BASE_URL
sub = logger.CreateSubLogger("stage", "bitbucket", "url", repo.URL)
Expand Down Expand Up @@ -55,15 +68,45 @@ func Get(conf *types.Conf) ([]types.Repo, bool) {
continue
}

include := types.GetMap(repo.Include)
exclude := types.GetMap(repo.Exclude)
workspaces, err := client.Workspaces.List()
if err != nil {
sub.Error().
Msg(err.Error())
} else {
for _, workspace := range workspaces.Workspaces {
if workspace.Slug != repo.User {
if len(includeorgs) > 0 {
if !includeorgs[workspace.Slug] {
continue
}
}
if len(excludeorgs) > 0 {
if excludeorgs[workspace.Slug] {
continue
}
}
workspacerepos, err := client.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{Owner: workspace.Slug})
if err != nil {
sub.Error().
Msg(err.Error())
} else {
repositories.Items = append(repositories.Items, workspacerepos.Items...)
}

}
}
}

for _, r := range repositories.Items {
sub.Debug().Msg(r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string))
user := repo.User
if r.Owner != nil {
if _, ok := r.Owner["nickname"]; ok {
user = r.Owner["nickname"].(string)
if _, ok := r.Owner["username"]; ok {
user = r.Owner["username"].(string)
} else {
if _, ok := r.Owner["nickname"]; ok {
user = r.Owner["nickname"].(string)
}
}
}

Expand Down

0 comments on commit d488482

Please sign in to comment.