Skip to content

Commit

Permalink
Uplift branch_protection resource to use v4 API
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmarabeas committed Jun 16, 2020
1 parent 60fff96 commit 8430e4b
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 532 deletions.
40 changes: 40 additions & 0 deletions github/migrate_github_branch_protection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package github

import "github.com/hashicorp/terraform/helper/schema"

func resourceGithubBranchProtectionV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"repository": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"branch": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}

func resourceGithubBranchProtectionUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
repoName := rawState["repository"].(string)
repoID, err := getRepositoryID(repoName, meta)
if err != nil {
return nil, err
}

branch := rawState["branch"].(string)
protectionRuleID, err := getBranchProtectionID(repoName, branch, meta)
if err != nil {
return nil, err
}

rawState[id] = protectionRuleID
rawState[repositoryID] = repoID
rawState[pattern] = branch

return rawState, nil
}
Loading

0 comments on commit 8430e4b

Please sign in to comment.