From 6e364068978bb421cb5b4ac96af3651ee42fece1 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Fri, 3 Nov 2023 13:25:29 +0200 Subject: [PATCH] change register repository calls to use one call per repo This makes processing faster and allows us to mass register repos. --- cmd/cli/app/repo/repo_register.go | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/cmd/cli/app/repo/repo_register.go b/cmd/cli/app/repo/repo_register.go index d0da04f53e..f79b6a5de2 100644 --- a/cmd/cli/app/repo/repo_register.go +++ b/cmd/cli/app/repo/repo_register.go @@ -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{ @@ -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), }