Skip to content

Commit

Permalink
github_branch_default: send only fields that changed. Fixes integrati…
Browse files Browse the repository at this point in the history
  • Loading branch information
dee-kryvenko committed Jan 21, 2021
1 parent 3a9dbb0 commit e756e06
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions github/resource_github_branch_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"

"github.com/google/go-github/v32/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -38,14 +39,11 @@ func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta interface{})
repoName := d.Get("repository").(string)
defaultBranch := d.Get("branch").(string)

ctx := context.Background()

repository, _, err := client.Repositories.Get(ctx, owner, repoName)
if err != nil {
return err
repository := &github.Repository{
DefaultBranch: &defaultBranch,
}

repository.DefaultBranch = &defaultBranch
ctx := context.Background()

log.Printf("[DEBUG] Creating branch default: %s (%s/%s)", defaultBranch, owner, repoName)
if _, _, err := client.Repositories.Edit(ctx, owner, repoName, repository); err != nil {
Expand Down Expand Up @@ -87,17 +85,14 @@ func resourceGithubBranchDefaultDelete(d *schema.ResourceData, meta interface{})
repoName := d.Id()
defaultBranch := d.Get("branch").(string)

ctx := context.Background()

repository, _, err := client.Repositories.Get(ctx, owner, repoName)
if err != nil {
return err
repository := &github.Repository{
DefaultBranch: nil,
}

repository.DefaultBranch = nil
ctx := context.Background()

log.Printf("[DEBUG] Removing branch default: %s (%s/%s)", defaultBranch, owner, repoName)
_, _, err = client.Repositories.Edit(ctx, owner, repoName, repository)
_, _, err := client.Repositories.Edit(ctx, owner, repoName, repository)
return err
}

Expand All @@ -108,14 +103,11 @@ func resourceGithubBranchDefaultUpdate(d *schema.ResourceData, meta interface{})
repoName := d.Id()
defaultBranch := d.Get("branch").(string)

ctx := context.Background()

repository, _, err := client.Repositories.Get(ctx, owner, repoName)
if err != nil {
return err
repository := &github.Repository{
DefaultBranch: &defaultBranch,
}

repository.DefaultBranch = &defaultBranch
ctx := context.Background()

log.Printf("[DEBUG] Updating branch default: %s (%s/%s)", defaultBranch, owner, repoName)
if _, _, err := client.Repositories.Edit(ctx, owner, repoName, repository); err != nil {
Expand Down

0 comments on commit e756e06

Please sign in to comment.