Skip to content

Commit e9bb788

Browse files
ksatirlikfcampbell
andauthored
make github_ref respect owner (#1651)
* make `github_ref` respect `owner` (instead of deriving it from the token) * `id` is also exported and should be mentioned * If no owner specified, use owner of token --------- Co-authored-by: Keegan Campbell <[email protected]>
1 parent 89aa2c5 commit e9bb788

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This project is used to read and write to/from GitHub (repositories, teams, file
1414

1515
## Usage
1616

17-
Detailed documentation for the GitHub provider can be found [here](https://www.terraform.io/docs/providers/github/index.html).
17+
Detailed documentation for the GitHub provider can be found [here](https://registry.terraform.io/providers/integrations/github).
1818

1919
## Contributing
2020

github/data_source_github_ref.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func dataSourceGithubRef() *schema.Resource {
2424
Required: true,
2525
ForceNew: true,
2626
},
27+
"owner": {
28+
Type: schema.TypeString,
29+
Optional: true,
30+
},
2731
"etag": {
2832
Type: schema.TypeString,
2933
Computed: true,
@@ -38,15 +42,18 @@ func dataSourceGithubRef() *schema.Resource {
3842

3943
func dataSourceGithubRefRead(d *schema.ResourceData, meta interface{}) error {
4044
client := meta.(*Owner).v3client
41-
orgName := meta.(*Owner).name
45+
owner, ok := d.Get("owner").(string)
46+
if !ok {
47+
owner = meta.(*Owner).name
48+
}
4249
repoName := d.Get("repository").(string)
4350
ref := d.Get("ref").(string)
4451

45-
refData, resp, err := client.Git.GetRef(context.TODO(), orgName, repoName, ref)
52+
refData, resp, err := client.Git.GetRef(context.TODO(), owner, repoName, ref)
4653
if err != nil {
4754
if err, ok := err.(*github.ErrorResponse); ok {
4855
if err.Response.StatusCode == http.StatusNotFound {
49-
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", orgName, repoName, ref)
56+
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref)
5057
d.SetId("")
5158
return nil
5259
}

website/docs/d/ref.html.markdown

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ Use this data source to retrieve information about a repository ref.
1313

1414
```hcl
1515
data "github_ref" "development" {
16+
owner = "example"
1617
repository = "example"
17-
ref = "heads/development"
18+
ref = "heads/development"
1819
}
1920
```
2021

2122
## Argument Reference
2223

2324
The following arguments are supported:
2425

26+
* `owner` - (Required) Owner of the repository.
27+
2528
* `repository` - (Required) The GitHub repository name.
2629

2730
* `ref` - (Required) The repository ref to look up. Must be formatted `heads/<ref>` for branches, and `tags/<ref>` for tags.
@@ -32,4 +35,6 @@ The following additional attributes are exported:
3235

3336
* `etag` - An etag representing the ref.
3437

38+
* `id` - A string storing a reference to the repository name and ref.
39+
3540
* `sha` - A string storing the reference's `HEAD` commit's SHA1.

0 commit comments

Comments
 (0)