@@ -11,11 +11,10 @@ import (
1111 "github.com/MakeNowJust/heredoc/v2"
1212 "github.com/charmbracelet/log"
1313 "github.com/ctrlplanedev/cli/internal/api"
14+ ctrlp "github.com/ctrlplanedev/cli/internal/common"
1415 "github.com/ctrlplanedev/cli/internal/kinds"
15- "github.com/ctrlplanedev/cli/pkg/resourceprovider"
1616 "github.com/google/go-github/v57/github"
1717 "github.com/spf13/cobra"
18- "github.com/spf13/viper"
1918 "golang.org/x/oauth2"
2019)
2120
@@ -161,9 +160,17 @@ func runSync(repoPath, token, name *string, states *[]string) func(cmd *cobra.Co
161160 }
162161 log .Debug ("Pull requests processed successfully" , "count" , len (resources ))
163162
163+ // Set default provider name if not provided
164+ if * name == "" {
165+ * name = fmt .Sprintf ("github-prs-%s-%s" , owner , repo )
166+ log .Debug ("Using generated provider name" , "name" , * name )
167+ } else {
168+ log .Debug ("Using provided provider name" , "name" , * name )
169+ }
170+
164171 // Upsert resources to Ctrlplane
165172 log .Debug ("Upserting resources to Ctrlplane" , "count" , len (resources ))
166- return upsertToCtrlplane (ctx , resources , owner , repo , * name )
173+ return ctrlp . UpsertResources (ctx , resources , name )
167174 }
168175}
169176
@@ -607,54 +614,3 @@ func initPullRequestMetadata(pr *github.PullRequest, owner, repo string) map[str
607614}
608615
609616// var relationshipRules = []api.Relationship{}
610-
611- // upsertToCtrlplane handles upserting resources to Ctrlplane
612- func upsertToCtrlplane (ctx context.Context , resources []api.ResourceProviderResource , owner , repo , name string ) error {
613- log .Debug ("Upserting resources to Ctrlplane" , "count" , len (resources ))
614-
615- if name == "" {
616- name = fmt .Sprintf ("github-prs-%s-%s" , owner , repo )
617- log .Debug ("Using generated provider name" , "name" , name )
618- } else {
619- log .Debug ("Using provided provider name" , "name" , name )
620- }
621-
622- apiURL := viper .GetString ("url" )
623- apiKey := viper .GetString ("api-key" )
624- workspaceId := viper .GetString ("workspace" )
625-
626- log .Debug ("API configuration" , "url" , apiURL , "workspace" , workspaceId )
627-
628- log .Debug ("Creating API client" )
629- ctrlplaneClient , err := api .NewAPIKeyClientWithResponses (apiURL , apiKey )
630- if err != nil {
631- log .Error ("Failed to create API client" , "error" , err )
632- return fmt .Errorf ("failed to create API client: %w" , err )
633- }
634-
635- log .Debug ("Creating resource provider" , "name" , name )
636- rp , err := resourceprovider .New (ctrlplaneClient , workspaceId , name )
637- if err != nil {
638- log .Error ("Failed to create resource provider" , "name" , name , "error" , err )
639- return fmt .Errorf ("failed to create resource provider: %w" , err )
640- }
641-
642- // log.Debug("Adding resource relationship rules", "rules_count", len(relationshipRules))
643- // err = rp.AddResourceRelationshipRule(ctx, relationshipRules)
644- // if err != nil {
645- // log.Error("Failed to add resource relationship rule", "name", name, "error", err)
646- // } else {
647- // log.Debug("Successfully added relationship rules")
648- // }
649-
650- log .Debug ("Upserting resources" , "count" , len (resources ))
651- upsertResp , err := rp .UpsertResource (ctx , resources )
652- if err != nil {
653- log .Error ("Failed to upsert resources" , "error" , err )
654- return fmt .Errorf ("failed to upsert resources: %w" , err )
655- }
656-
657- log .Info ("Response from upserting resources" , "status" , upsertResp .Status )
658- log .Debug ("Successfully upserted resources to Ctrlplane" )
659- return nil
660- }
0 commit comments