Skip to content

Commit

Permalink
Fix importing github_branch_protection
Browse files Browse the repository at this point in the history
Importing a branch protection rule by an ID of the form
<repo-node-id>:<pattern> was broken.

Closes: integrations#671
  • Loading branch information
tibbes committed Feb 28, 2021
1 parent e662b4f commit c98f482
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion github/migrate_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
Expand Down

0 comments on commit c98f482

Please sign in to comment.