Skip to content

Commit

Permalink
change register repository calls to use one call per repo
Browse files Browse the repository at this point in the history
This makes processing faster and allows us to mass register repos.
  • Loading branch information
JAORMX committed Nov 3, 2023
1 parent d3cb8fa commit 6e36406
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions cmd/cli/app/repo/repo_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,27 @@ var repo_registerCmd = &cobra.Command{
os.Exit(1)
}

// Construct the RegisterRepositoryRequest
request := &pb.RegisterRepositoryRequest{
Provider: provider,
Repositories: selectedRepos,
ProjectId: projectID,
}
results := []*pb.RegisterRepoResult{}
for idx := range selectedRepos {
repo := selectedRepos[idx]
repoRegList := []*pb.UpstreamRepositoryRef{repo}
// Construct the RegisterRepositoryRequest
request := &pb.RegisterRepositoryRequest{
Provider: provider,
Repositories: repoRegList,
ProjectId: projectID,
}

// Register the repos
registerResp, err := client.RegisterRepository(context.Background(), request)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error registering repositories: %s\n", err)
os.Exit(1)
result, err := client.RegisterRepository(context.Background(), request)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error registering repository %s: %s\n", repo.Name, err)
continue
}

results = append(results, result.Results...)
}

// Register the repos
// The result gives a list of repositories with the registration status
// Let's parse the results and print the status
columns := []table.Column{
Expand All @@ -146,8 +153,8 @@ var repo_registerCmd = &cobra.Command{
{Title: "Message", Width: 60},
}

rows := make([]table.Row, len(registerResp.Results))
for i, result := range registerResp.Results {
rows := make([]table.Row, len(results))
for i, result := range results {
rows[i] = table.Row{
fmt.Sprintf("%s/%s", result.Repository.Owner, result.Repository.Name),
}
Expand Down

0 comments on commit 6e36406

Please sign in to comment.