Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an --all flag to the repo-register command #3681

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions cmd/cli/app/repo/repo_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,47 @@ var repoRegisterCmd = &cobra.Command{
//
//nolint:gocyclo
func RegisterCmd(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc.ClientConn) error {
client := minderv1.NewRepositoryServiceClient(conn)
repoClient := minderv1.NewRepositoryServiceClient(conn)

provider := viper.GetString("provider")
project := viper.GetString("project")
inputRepoList := viper.GetStringSlice("name")
registerAll := viper.GetBool("all")

// No longer print usage on returned error, since we've parsed our inputs
// See https://github.com/spf13/cobra/issues/340#issuecomment-374617413
cmd.SilenceUsage = true

if registerAll {
if len(inputRepoList) > 0 {
return cli.MessageAndError("Cannot use --all with --name", nil)
}

providerClient := minderv1.NewProvidersServiceClient(conn)
_, err := providerClient.ReconcileEntityRegistration(ctx, &minderv1.ReconcileEntityRegistrationRequest{
Context: &minderv1.Context{
Provider: &provider,
Project: &project,
},
Entity: minderv1.Entity_ENTITY_REPOSITORIES.ToString(),
})
if err != nil {
return cli.MessageAndError("Error reconciling provider registration", err)
}

cmd.Println("Issued task to register all available repositories")
cmd.Println("Use `minder repo list` to check the list registered repositories")
return nil
}

for _, repo := range inputRepoList {
if err := cli.ValidateRepositoryName(repo); err != nil {
return cli.MessageAndError("Invalid repository name", err)
}
}

// Fetch remote repos, both registered and unregistered.
repos, err := fetchRepos(ctx, provider, project, client)
repos, err := fetchRepos(ctx, provider, project, repoClient)
if err != nil {
return cli.MessageAndError("Error getting registered repos", err)
}
Expand Down Expand Up @@ -115,7 +138,7 @@ func RegisterCmd(ctx context.Context, cmd *cobra.Command, _ []string, conn *grpc
}
}

results, warnings := registerRepos(project, client, selectedRepos)
results, warnings := registerRepos(project, repoClient, selectedRepos)
printWarnings(cmd, warnings)

printRepoRegistrationStatus(cmd, results)
Expand Down Expand Up @@ -245,4 +268,5 @@ func init() {
RepoCmd.AddCommand(repoRegisterCmd)
// Flags
repoRegisterCmd.Flags().StringSliceP("name", "n", []string{}, "List of repository names to register, i.e owner/repo,owner/repo")
repoRegisterCmd.Flags().BoolP("all", "a", false, "Register all unregistered repositories")
}