Browse Source

add missing fields for various types

Includes additions to User, Organization, Repository, and Gist.  Some
minor changes to existing fields based on changes in the v3 API (for
example, Gist.User became Gist.Owner).  Most everything else is new
additions.

refs #103
Will Norris 12 years ago
parent
commit
80ed3576c9
6 changed files with 128 additions and 58 deletions
  1. +1
    -1
      github/gists.go
  2. +10
    -1
      github/orgs.go
  3. +72
    -26
      github/repos.go
  4. +39
    -21
      github/users.go
  5. +3
    -3
      github/users_test.go
  6. +3
    -6
      tests/fields/fields.go

+ 1
- 1
github/gists.go View File

@ -23,7 +23,7 @@ type Gist struct {
ID *string `json:"id,omitempty"` ID *string `json:"id,omitempty"`
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
Public *bool `json:"public,omitempty"` Public *bool `json:"public,omitempty"`
User *User `json:"user,omitempty"`
Owner *User `json:"owner,omitempty"`
Files map[GistFilename]GistFile `json:"files,omitempty"` Files map[GistFilename]GistFile `json:"files,omitempty"`
Comments *int `json:"comments,omitempty"` Comments *int `json:"comments,omitempty"`
HTMLURL *string `json:"html_url,omitempty"` HTMLURL *string `json:"html_url,omitempty"`


+ 10
- 1
github/orgs.go View File

@ -22,9 +22,10 @@ type OrganizationsService struct {
type Organization struct { type Organization struct {
Login *string `json:"login,omitempty"` Login *string `json:"login,omitempty"`
ID *int `json:"id,omitempty"` ID *int `json:"id,omitempty"`
URL *string `json:"url,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"` AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
Company *string `json:"company,omitempty"`
Blog *string `json:"blog,omitempty"` Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"` Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"` Email *string `json:"email,omitempty"`
@ -40,7 +41,15 @@ type Organization struct {
DiskUsage *int `json:"disk_usage,omitempty"` DiskUsage *int `json:"disk_usage,omitempty"`
Collaborators *int `json:"collaborators,omitempty"` Collaborators *int `json:"collaborators,omitempty"`
BillingEmail *string `json:"billing_email,omitempty"` BillingEmail *string `json:"billing_email,omitempty"`
Type *string `json:"type,omitempty"`
Plan *Plan `json:"plan,omitempty"` Plan *Plan `json:"plan,omitempty"`
// API URLs
URL *string `json:"url,omitempty"`
EventsURL *string `json:"events_url,omitempty"`
MembersURL *string `json:"members_url,omitempty"`
PublicMembersURL *string `json:"public_members_url,omitempty"`
ReposURL *string `json:"repos_url,omitempty"`
} }
func (o Organization) String() string { func (o Organization) String() string {


+ 72
- 26
github/repos.go View File

@ -17,34 +17,80 @@ type RepositoriesService struct {
// Repository represents a GitHub repository. // Repository represents a GitHub repository.
type Repository struct { type Repository struct {
ID *int `json:"id,omitempty"`
Owner *User `json:"owner,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Homepage *string `json:"homepage,omitempty"`
DefaultBranch *string `json:"default_branch,omitempty"`
MasterBranch *string `json:"master_branch,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
CloneURL *string `json:"clone_url,omitempty"`
GitURL *string `json:"git_url,omitempty"`
MirrorURL *string `json:"mirror_url,omitempty"`
SSHURL *string `json:"ssh_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"`
Language *string `json:"language,omitempty"`
Fork *bool `json:"fork"`
ForksCount *int `json:"forks_count,omitempty"`
WatchersCount *int `json:"watchers_count,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
Size *int `json:"size,omitempty"`
ID *int `json:"id,omitempty"`
Owner *User `json:"owner,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
Description *string `json:"description,omitempty"`
Homepage *string `json:"homepage,omitempty"`
DefaultBranch *string `json:"default_branch,omitempty"`
MasterBranch *string `json:"master_branch,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
CloneURL *string `json:"clone_url,omitempty"`
GitURL *string `json:"git_url,omitempty"`
MirrorURL *string `json:"mirror_url,omitempty"`
SSHURL *string `json:"ssh_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"`
Language *string `json:"language,omitempty"`
Fork *bool `json:"fork"`
ForksCount *int `json:"forks_count,omitempty"`
NetworkCount *int `json:"network_count,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
StargazersCount *int `json:"stargazers_count,omitempty"`
SubscribersCount *int `json:"subscribers_count,omitempty"`
WatchersCount *int `json:"watchers_count,omitempty"`
Size *int `json:"size,omitempty"`
Parent *Repository `json:"parent,omitempty"`
Source *Repository `json:"source,omitempty"`
Organization *Organization `json:"organization,omitempty"`
Permissions *map[string]bool `json:"permissions,omitempty"`
// Additional mutable fields when creating and editing a repository // Additional mutable fields when creating and editing a repository
Private *bool `json:"private"`
HasIssues *bool `json:"has_issues"`
HasWiki *bool `json:"has_wiki"`
Private *bool `json:"private"`
HasIssues *bool `json:"has_issues"`
HasWiki *bool `json:"has_wiki"`
HasDownloads *bool `json:"has_downloads"`
// API URLs
URL *string `json:"url,omitempty"`
ArchiveURL *string `json:"archive_url,omitempty"`
AssigneesURL *string `json:"assignees_url,omitempty"`
BlobsURL *string `json:"blobs_url,omitempty"`
BranchesURL *string `json:"branches_url,omitempty"`
CollaboratorsURL *string `json:"collaborators_url,omitempty"`
CommentsURL *string `json:"comments_url,omitempty"`
CommitsURL *string `json:"commits_url,omitempty"`
CompareURL *string `json:"compare_url,omitempty"`
ContentsURL *string `json:"contents_url,omitempty"`
ContributorsURL *string `json:"contributors_url,omitempty"`
DownloadsURL *string `json:"downloads_url,omitempty"`
EventsURL *string `json:"events_url,omitempty"`
ForksURL *string `json:"forks_url,omitempty"`
GitCommitsURL *string `json:"git_commits_url,omitempty"`
GitRefsURL *string `json:"git_refs_url,omitempty"`
GitTagsURL *string `json:"git_tags_url,omitempty"`
HooksURL *string `json:"hooks_url,omitempty"`
IssueCommentURL *string `json:"issue_comment_url,omitempty"`
IssueEventsURL *string `json:"issue_events_url,omitempty"`
IssuesURL *string `json:"issues_url,omitempty"`
KeysURL *string `json:"keys_url,omitempty"`
LabelsURL *string `json:"labels_url,omitempty"`
LanguagesURL *string `json:"languages_url,omitempty"`
MergesURL *string `json:"merges_url,omitempty"`
MilestonesURL *string `json:"milestones_url,omitempty"`
NotificationsURL *string `json:"notifications_url,omitempty"`
PullsURL *string `json:"pulls_url,omitempty"`
ReleasesURL *string `json:"releases_url,omitempty"`
StargazersURL *string `json:"stargazers_url,omitempty"`
StatusesURL *string `json:"statuses_url,omitempty"`
SubscribersURL *string `json:"subscribers_url,omitempty"`
SubscriptionURL *string `json:"subscription_url,omitempty"`
TagsURL *string `json:"tags_url,omitempty"`
TreesURL *string `json:"trees_url,omitempty"`
TeamsURL *string `json:"teams_url,omitempty"`
} }
func (r Repository) String() string { func (r Repository) String() string {


+ 39
- 21
github/users.go View File

@ -5,11 +5,7 @@
package github package github
import (
"fmt"
"time"
)
import "fmt"
// UsersService handles communication with the user related // UsersService handles communication with the user related
// methods of the GitHub API. // methods of the GitHub API.
@ -21,22 +17,44 @@ type UsersService struct {
// User represents a GitHub user. // User represents a GitHub user.
type User struct { type User struct {
Login *string `json:"login,omitempty"`
ID *int `json:"id,omitempty"`
URL *string `json:"url,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
GravatarID *string `json:"gravatar_id,omitempty"`
Name *string `json:"name,omitempty"`
Company *string `json:"company,omitempty"`
Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"`
Hireable *bool `json:"hireable,omitempty"`
PublicRepos *int `json:"public_repos,omitempty"`
Followers *int `json:"followers,omitempty"`
Following *int `json:"following,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Login *string `json:"login,omitempty"`
ID *int `json:"id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
GravatarID *string `json:"gravatar_id,omitempty"`
Name *string `json:"name,omitempty"`
Company *string `json:"company,omitempty"`
Blog *string `json:"blog,omitempty"`
Location *string `json:"location,omitempty"`
Email *string `json:"email,omitempty"`
Hireable *bool `json:"hireable,omitempty"`
Bio *string `json:"bio,omitempty"`
PublicRepos *int `json:"public_repos,omitempty"`
PublicGists *int `json:"public_gists,omitempty"`
Followers *int `json:"followers,omitempty"`
Following *int `json:"following,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Type *string `json:"type,omitempty"`
SiteAdmin *bool `json:"site_admin,omitempty"`
TotalPrivateRepos *int `json:"total_private_repos,omitempty"`
OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"`
PrivateGists *int `json:"private_gists,omitempty"`
DiskUsage *int `json:"disk_usage,omitempty"`
Collaborators *int `json:"collaborators,omitempty"`
Plan *Plan `json:"plan,omitempty"`
// API URLs
URL *string `json:"url,omitempty"`
EventsURL *string `json:"events_url,omitempty"`
FollowingURL *string `json:"following_url,omitempty"`
FollowersURL *string `json:"followers_url,omitempty"`
GistsURL *string `json:"gists_url,omitempty"`
OrganizationsURL *string `json:"organizations_url,omitempty"`
ReceivedEventsURL *string `json:"received_events_url,omitempty"`
ReposURL *string `json:"repos_url,omitempty"`
StarredURL *string `json:"starred_url,omitempty"`
SubscriptionsURL *string `json:"subscriptions_url,omitempty"`
} }
func (u User) String() string { func (u User) String() string {


+ 3
- 3
github/users_test.go View File

@ -31,12 +31,11 @@ func TestUser_marshall(t *testing.T) {
PublicRepos: Int(1), PublicRepos: Int(1),
Followers: Int(1), Followers: Int(1),
Following: Int(1), Following: Int(1),
CreatedAt: &referenceTime,
CreatedAt: &Timestamp{referenceTime},
} }
want := `{ want := `{
"login": "l", "login": "l",
"id": 1, "id": 1,
"url": "u",
"avatar_url": "a", "avatar_url": "a",
"gravatar_id": "g", "gravatar_id": "g",
"name": "n", "name": "n",
@ -48,7 +47,8 @@ func TestUser_marshall(t *testing.T) {
"public_repos": 1, "public_repos": 1,
"followers": 1, "followers": 1,
"following": 1, "following": 1,
"created_at": ` + referenceTimeStr + `
"created_at": ` + referenceTimeStr + `,
"url": "u"
}` }`
testJSONMarshal(t, u, want) testJSONMarshal(t, u, want)
} }


+ 3
- 6
tests/fields/fields.go View File

@ -59,9 +59,11 @@ func main() {
}{ }{
//{"rate_limit", &github.RateLimits{}}, //{"rate_limit", &github.RateLimits{}},
{"users/octocat", &github.User{}}, {"users/octocat", &github.User{}},
{"user", &github.User{}},
{"users/willnorris/keys", &[]github.Key{}}, {"users/willnorris/keys", &[]github.Key{}},
{"orgs/google", &github.Organization{}},
{"orgs/google-test", &github.Organization{}},
{"repos/google/go-github", &github.Repository{}}, {"repos/google/go-github", &github.Repository{}},
{"/gists/9257657", &github.Gist{}},
} { } {
err := testType(tt.url, tt.typ) err := testType(tt.url, tt.typ)
if err != nil { if err != nil {
@ -72,11 +74,6 @@ func main() {
// testType fetches the JSON resource at urlStr and compares its keys to the // testType fetches the JSON resource at urlStr and compares its keys to the
// struct fields of typ. // struct fields of typ.
//
// TODO: handle resources that are more easily fetched as an array of objects,
// rather than a single object (e.g. a user's public keys). In this case, we
// should just take the first object in the array, and use that. In that case,
// should typ also be specified as a slice?
func testType(urlStr string, typ interface{}) error { func testType(urlStr string, typ interface{}) error {
slice := reflect.Indirect(reflect.ValueOf(typ)).Kind() == reflect.Slice slice := reflect.Indirect(reflect.ValueOf(typ)).Kind() == reflect.Slice


Loading…
Cancel
Save