Browse Source

licenses: add support for repository license via RepositoriesService.Get

Parker Moore 11 years ago
parent
commit
43c0b5facf
2 changed files with 10 additions and 2 deletions
  1. +7
    -0
      github/repos.go
  2. +3
    -2
      github/repos_test.go

+ 7
- 0
github/repos.go View File

@ -49,6 +49,9 @@ type Repository struct {
Organization *Organization `json:"organization,omitempty"`
Permissions *map[string]bool `json:"permissions,omitempty"`
// Only provided when using RepositoriesService.Get while in preview
License *License `json:"license,omitempty"`
// Additional mutable fields when creating and editing a repository
Private *bool `json:"private"`
HasIssues *bool `json:"has_issues"`
@ -255,6 +258,10 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
return nil, nil, err
}
// TODO: remove custom Accept header when the license support fully launches
// https://developer.github.com/v3/licenses/#get-a-repositorys-license
req.Header.Set("Accept", mediaTypeLicensesPreview)
repository := new(Repository)
resp, err := s.client.Do(req, repository)
if err != nil {


+ 3
- 2
github/repos_test.go View File

@ -191,7 +191,8 @@ func TestRepositoriesService_Get(t *testing.T) {
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`)
testHeader(t, r, "Accept", mediaTypeLicensesPreview)
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
})
repo, _, err := client.Repositories.Get("o", "r")
@ -199,7 +200,7 @@ func TestRepositoriesService_Get(t *testing.T) {
t.Errorf("Repositories.Get returned error: %v", err)
}
want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}}
want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repositories.Get returned %+v, want %+v", repo, want)
}


Loading…
Cancel
Save