From 6c5af5ebd45c5d83a08e2bafb2e3e6b1c8d2c18d Mon Sep 17 00:00:00 2001 From: Jan Sebastian Siwy Date: Wed, 18 Mar 2020 13:19:47 +0100 Subject: [PATCH] Add support to retrieve information about the currently authenticated user Copy https://github.com/terraform-providers/terraform-provider-github/pull/261 as the original repository behind this PR has been deleted --- github/data_source_github_user.go | 4 ++-- website/docs/d/user.html.markdown | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/github/data_source_github_user.go b/github/data_source_github_user.go index c22c96e1ef..2f5cbcfde3 100644 --- a/github/data_source_github_user.go +++ b/github/data_source_github_user.go @@ -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 } diff --git a/website/docs/d/user.html.markdown b/website/docs/d/user.html.markdown index b3c051b0ae..467765f945 100644 --- a/website/docs/d/user.html.markdown +++ b/website/docs/d/user.html.markdown @@ -1,6 +1,7 @@ --- layout: "github" page_title: "GitHub: github_user" +sidebar_current: "docs-github-datasource-user" description: |- Get information on a GitHub user. --- @@ -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 @@ -41,4 +53,3 @@ data "github_user" "example" { * `following` - the number of following users. * `created_at` - the creation date. * `updated_at` - the update date. -