Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make github_ref respect owner #1651

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This project is used to read and write to/from GitHub (repositories, teams, file

## Usage

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

## Contributing

Expand Down
13 changes: 10 additions & 3 deletions github/data_source_github_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func dataSourceGithubRef() *schema.Resource {
Required: true,
ForceNew: true,
},
"owner": {
Type: schema.TypeString,
Optional: true,
},
"etag": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -38,15 +42,18 @@ func dataSourceGithubRef() *schema.Resource {

func dataSourceGithubRefRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Owner).v3client
orgName := meta.(*Owner).name
owner, ok := d.Get("owner").(string)
if !ok {
owner = meta.(*Owner).name
}
repoName := d.Get("repository").(string)
ref := d.Get("ref").(string)

refData, resp, err := client.Git.GetRef(context.TODO(), orgName, repoName, ref)
refData, resp, err := client.Git.GetRef(context.TODO(), owner, repoName, ref)
if err != nil {
if err, ok := err.(*github.ErrorResponse); ok {
if err.Response.StatusCode == http.StatusNotFound {
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", orgName, repoName, ref)
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref)
d.SetId("")
return nil
}
Expand Down
7 changes: 6 additions & 1 deletion website/docs/d/ref.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ Use this data source to retrieve information about a repository ref.

```hcl
data "github_ref" "development" {
owner = "example"
repository = "example"
ref = "heads/development"
ref = "heads/development"
}
```

## Argument Reference

The following arguments are supported:

* `owner` - (Required) Owner of the repository.

* `repository` - (Required) The GitHub repository name.

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

* `etag` - An etag representing the ref.

* `id` - A string storing a reference to the repository name and ref.

* `sha` - A string storing the reference's `HEAD` commit's SHA1.