-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ap_go_github_upgrade_v31
# Conflicts: # go.mod
- Loading branch information
Showing
1,503 changed files
with
306,970 additions
and
2,524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGithubBranch() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubBranchRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"repository": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"branch": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"etag": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ref": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"sha": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubBranchRead(d *schema.ResourceData, meta interface{}) error { | ||
err := checkOrganization(meta) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := meta.(*Organization).v3client | ||
orgName := meta.(*Organization).name | ||
repoName := d.Get("repository").(string) | ||
branchName := d.Get("branch").(string) | ||
branchRefName := "refs/heads/" + branchName | ||
|
||
log.Printf("[DEBUG] Reading GitHub branch reference %s/%s (%s)", | ||
orgName, repoName, branchRefName) | ||
ref, resp, err := client.Git.GetRef( | ||
context.TODO(), orgName, repoName, branchRefName) | ||
if err != nil { | ||
return fmt.Errorf("Error reading GitHub branch reference %s/%s (%s): %s", | ||
orgName, repoName, branchRefName, err) | ||
} | ||
|
||
d.SetId(buildTwoPartID(repoName, branchName)) | ||
d.Set("etag", resp.Header.Get("ETag")) | ||
d.Set("ref", *ref.Ref) | ||
d.Set("sha", *ref.Object.SHA) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package github | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccGithubBranchDataSource_basic(t *testing.T) { | ||
|
||
var ( | ||
name = "main" | ||
repo = "test-repo" | ||
rn = "data.github_branch." + name | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "master"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "master"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, | ||
{ | ||
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "master"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "master"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, | ||
{ | ||
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "test-branch"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "test-branch"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, | ||
{ | ||
Config: testAccCheckGithubBranchDataSourceConfig(name, repo, "test-branch"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(rn, "repository", repo), | ||
resource.TestCheckResourceAttr(rn, "branch", "test-branch"), | ||
resource.TestCheckResourceAttrSet(rn, "etag"), | ||
resource.TestCheckResourceAttrSet(rn, "ref"), | ||
resource.TestCheckResourceAttrSet(rn, "sha"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
} | ||
|
||
func testAccCheckGithubBranchDataSourceConfig(name, repo, branch string) string { | ||
return fmt.Sprintf(` | ||
data "github_branch" "%s" { | ||
repository = "%s" | ||
branch = "%s" | ||
} | ||
`, name, repo, branch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.