Skip to content

Commit

Permalink
Add visibility parameter to repository resource
Browse files Browse the repository at this point in the history
Adds the additional visibility parameter allowing for enterprise
accounts to set the repository to be only internally visible.

Resolves #304
  • Loading branch information
patrickmarabeas committed May 11, 2020
1 parent 91fc6ed commit 24a0b33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func resourceGithubRepository() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"visibility": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"public", "private", "internal"}, false),
},
"has_issues": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -179,6 +184,7 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
Description: github.String(d.Get("description").(string)),
Homepage: github.String(d.Get("homepage_url").(string)),
Private: github.Bool(d.Get("private").(bool)),
Visibility: github.String(d.Get("visibility").(string)),
HasDownloads: github.Bool(d.Get("has_downloads").(bool)),
HasIssues: github.Bool(d.Get("has_issues").(bool)),
HasProjects: github.Bool(d.Get("has_projects").(bool)),
Expand Down Expand Up @@ -303,6 +309,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
d.Set("description", repo.GetDescription())
d.Set("homepage_url", repo.GetHomepage())
d.Set("private", repo.GetPrivate())
d.Set("visibility", repo.GetVisibility())
d.Set("has_issues", repo.GetHasIssues())
d.Set("has_projects", repo.GetHasProjects())
d.Set("has_wiki", repo.GetHasWiki())
Expand Down
4 changes: 4 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ type testAccGithubRepositoryExpectedAttributes struct {
Description string
Homepage string
Private bool
Visibility string
HasDownloads bool
HasIssues bool
HasProjects bool
Expand Down Expand Up @@ -594,6 +595,9 @@ func testAccCheckGithubRepositoryAttributes(repo *github.Repository, want *testA
if private := repo.GetPrivate(); private != want.Private {
return fmt.Errorf("got private %#v; want %#v", private, want.Private)
}
if visibility := repo.GetVisibility(); visibility != want.Visibility {
return fmt.Errorf("got visibility %#v; want %#v", visibility, want.Visibility)
}
if hasIssues := repo.GetHasIssues(); hasIssues != want.HasIssues {
return fmt.Errorf("got has issues %#v; want %#v", hasIssues, want.HasIssues)
}
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ The following arguments are supported:

* `private` - (Optional) Set to `true` to create a private repository.
Repositories are created as public (e.g. open source) by default.

* `visibility` - (Optional) Can be `public` or `private`. If your organization is associated with an enterprise account
using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, visibility can also be `internal`. The `visibility`
parameter overrides the `private` parameter.

* `has_issues` - (Optional) Set to `true` to enable the GitHub Issues features
on the repository.
Expand Down

0 comments on commit 24a0b33

Please sign in to comment.