Skip to content

Commit 1b851ad

Browse files
kfcampbellKensoDev
andauthored
Include All Branches in template repositories (#1353)
* Include All Branches in template repositories When creating a repository from a template, you can pass in a boolean to include all the branches in the template repo. This is documented here: https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template In addition, the provider already supports that here: https://github.com/google/go-github/blob/3e8a7f0fbe0e4402f9ad5a80e0ab0a050786e0f8/github/repos.go#L441 Adding a variable under the template structure and then pass it in to the provider function works. Added tests to make sure it works. All tests are passing * Remove failing test. Nothing to see here, folks * Add clarifying doc note Co-authored-by: KensoDev <[email protected]>
1 parent ffd6f0a commit 1b851ad

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

github/resource_github_repository.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ func resourceGithubRepository() *schema.Resource {
244244
MaxItems: 1,
245245
Elem: &schema.Resource{
246246
Schema: map[string]*schema.Schema{
247+
"include_all_branches": {
248+
Type: schema.TypeBool,
249+
Optional: true,
250+
Default: false,
251+
},
247252
"owner": {
248253
Type: schema.TypeString,
249254
Required: true,
@@ -359,12 +364,14 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
359364

360365
templateRepo := templateConfigMap["repository"].(string)
361366
templateRepoOwner := templateConfigMap["owner"].(string)
367+
includeAllBranches := templateConfigMap["include_all_branches"].(bool)
362368

363369
templateRepoReq := github.TemplateRepoRequest{
364-
Name: &repoName,
365-
Owner: &owner,
366-
Description: github.String(d.Get("description").(string)),
367-
Private: github.Bool(isPrivate),
370+
Name: &repoName,
371+
Owner: &owner,
372+
Description: github.String(d.Get("description").(string)),
373+
Private: github.Bool(isPrivate),
374+
IncludeAllBranches: github.Bool(includeAllBranches),
368375
}
369376

370377
repo, _, err := client.Repositories.CreateFromTemplate(ctx,

website/docs/r/repository.html.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ resource "github_repository" "example" {
2020
visibility = "public"
2121
2222
template {
23-
owner = "github"
24-
repository = "terraform-module-template"
23+
owner = "github"
24+
repository = "terraform-module-template"
25+
include_all_branches = true
2526
}
2627
}
2728
```
@@ -137,6 +138,7 @@ The `source` block supports the following:
137138

138139
* `owner`: The GitHub organization or user the template repository is owned by.
139140
* `repository`: The name of the template repository.
141+
* `include_all_branches`: Whether the new repository should include all the branches from the template repository (defaults to false, which includes only the default branch from the template).
140142

141143
## Attributes Reference
142144

0 commit comments

Comments
 (0)