From c98f482190b2f26506a6aff9e297767d778624ee Mon Sep 17 00:00:00 2001 From: Julian Tibble Date: Sun, 28 Feb 2021 22:59:19 +0000 Subject: [PATCH] Fix importing github_branch_protection Importing a branch protection rule by an ID of the form : was broken. Closes: https://github.com/integrations/terraform-provider-github/issues/671 --- github/migrate_github_branch_protection.go | 2 +- github/resource_github_branch_protection.go | 2 +- github/util_v4_branch_protection.go | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/github/migrate_github_branch_protection.go b/github/migrate_github_branch_protection.go index 02c537a5a5..f54957f23a 100644 --- a/github/migrate_github_branch_protection.go +++ b/github/migrate_github_branch_protection.go @@ -27,7 +27,7 @@ func resourceGithubBranchProtectionUpgradeV0(rawState map[string]interface{}, me } branch := rawState["branch"].(string) - protectionRuleID, err := getBranchProtectionID(repoName, branch, meta) + protectionRuleID, err := getBranchProtectionID(repoID, branch, meta) if err != nil { return nil, err } diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index 21311a7973..63b7c2e56a 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -307,7 +307,7 @@ func resourceGithubBranchProtectionImport(d *schema.ResourceData, meta interface } d.Set("repository_id", repoID) - id, err := getBranchProtectionID(repoName, pattern, meta) + id, err := getBranchProtectionID(repoID, pattern, meta) if err != nil { return nil, err } diff --git a/github/util_v4_branch_protection.go b/github/util_v4_branch_protection.go index ad4f880fea..5e175c6d90 100644 --- a/github/util_v4_branch_protection.go +++ b/github/util_v4_branch_protection.go @@ -255,7 +255,7 @@ func setPushes(protection BranchProtectionRule) []string { return pushActors } -func getBranchProtectionID(name string, pattern string, meta interface{}) (githubv4.ID, error) { +func getBranchProtectionID(repoID githubv4.ID, pattern string, meta interface{}) (githubv4.ID, error) { var query struct { Node struct { Repository struct { @@ -268,11 +268,10 @@ func getBranchProtectionID(name string, pattern string, meta interface{}) (githu } `graphql:"branchProtectionRules(first: $first, after: $cursor)"` ID string } `graphql:"... on Repository"` - } `graphql:"repository(owner: $owner, name: $name)"` + } `graphql:"node(id: $id)"` } variables := map[string]interface{}{ - "owner": githubv4.String(meta.(*Owner).name), - "name": githubv4.String(name), + "id": repoID, "first": githubv4.Int(100), "cursor": (*githubv4.String)(nil), }