Browse Source

adding ability to list organization repos

Craig Peterson 11 years ago
committed by Will Norris
parent
commit
34bb95064e
3 changed files with 14 additions and 2 deletions
  1. +3
    -0
      github/github.go
  2. +9
    -0
      github/repos.go
  3. +2
    -2
      github/repos_test.go

+ 3
- 0
github/github.go View File

@ -42,6 +42,9 @@ const (
// https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/
mediaTypeStarringPreview = "application/vnd.github.v3.star+json"
// https://developer.github.com/changes/2014-12-08-organization-permissions-api-preview/
mediaTypeOrganizationsPreview = "application/vnd.github.moondragon+json"
)
// A Client manages communication with the GitHub API.


+ 9
- 0
github/repos.go View File

@ -122,6 +122,11 @@ type RepositoryListOptions struct {
// Default is "asc" when sort is "full_name", otherwise default is "desc".
Direction string `url:"direction,omitempty"`
// Include orginization repositories the user has access to.
// This will become the default behavior in the future, but is opt-in for now.
// See https://developer.github.com/changes/2015-01-07-prepare-for-organization-permissions-changes/
IncludeOrg bool `url:"-"`
ListOptions
}
@ -146,6 +151,10 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
return nil, nil, err
}
if opt != nil && opt.IncludeOrg {
req.Header.Set("Accept", mediaTypeOrganizationsPreview)
}
repos := new([]Repository)
resp, err := s.client.Do(req, repos)
if err != nil {


+ 2
- 2
github/repos_test.go View File

@ -45,11 +45,11 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
"direction": "asc",
"page": "2",
})
testHeader(t, r, "Accept", mediaTypeOrganizationsPreview)
fmt.Fprint(w, `[{"id":1}]`)
})
opt := &RepositoryListOptions{"owner", "created", "asc", ListOptions{Page: 2}}
opt := &RepositoryListOptions{"owner", "created", "asc", true, ListOptions{Page: 2}}
repos, _, err := client.Repositories.List("u", opt)
if err != nil {
t.Errorf("Repositories.List returned error: %v", err)


Loading…
Cancel
Save