Skip to content

Commit

Permalink
Merge pull request integrations#2 from mootpt/f-github-data-user-gpg
Browse files Browse the repository at this point in the history
added attributes to github_user and github_team data sources
  • Loading branch information
stack72 authored Jun 16, 2017
2 parents aff7516 + 53c1c10 commit 2dbc7ac
Show file tree
Hide file tree
Showing 44 changed files with 1,178 additions and 292 deletions.
27 changes: 22 additions & 5 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func dataSourceGithubTeam() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"members": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -44,17 +49,29 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Refreshing Gitub Team: %s", slug)

client := meta.(*Organization).client
ctx := context.Background()

team, err := getGithubTeamBySlug(client, meta.(*Organization).name, slug)
if err != nil {
return err
}

d.SetId(strconv.Itoa(*team.ID))
d.Set("name", *team.Name)
d.Set("description", *team.Description)
d.Set("privacy", *team.Privacy)
d.Set("permission", *team.Permission)
member, _, err := client.Organizations.ListTeamMembers(ctx, team.GetID(), nil)
if err != nil {
return err
}

members := []string{}
for _, v := range member {
members = append(members, v.GetLogin())
}

d.SetId(strconv.Itoa(team.GetID()))
d.Set("name", team.GetName())
d.Set("members", members)
d.Set("description", team.GetDescription())
d.Set("privacy", team.GetPrivacy())
d.Set("permission", team.GetPermission())

return nil
}
Expand Down
68 changes: 50 additions & 18 deletions github/data_source_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func dataSourceGithubUser() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"gpg_keys": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"ssh_keys": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"public_repos": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -90,29 +100,51 @@ func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Refreshing Gitub User: %s", username)

client := meta.(*Organization).client
ctx := context.Background()

user, _, err := client.Users.Get(ctx, username)
if err != nil {
return err
}

user, _, err := client.Users.Get(context.TODO(), username)
gpg, _, err := client.Users.ListGPGKeys(ctx, username, nil)
if err != nil {
return err
}
ssh, _, err := client.Users.ListKeys(ctx, username, nil)
if err != nil {
return err
}

gpgKeys := []string{}
for _, v := range gpg {
gpgKeys = append(gpgKeys, v.GetPublicKey())
}

sshKeys := []string{}
for _, v := range ssh {
sshKeys = append(sshKeys, v.GetKey())
}

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)
d.SetId(strconv.Itoa(user.GetID()))
d.Set("login", user.GetLogin())
d.Set("avatar_url", user.GetAvatarURL())
d.Set("gravatar_id", user.GetGravatarID())
d.Set("site_admin", user.GetSiteAdmin())
d.Set("company", user.GetCompany())
d.Set("blog", user.GetBlog())
d.Set("location", user.GetLocation())
d.Set("name", user.GetName())
d.Set("email", user.GetEmail())
d.Set("bio", user.GetBio())
d.Set("gpg_keys", gpgKeys)
d.Set("ssh_keys", sshKeys)
d.Set("public_repos", user.GetPublicRepos())
d.Set("public_gists", user.GetPublicGists())
d.Set("followers", user.GetFollowers())
d.Set("following", user.GetFollowing())
d.Set("created_at", user.GetCreatedAt())
d.Set("updated_at", user.GetUpdatedAt())

return nil
}
12 changes: 8 additions & 4 deletions vendor/github.com/google/go-github/github/activity_events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions vendor/github.com/google/go-github/github/authorizations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 34 additions & 6 deletions vendor/github.com/google/go-github/github/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2dbc7ac

Please sign in to comment.