-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
GitHub user #14570
Merged
+228
−0
Merged
GitHub user #14570
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceGithubUser() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceGithubUserRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"username": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"login": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"avatar_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"gravatar_id": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"site_admin": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"company": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"blog": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"location": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"email": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bio": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"public_repos": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"public_gists": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"followers": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"following": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"created_at": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"updated_at": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[INFO] Refreshing Gitub User: %s", d.Id()) | ||
|
||
username := d.Get("username").(string) | ||
client := meta.(*Organization).client | ||
|
||
user, _, err := client.Users.Get(context.TODO(), username) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(strconv.Itoa(*user.ID)) | ||
d.Set("login", *user.Login) | ||
d.Set("avatar_url", *user.AvatarURL) | ||
d.Set("gravatar_id", *user.GravatarID) | ||
d.Set("site_admin", *user.SiteAdmin) | ||
d.Set("company", *user.Company) | ||
d.Set("blog", *user.Blog) | ||
d.Set("location", *user.Location) | ||
d.Set("name", *user.Name) | ||
d.Set("email", *user.Email) | ||
d.Set("bio", *user.Bio) | ||
d.Set("public_repos", *user.PublicRepos) | ||
d.Set("public_gists", *user.PublicGists) | ||
d.Set("followers", *user.Followers) | ||
d.Set("following", *user.Following) | ||
d.Set("created_at", *user.CreatedAt) | ||
d.Set("updated_at", *user.UpdatedAt) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
layout: "github" | ||
page_title: "Github: github_user" | ||
sidebar_current: "docs-github-datasource-user" | ||
description: |- | ||
Get information on a Github user. | ||
--- | ||
|
||
# github\_user | ||
|
||
Use this data source to retrieve information about a Github user. | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "github_user" "example" { | ||
username = "example" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `username` - (Required) The username. | ||
|
||
## Attributes Reference | ||
|
||
* `login` - the user's login. | ||
* `avatar_url` - the user's avatar URL. | ||
* `gravatar_id` - the user's gravatar ID. | ||
* `site_admin` - whether the user is a Github admin. | ||
* `name` - the user's full name. | ||
* `company` - the user's company name. | ||
* `blog` - the user's blog location. | ||
* `location` - the user's location. | ||
* `email` - the user's email. | ||
* `bio` - the user's bio. | ||
* `public_repos` - the number of public repositories. | ||
* `public_gists` - the number of public gists. | ||
* `followers` - the number of followers. | ||
* `following` - the number of following users. | ||
* `created_at` - the creation date. | ||
* `updated_at` - the update date. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On an initial run the
id
isnil
, could change the log statement to print theusername
as it's a required parameterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I can use that indeed.