Skip to content

Commit b599ebb

Browse files
authored
maint: gofmt clean up (#2888)
1 parent 1aa6d2b commit b599ebb

File tree

2 files changed

+175
-175
lines changed

2 files changed

+175
-175
lines changed

github/resource_github_repository.go

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -579,90 +579,90 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
579579
repoReq.Private = github.Bool(isPrivate)
580580

581581
if template, ok := d.GetOk("template"); ok {
582-
templateConfigBlocks := template.([]interface{})
583-
584-
for _, templateConfigBlock := range templateConfigBlocks {
585-
templateConfigMap, ok := templateConfigBlock.(map[string]interface{})
586-
if !ok {
587-
return errors.New("failed to unpack template configuration block")
588-
}
589-
590-
templateRepo := templateConfigMap["repository"].(string)
591-
templateRepoOwner := templateConfigMap["owner"].(string)
592-
includeAllBranches := templateConfigMap["include_all_branches"].(bool)
593-
594-
templateRepoReq := github.TemplateRepoRequest{
595-
Name: &repoName,
596-
Owner: &owner,
597-
Description: github.String(d.Get("description").(string)),
598-
Private: github.Bool(isPrivate),
599-
IncludeAllBranches: github.Bool(includeAllBranches),
600-
}
601-
602-
repo, _, err := client.Repositories.CreateFromTemplate(ctx,
603-
templateRepoOwner,
604-
templateRepo,
605-
&templateRepoReq,
606-
)
607-
if err != nil {
608-
return err
609-
}
610-
611-
d.SetId(*repo.Name)
612-
}
613-
} else if d.Get("fork").(bool) {
614-
// Handle repository forking
615-
sourceOwner := d.Get("source_owner").(string)
616-
sourceRepo := d.Get("source_repo").(string)
617-
requestedName := d.Get("name").(string)
618-
owner := meta.(*Owner).name
619-
log.Printf("[INFO] Creating fork of %s/%s in %s", sourceOwner, sourceRepo, owner)
620-
621-
if sourceOwner == "" || sourceRepo == "" {
622-
return fmt.Errorf("source_owner and source_repo must be provided when forking a repository")
623-
}
624-
625-
// Create the fork using the GitHub client library
626-
opts := &github.RepositoryCreateForkOptions{
627-
Name: requestedName,
582+
templateConfigBlocks := template.([]interface{})
583+
584+
for _, templateConfigBlock := range templateConfigBlocks {
585+
templateConfigMap, ok := templateConfigBlock.(map[string]interface{})
586+
if !ok {
587+
return errors.New("failed to unpack template configuration block")
628588
}
629-
630-
if meta.(*Owner).IsOrganization {
631-
opts.Organization = owner
589+
590+
templateRepo := templateConfigMap["repository"].(string)
591+
templateRepoOwner := templateConfigMap["owner"].(string)
592+
includeAllBranches := templateConfigMap["include_all_branches"].(bool)
593+
594+
templateRepoReq := github.TemplateRepoRequest{
595+
Name: &repoName,
596+
Owner: &owner,
597+
Description: github.String(d.Get("description").(string)),
598+
Private: github.Bool(isPrivate),
599+
IncludeAllBranches: github.Bool(includeAllBranches),
632600
}
633-
634-
fork, resp, err := client.Repositories.CreateFork(ctx, sourceOwner, sourceRepo, opts)
635-
601+
602+
repo, _, err := client.Repositories.CreateFromTemplate(ctx,
603+
templateRepoOwner,
604+
templateRepo,
605+
&templateRepoReq,
606+
)
636607
if err != nil {
637-
// Handle accepted error (202) which means the fork is being created asynchronously
638-
if _, ok := err.(*github.AcceptedError); ok {
639-
log.Printf("[INFO] Fork is being created asynchronously")
640-
// Despite the 202 status, the API should still return preliminary fork information
641-
if fork == nil {
642-
return fmt.Errorf("fork information not available after accepted status")
643-
}
644-
log.Printf("[DEBUG] Fork name: %s", fork.GetName())
645-
} else {
646-
return fmt.Errorf("failed to create fork: %v", err)
647-
}
648-
} else if resp != nil {
649-
log.Printf("[DEBUG] Fork response status: %d", resp.StatusCode)
608+
return err
650609
}
651-
652-
if fork == nil {
653-
return fmt.Errorf("fork creation failed - no repository returned")
610+
611+
d.SetId(*repo.Name)
612+
}
613+
} else if d.Get("fork").(bool) {
614+
// Handle repository forking
615+
sourceOwner := d.Get("source_owner").(string)
616+
sourceRepo := d.Get("source_repo").(string)
617+
requestedName := d.Get("name").(string)
618+
owner := meta.(*Owner).name
619+
log.Printf("[INFO] Creating fork of %s/%s in %s", sourceOwner, sourceRepo, owner)
620+
621+
if sourceOwner == "" || sourceRepo == "" {
622+
return fmt.Errorf("source_owner and source_repo must be provided when forking a repository")
623+
}
624+
625+
// Create the fork using the GitHub client library
626+
opts := &github.RepositoryCreateForkOptions{
627+
Name: requestedName,
628+
}
629+
630+
if meta.(*Owner).IsOrganization {
631+
opts.Organization = owner
632+
}
633+
634+
fork, resp, err := client.Repositories.CreateFork(ctx, sourceOwner, sourceRepo, opts)
635+
636+
if err != nil {
637+
// Handle accepted error (202) which means the fork is being created asynchronously
638+
if _, ok := err.(*github.AcceptedError); ok {
639+
log.Printf("[INFO] Fork is being created asynchronously")
640+
// Despite the 202 status, the API should still return preliminary fork information
641+
if fork == nil {
642+
return fmt.Errorf("fork information not available after accepted status")
643+
}
644+
log.Printf("[DEBUG] Fork name: %s", fork.GetName())
645+
} else {
646+
return fmt.Errorf("failed to create fork: %v", err)
654647
}
655-
656-
log.Printf("[INFO] Fork created with name: %s", fork.GetName())
657-
d.SetId(fork.GetName())
658-
log.Printf("[DEBUG] Set resource ID to just the name: %s", d.Id())
659-
660-
d.Set("name", fork.GetName())
661-
d.Set("full_name", fork.GetFullName()) // Add the full name for reference
662-
d.Set("html_url", fork.GetHTMLURL())
663-
d.Set("ssh_clone_url", fork.GetSSHURL())
664-
d.Set("git_clone_url", fork.GetGitURL())
665-
d.Set("http_clone_url", fork.GetCloneURL())
648+
} else if resp != nil {
649+
log.Printf("[DEBUG] Fork response status: %d", resp.StatusCode)
650+
}
651+
652+
if fork == nil {
653+
return fmt.Errorf("fork creation failed - no repository returned")
654+
}
655+
656+
log.Printf("[INFO] Fork created with name: %s", fork.GetName())
657+
d.SetId(fork.GetName())
658+
log.Printf("[DEBUG] Set resource ID to just the name: %s", d.Id())
659+
660+
d.Set("name", fork.GetName())
661+
d.Set("full_name", fork.GetFullName()) // Add the full name for reference
662+
d.Set("html_url", fork.GetHTMLURL())
663+
d.Set("ssh_clone_url", fork.GetSSHURL())
664+
d.Set("git_clone_url", fork.GetGitURL())
665+
d.Set("http_clone_url", fork.GetCloneURL())
666666
} else {
667667
// Create without a repository template
668668
var repo *github.Repository
@@ -789,7 +789,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
789789
// Set fork information if this is a fork
790790
if repo.GetFork() {
791791
d.Set("fork", true)
792-
792+
793793
// If the repository has parent information, set the source details
794794
if repo.Parent != nil {
795795
d.Set("source_owner", repo.Parent.GetOwner().GetLogin())

0 commit comments

Comments
 (0)