Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Add support to retrieve information about the currently authenticated…
Browse files Browse the repository at this point in the history
… user

Copy https://github.com/terraform-providers/terraform-provider-github/pull/261 as the original repository behind this PR has been deleted
  • Loading branch information
jansiwy authored and fmasuhr committed Jun 22, 2020
1 parent 0eb729b commit eef1c0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions github/data_source_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error {
return err
}

gpg, _, err := client.Users.ListGPGKeys(ctx, username, nil)
gpg, _, err := client.Users.ListGPGKeys(ctx, user.GetLogin(), nil)
if err != nil {
return err
}
ssh, _, err := client.Users.ListKeys(ctx, username, nil)
ssh, _, err := client.Users.ListKeys(ctx, user.GetLogin(), nil)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions github/resource_github_repository_vulnerability_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func resourceGithubRepositoryVulnerabilityAlertsCreate(d *schema.ResourceData, m
return err
}

client := meta.(*Organization).client
client := meta.(*Owner).v3client

orgName := meta.(*Organization).name
orgName := meta.(*Owner).name
repoName := d.Get("repository").(string)

log.Printf("[DEBUG] Creating repository vulnerability alerts: %s/%s", orgName, repoName)
Expand All @@ -53,13 +53,13 @@ func resourceGithubRepositoryVulnerabilityAlertsRead(d *schema.ResourceData, met
return err
}

client := meta.(*Organization).client
client := meta.(*Owner).v3client

repoName := d.Id()
if err != nil {
return err
}
orgName := meta.(*Organization).name
orgName := meta.(*Owner).name

log.Printf("[DEBUG] Reading repository vulnerability alerts: %s/%s", orgName, repoName)
ctx := context.WithValue(context.Background(), ctxId, d.Id())
Expand All @@ -80,13 +80,13 @@ func resourceGithubRepositoryVulnerabilityAlertsDelete(d *schema.ResourceData, m
return err
}

client := meta.(*Organization).client
client := meta.(*Owner).v3client
repoName := d.Id()
if err != nil {
return err
}

orgName := meta.(*Organization).name
orgName := meta.(*Owner).name
ctx := context.WithValue(context.Background(), ctxId, d.Id())
log.Printf("[DEBUG] Deleting repository vulnerability alerts%s/%s", orgName, repoName)
_, err = client.Repositories.DisableVulnerabilityAlerts(ctx, orgName, repoName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func testAccCheckGithubRepositoryVulnerabilityAlertsExists(n, id string) resourc
return fmt.Errorf("Expected ID to be %v, got %v", id, rs.Primary.ID)
}

conn := testAccProvider.Meta().(*Organization).client
o := testAccProvider.Meta().(*Organization).name
conn := testAccProvider.Meta().(*Owner).v3client
o := testAccProvider.Meta().(*Owner).name

enabled, _, err := conn.Repositories.GetVulnerabilityAlerts(context.TODO(), o, id)
if err != nil {
Expand All @@ -59,14 +59,14 @@ func testAccCheckGithubRepositoryVulnerabilityAlertsExists(n, id string) resourc
}

func testAccGithubRepositoryVulnerabilityAlertsDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*Organization).client
conn := testAccProvider.Meta().(*Owner).v3client

for _, rs := range s.RootModule().Resources {
if rs.Type != "github_repository_vulnerability_alerts" {
continue
}

o := testAccProvider.Meta().(*Organization).name
o := testAccProvider.Meta().(*Owner).name
enabled, _, err := conn.Repositories.GetVulnerabilityAlerts(context.TODO(), o, rs.Primary.ID)

if err == nil {
Expand Down
15 changes: 13 additions & 2 deletions website/docs/d/user.html.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: "github"
page_title: "GitHub: github_user"
sidebar_current: "docs-github-datasource-user"
description: |-
Get information on a GitHub user.
---
Expand All @@ -12,14 +13,25 @@ Use this data source to retrieve information about a GitHub user.
## Example Usage

```hcl
# Retrieve information about a GitHub user.
data "github_user" "example" {
username = "example"
}
# Retrieve information about the currently authenticated user.
data "github_user" "current" {
username = ""
}
output "current_github_login" {
value = "${data.github_user.current.login}"
}
```

## Argument Reference

* `username` - (Required) The username.
* `username` - (Required) The username. Use an empty string `""` to retrieve information about the currently authenticated user.

## Attributes Reference

Expand All @@ -41,4 +53,3 @@ data "github_user" "example" {
* `following` - the number of following users.
* `created_at` - the creation date.
* `updated_at` - the update date.

0 comments on commit eef1c0c

Please sign in to comment.