Skip to content

Commit

Permalink
Merge branch 'master' into ap_go_github_upgrade_v31
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
  • Loading branch information
anGie44 committed May 5, 2020
2 parents 41376f1 + b680bac commit 7834ac2
Show file tree
Hide file tree
Showing 1,503 changed files with 306,970 additions and 2,524 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
-keyout github/test-fixtures/key.pem -out github/test-fixtures/cert.pem
- name: Acceptance Tests
uses: terraformtesting/acceptance-tests@v1.2.0
uses: terraformtesting/acceptance-tests@v1.3.0
with:
RUN_FILTER: ${{ env.RUN_FILTER }}
GITHUB_ORGANIZATION: terraformtesting
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ branches:
- master

install:
# This script is used by the Travis build to install a cookie for
# go.googlesource.com so rate limits are higher when using `go get` to fetch
# packages that live there.
# See: https://github.com/golang/go/issues/12933
- bash scripts/gogetcookie.sh
- make tools

matrix:
Expand Down
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
## 2.7.0 (Unreleased)
## 2.8.0 (Unreleased)

BUG FIXES:

* Documentation Fix for `github_branch_protection` resource [GH-410]
* Documentation Layout Fix for `github_ip_ranges` and `github_membership` data sources [GH-423]
* Documentation Fix for `github_repository_file` import [GH-443]

## 2.7.0 (May 01, 2020)

BUG FIXES:

* Add Missing Acceptance Test ([#427](https://github.com/terraform-providers/terraform-provider-github/issues/427))

ENHANCEMENTS:

* Add GraphQL Client ([#331](https://github.com/terraform-providers/terraform-provider-github/issues/331))
* **New Data Source** `github_branch` ([#364](https://github.com/terraform-providers/terraform-provider-github/issues/364))
* **New Resource** `github_branch` ([#364](https://github.com/terraform-providers/terraform-provider-github/issues/364))


## 2.6.1 (April 07, 2020)

BUG FIXES:
Expand Down
5 changes: 2 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ PKG_NAME=github
default: build

tools:
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint

build: fmtcheck
go install
Expand Down Expand Up @@ -67,4 +67,3 @@ endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck lint tools test-compile website website-lint website-test

69 changes: 69 additions & 0 deletions github/data_source_github_branch.go
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
}
74 changes: 74 additions & 0 deletions github/data_source_github_branch_test.go
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)
}
34 changes: 17 additions & 17 deletions github/data_source_github_collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,23 @@ func flattenGitHubCollaborators(collaborators []*github.User) ([]interface{}, er
for _, c := range collaborators {
result := make(map[string]interface{})

result["login"] = c.Login
result["id"] = c.ID
result["url"] = c.URL
result["html_url"] = c.HTMLURL
result["following_url"] = c.FollowingURL
result["followers_url"] = c.FollowersURL
result["gists_url"] = c.GistsURL
result["starred_url"] = c.StarredURL
result["subscriptions_url"] = c.SubscriptionsURL
result["organizations_url"] = c.OrganizationsURL
result["repos_url"] = c.ReposURL
result["events_url"] = c.EventsURL
result["received_events_url"] = c.ReceivedEventsURL
result["type"] = c.Type
result["site_admin"] = c.SiteAdmin

permissionName, err := getRepoPermission(c.Permissions)
result["login"] = c.GetLogin()
result["id"] = c.GetID()
result["url"] = c.GetURL()
result["html_url"] = c.GetHTMLURL()
result["following_url"] = c.GetFollowingURL()
result["followers_url"] = c.GetFollowersURL()
result["gists_url"] = c.GetGistsURL()
result["starred_url"] = c.GetStarredURL()
result["subscriptions_url"] = c.GetSubscriptionsURL()
result["organizations_url"] = c.GetOrganizationsURL()
result["repos_url"] = c.GetReposURL()
result["events_url"] = c.GetEventsURL()
result["received_events_url"] = c.GetReceivedEventsURL()
result["type"] = c.GetType()
result["site_admin"] = c.GetSiteAdmin()

permissionName, err := getRepoPermission(c.GetPermissions())
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions github/data_source_github_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func dataSourceGithubMembershipRead(d *schema.ResourceData, meta interface{}) er
return err
}

d.SetId(buildTwoPartID(membership.Organization.Login, membership.User.Login))
d.SetId(buildTwoPartID(membership.GetOrganization().GetLogin(), membership.GetUser().GetLogin()))

d.Set("username", membership.User.Login)
d.Set("role", membership.Role)
d.Set("username", membership.GetUser().GetLogin())
d.Set("role", membership.GetRole())
d.Set("etag", resp.Header.Get("ETag"))
return nil
}
34 changes: 17 additions & 17 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,23 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er
d.SetId(repoName)

d.Set("name", repoName)
d.Set("description", repo.Description)
d.Set("homepage_url", repo.Homepage)
d.Set("private", repo.Private)
d.Set("has_issues", repo.HasIssues)
d.Set("has_wiki", repo.HasWiki)
d.Set("allow_merge_commit", repo.AllowMergeCommit)
d.Set("allow_squash_merge", repo.AllowSquashMerge)
d.Set("allow_rebase_merge", repo.AllowRebaseMerge)
d.Set("has_downloads", repo.HasDownloads)
d.Set("full_name", repo.FullName)
d.Set("default_branch", repo.DefaultBranch)
d.Set("html_url", repo.HTMLURL)
d.Set("ssh_clone_url", repo.SSHURL)
d.Set("svn_url", repo.SVNURL)
d.Set("git_clone_url", repo.GitURL)
d.Set("http_clone_url", repo.CloneURL)
d.Set("archived", repo.Archived)
d.Set("description", repo.GetDescription())
d.Set("homepage_url", repo.GetHomepage())
d.Set("private", repo.GetPrivate())
d.Set("has_issues", repo.GetHasIssues())
d.Set("has_wiki", repo.GetHasWiki())
d.Set("allow_merge_commit", repo.GetAllowMergeCommit())
d.Set("allow_squash_merge", repo.GetAllowSquashMerge())
d.Set("allow_rebase_merge", repo.GetAllowRebaseMerge())
d.Set("has_downloads", repo.GetHasDownloads())
d.Set("full_name", repo.GetFullName())
d.Set("default_branch", repo.GetDefaultBranch())
d.Set("html_url", repo.GetHTMLURL())
d.Set("ssh_clone_url", repo.GetSSHURL())
d.Set("svn_url", repo.GetSVNURL())
d.Set("git_clone_url", repo.GetGitURL())
d.Set("http_clone_url", repo.GetCloneURL())
d.Set("archived", repo.GetArchived())
d.Set("node_id", repo.GetNodeID())

err = d.Set("topics", flattenStringList(repo.Topics))
Expand Down
4 changes: 3 additions & 1 deletion github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func Provider() terraform.ResourceProvider {

ResourcesMap: map[string]*schema.Resource{
"github_actions_secret": resourceGithubActionsSecret(),
"github_branch": resourceGithubBranch(),
"github_branch_protection": resourceGithubBranchProtection(),
"github_issue_label": resourceGithubIssueLabel(),
"github_membership": resourceGithubMembership(),
Expand All @@ -69,6 +70,8 @@ func Provider() terraform.ResourceProvider {
},

DataSourcesMap: map[string]*schema.Resource{
"github_actions_public_key": dataSourceGithubActionsPublicKey(),
"github_branch": dataSourceGithubBranch(),
"github_collaborators": dataSourceGithubCollaborators(),
"github_ip_ranges": dataSourceGithubIpRanges(),
"github_membership": dataSourceGithubMembership(),
Expand All @@ -77,7 +80,6 @@ func Provider() terraform.ResourceProvider {
"github_repository": dataSourceGithubRepository(),
"github_team": dataSourceGithubTeam(),
"github_user": dataSourceGithubUser(),
"github_actions_public_key": dataSourceGithubActionsPublicKey(),
},
}

Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_actions_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceGithubActionsSecretCreateOrUpdate(d *schema.ResourceData, meta inte
return err
}

d.SetId(buildTwoPartID(&repo, &secretName))
d.SetId(buildTwoPartID(repo, secretName))
return resourceGithubActionsSecretRead(d, meta)
}

Expand Down
Loading

0 comments on commit 7834ac2

Please sign in to comment.