Skip to content

Commit

Permalink
Merge pull request integrations#288 from shouichi/fix-not-to-recreate…
Browse files Browse the repository at this point in the history
…-label

Fix not to recreate labels when update
  • Loading branch information
Jeremy Udit authored Mar 3, 2020
2 parents ee7be87 + 450d9cf commit d30d6d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 14 additions & 1 deletion github/resource_github_issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,23 @@ func resourceGithubIssueLabelCreateOrUpdate(d *schema.ResourceData, meta interfa
ctx = context.WithValue(ctx, ctxId, d.Id())
}

// Pull out the original name. If we already have a resource, this is the
// parsed ID. If not, it's the value given to the resource.
var originalName string
if d.Id() == "" {
originalName = name
} else {
var err error
_, originalName, err = parseTwoPartID(d.Id(), "repository", "name")
if err != nil {
return err
}
}

log.Printf("[DEBUG] Querying label existence: %s (%s/%s)",
name, orgName, repoName)
existing, resp, err := client.Issues.GetLabel(ctx,
orgName, repoName, name)
orgName, repoName, originalName)
if err != nil && resp.StatusCode != http.StatusNotFound {
return err
}
Expand Down
16 changes: 13 additions & 3 deletions github/resource_github_issue_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestAccGithubIssueLabel_basic(t *testing.T) {
var label github.Label
var label, updatedLabel github.Label

rn := "github_issue_label.test"
rString := acctest.RandString(5)
Expand All @@ -33,8 +33,9 @@ func TestAccGithubIssueLabel_basic(t *testing.T) {
{
Config: testAccGithubIssueLabelUpdateConfig(repoName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGithubIssueLabelExists(rn, &label),
testAccCheckGithubIssueLabelAttributes(&label, "bar", "FFFFFF"),
testAccCheckGithubIssueLabelExists(rn, &updatedLabel),
testAccCheckGithubIssueLabelAttributes(&updatedLabel, "bar", "FFFFFF"),
testAccCheckGithubIssueLabelIDUnchanged(&label, &updatedLabel),
),
},
{
Expand Down Expand Up @@ -168,6 +169,15 @@ func testAccCheckGithubIssueLabelAttributes(label *github.Label, name, color str
}
}

func testAccCheckGithubIssueLabelIDUnchanged(label, updatedLabel *github.Label) resource.TestCheckFunc {
return func(_ *terraform.State) error {
if *label.ID != *updatedLabel.ID {
return fmt.Errorf("label was recreated")
}
return nil
}
}

func testAccGithubIssueLabelDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Organization).client

Expand Down

0 comments on commit d30d6d0

Please sign in to comment.