diff --git a/github/repos.go b/github/repos.go index 8d8d40f..ed9052c 100644 --- a/github/repos.go +++ b/github/repos.go @@ -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 { diff --git a/github/repos_test.go b/github/repos_test.go index def2119..c489fcf 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -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) }