Skip to content

Commit

Permalink
Add an --all flag to the repo-register command
Browse files Browse the repository at this point in the history
Adds an optional --all flag to the repo-register command that issues an event to reconcile all available repositories.

Fixes: #3269
  • Loading branch information
jhrozek committed Jun 20, 2024
1 parent 7e63c4b commit 0b51428
Showing 1 changed file with 27 additions and 3 deletions.
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")
}

0 comments on commit 0b51428

Please sign in to comment.