From 0ba7beb3654be8cd63b3147430da4e8172ec0060 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 11b3104cb9..cb312207e4 100644 --- a/github/data_source_github_user.go +++ b/github/data_source_github_user.go @@ -107,11 +107,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 78be637e6d..8e77c5ca3f 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. -