diff --git a/github/gists.go b/github/gists.go index 48a0eec..739279b 100644 --- a/github/gists.go +++ b/github/gists.go @@ -23,7 +23,7 @@ type Gist struct { ID *string `json:"id,omitempty"` Description *string `json:"description,omitempty"` Public *bool `json:"public,omitempty"` - User *User `json:"user,omitempty"` + Owner *User `json:"owner,omitempty"` Files map[GistFilename]GistFile `json:"files,omitempty"` Comments *int `json:"comments,omitempty"` HTMLURL *string `json:"html_url,omitempty"` diff --git a/github/orgs.go b/github/orgs.go index f42f61d..7596873 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -22,9 +22,10 @@ type OrganizationsService struct { type Organization 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"` 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"` @@ -40,7 +41,15 @@ type Organization struct { DiskUsage *int `json:"disk_usage,omitempty"` Collaborators *int `json:"collaborators,omitempty"` BillingEmail *string `json:"billing_email,omitempty"` + Type *string `json:"type,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 { diff --git a/github/repos.go b/github/repos.go index 4a937ba..8d122a8 100644 --- a/github/repos.go +++ b/github/repos.go @@ -17,34 +17,80 @@ type RepositoriesService struct { // Repository represents a GitHub repository. 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 - 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 { diff --git a/github/users.go b/github/users.go index 8ebfeea..9163418 100644 --- a/github/users.go +++ b/github/users.go @@ -5,11 +5,7 @@ package github -import ( - "fmt" - - "time" -) +import "fmt" // UsersService handles communication with the user related // methods of the GitHub API. @@ -21,22 +17,44 @@ type UsersService struct { // User represents a GitHub user. 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 { diff --git a/github/users_test.go b/github/users_test.go index f7ff2af..15ea3e8 100644 --- a/github/users_test.go +++ b/github/users_test.go @@ -31,12 +31,11 @@ func TestUser_marshall(t *testing.T) { PublicRepos: Int(1), Followers: Int(1), Following: Int(1), - CreatedAt: &referenceTime, + CreatedAt: &Timestamp{referenceTime}, } want := `{ "login": "l", "id": 1, - "url": "u", "avatar_url": "a", "gravatar_id": "g", "name": "n", @@ -48,7 +47,8 @@ func TestUser_marshall(t *testing.T) { "public_repos": 1, "followers": 1, "following": 1, - "created_at": ` + referenceTimeStr + ` + "created_at": ` + referenceTimeStr + `, + "url": "u" }` testJSONMarshal(t, u, want) } diff --git a/tests/fields/fields.go b/tests/fields/fields.go index cd9a112..5905690 100644 --- a/tests/fields/fields.go +++ b/tests/fields/fields.go @@ -59,9 +59,11 @@ func main() { }{ //{"rate_limit", &github.RateLimits{}}, {"users/octocat", &github.User{}}, + {"user", &github.User{}}, {"users/willnorris/keys", &[]github.Key{}}, - {"orgs/google", &github.Organization{}}, + {"orgs/google-test", &github.Organization{}}, {"repos/google/go-github", &github.Repository{}}, + {"/gists/9257657", &github.Gist{}}, } { err := testType(tt.url, tt.typ) if err != nil { @@ -72,11 +74,6 @@ func main() { // testType fetches the JSON resource at urlStr and compares its keys to the // 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 { slice := reflect.Indirect(reflect.ValueOf(typ)).Kind() == reflect.Slice