Browse Source

Implement support for RepositoriesService ListContributors

Chris Schaefer 12 years ago
committed by Will Norris
parent
commit
140d508209
2 changed files with 76 additions and 0 deletions
  1. +54
    -0
      github/repos.go
  2. +22
    -0
      github/repos_test.go

+ 54
- 0
github/repos.go View File

@ -230,6 +230,60 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
return r, resp, err return r, resp, err
} }
// Contributor represents a repository contributor
type Contributor struct {
Login *string `json:"login,omitempty"`
ID *int `json:"id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
GravatarID *string `json:"gravatar_id,omitempty"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
FollowersURL *string `json:"followers_url,omitempty"`
FollowingURL *string `json:"following_url,omitempty"`
GistsURL *string `json:"gists_url,omitempty"`
StarredURL *string `json:"starred_url,omitempty"`
SubscriptionsURL *string `json:"subscriptions_url,omitempty"`
OrganizationsURL *string `json:"organizations_url,omitempty"`
ReposURL *string `json:"repos_url,omitempty"`
EventsURL *string `json:"events_url,omitempty"`
ReceivedEventsURL *string `json:"received_events_url,omitempty"`
Type *string `json:"type,omitempty"`
SiteAdmin *bool `json:"site_admin"`
Contributions *int `json:"contributions,omitempty"`
}
// ListContributorsOptions specifies the optional parameters to the
// RepositoriesService.ListContributors method.
type ListContributorsOptions struct {
// Include anonymous contributors in results or not
Anon string `url:"anon,omitempty"`
}
// ListContributors lists contributors for a repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/#list-contributors
func (s *RepositoriesService) ListContributors(owner string, repository string, opt *ListContributorsOptions) ([]Contributor, *Response, error) {
u := fmt.Sprintf("/repos/%v/%v/contributors", owner, repository)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
contributor := new([]Contributor)
resp, err := s.client.Do(req, contributor)
if err != nil {
return nil, nil, err
}
return *contributor, resp, err
}
// ListLanguages lists languages for the specified repository. The returned map // ListLanguages lists languages for the specified repository. The returned map
// specifies the languages and the number of bytes of code written in that // specifies the languages and the number of bytes of code written in that
// language. For example: // language. For example:


+ 22
- 0
github/repos_test.go View File

@ -244,6 +244,28 @@ func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
testURLParseError(t, err) testURLParseError(t, err)
} }
func TestRepositoriesService_ListContributors(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/contributors", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"contributions":42}]`)
})
opts := &ListContributorsOptions{Anon: "true"}
contributors, _, err := client.Repositories.ListContributors("o", "r", opts)
if err != nil {
t.Errorf("Repositories.ListContributors returned error: %v", err)
}
want := []Contributor{{Contributions: Int(42)}}
if !reflect.DeepEqual(contributors, want) {
t.Errorf("Repositories.ListContributors returned %+v, want %+v", contributors, want)
}
}
func TestRepositoriesService_ListLanguages(t *testing.T) { func TestRepositoriesService_ListLanguages(t *testing.T) {
setup() setup()
defer teardown() defer teardown()


Loading…
Cancel
Save