From c998ab3f115e790079e0a26b4352b3626a10c145 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Wed, 27 Jul 2022 17:04:31 -0700 Subject: [PATCH] Replaying the changes in #1162 without the binary (#1234) --- github/data_source_github_repository.go | 12 +++++++++++- website/docs/d/repository.html.markdown | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 37e6935ff2..ddee5c99ab 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -28,6 +28,11 @@ func dataSourceGithubRepository() *schema.Resource { Computed: true, ConflictsWith: []string{"full_name"}, }, + "only_protected_branches": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "description": { Type: schema.TypeString, @@ -242,7 +247,12 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er d.Set("repo_id", repo.GetID()) d.Set("has_projects", repo.GetHasProjects()) - branches, _, err := client.Repositories.ListBranches(context.TODO(), owner, repoName, nil) + onlyProtectedBranches := d.Get("only_protected_branches").(bool) + listBranchOptions := &github.BranchListOptions{ + Protected: &onlyProtectedBranches, + } + + branches, _, err := client.Repositories.ListBranches(context.TODO(), owner, repoName, listBranchOptions) if err != nil { return err } diff --git a/website/docs/d/repository.html.markdown b/website/docs/d/repository.html.markdown index 59f934bffc..16c2360932 100644 --- a/website/docs/d/repository.html.markdown +++ b/website/docs/d/repository.html.markdown @@ -25,6 +25,8 @@ The following arguments are supported: * `full_name` - (Optional) Full name of the repository (in `org/name` format). +* `only_protected_branches` - (Optional). If true, the `branches` attributes will be populated only with protected branches. Default: `false`. + ## Attributes Reference * `node_id` - the Node ID of the repository.