From 59cf7e6efbc82cd8d8413fcb7fb96487ea65168c Mon Sep 17 00:00:00 2001 From: Nick Miyake Date: Sat, 12 Nov 2016 13:28:16 -0800 Subject: [PATCH] Update License struct and add new RepositoryLicense struct Update structs to reflect the new reponses returned from GitHub. Fixes #471 --- github/licenses.go | 31 ++++++++++++++++++++++++++----- github/licenses_test.go | 10 ++++++---- github/repos.go | 6 +++--- github/repos_test.go | 18 ++++++++++++------ 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/github/licenses.go b/github/licenses.go index 35cd234..0b5e8b3 100644 --- a/github/licenses.go +++ b/github/licenses.go @@ -10,23 +10,44 @@ import "fmt" // LicensesService handles communication with the license related // methods of the GitHub API. // -// GitHub API docs: http://developer.github.com/v3/pulls/ +// GitHub API docs: https://developer.github.com/v3/licenses/ type LicensesService service +// RepositoryLicense represents the license for a repository. +type RepositoryLicense struct { + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + + SHA *string `json:"sha,omitempty"` + Size *int `json:"size,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + GitURL *string `json:"git_url,omitempty"` + DownloadURL *string `json:"download_url,omitempty"` + Type *string `json:"type,omitempty"` + Content *string `json:"content,omitempty"` + Encoding *string `json:"encoding,omitempty"` + License *License `json:"license,omitempty"` +} + +func (l RepositoryLicense) String() string { + return Stringify(l) +} + // License represents an open source license. type License struct { Key *string `json:"key,omitempty"` Name *string `json:"name,omitempty"` URL *string `json:"url,omitempty"` + SPDXID *string `json:"spdx_id,omitempty"` HTMLURL *string `json:"html_url,omitempty"` Featured *bool `json:"featured,omitempty"` Description *string `json:"description,omitempty"` - Category *string `json:"category,omitempty"` Implementation *string `json:"implementation,omitempty"` - Required *[]string `json:"required,omitempty"` - Permitted *[]string `json:"permitted,omitempty"` - Forbidden *[]string `json:"forbidden,omitempty"` + Permissions *[]string `json:"permissions,omitempty"` + Conditions *[]string `json:"conditions,omitempty"` + Limitations *[]string `json:"limitations,omitempty"` Body *string `json:"body,omitempty"` } diff --git a/github/licenses_test.go b/github/licenses_test.go index 2319bb4..00a621c 100644 --- a/github/licenses_test.go +++ b/github/licenses_test.go @@ -19,7 +19,7 @@ func TestLicensesService_List(t *testing.T) { mux.HandleFunc("/licenses", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", mediaTypeLicensesPreview) - fmt.Fprint(w, `[{"key":"mit","name":"MIT","url":"https://api.github.com/licenses/mit"}]`) + fmt.Fprint(w, `[{"key":"mit","name":"MIT","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}]`) }) licenses, _, err := client.Licenses.List() @@ -28,9 +28,11 @@ func TestLicensesService_List(t *testing.T) { } want := []*License{{ - Key: String("mit"), - Name: String("MIT"), - URL: String("https://api.github.com/licenses/mit"), + Key: String("mit"), + Name: String("MIT"), + SPDXID: String("MIT"), + URL: String("https://api.github.com/licenses/mit"), + Featured: Bool(true), }} if !reflect.DeepEqual(licenses, want) { t.Errorf("Licenses.List returned %+v, want %+v", licenses, want) diff --git a/github/repos.go b/github/repos.go index ffb8922..ff84673 100644 --- a/github/repos.go +++ b/github/repos.go @@ -595,18 +595,18 @@ func (s *RepositoriesService) EditBranch(owner, repo, branchName string, branch // License gets the contents of a repository's license if one is detected. // // GitHub API docs: https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license -func (s *RepositoriesService) License(owner, repo string) (*License, *Response, error) { +func (s *RepositoriesService) License(owner, repo string) (*RepositoryLicense, *Response, error) { u := fmt.Sprintf("repos/%v/%v/license", owner, repo) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err } - r := &Repository{} + r := &RepositoryLicense{} resp, err := s.client.Do(req, r) if err != nil { return nil, resp, err } - return r.License, resp, err + return r, resp, err } diff --git a/github/repos_test.go b/github/repos_test.go index a75ac6b..209227c 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -519,7 +519,7 @@ func TestRepositoriesService_License(t *testing.T) { mux.HandleFunc("/repos/o/r/license", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"license":{"key":"mit","name":"MIT License","url":"https://api.github.com/licenses/mit","featured":true}}`) + fmt.Fprint(w, `{"name": "LICENSE", "path": "LICENSE", "license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","featured":true}}`) }) got, _, err := client.Repositories.License("o", "r") @@ -527,12 +527,18 @@ func TestRepositoriesService_License(t *testing.T) { t.Errorf("Repositories.License returned error: %v", err) } - want := &License{ - Name: String("MIT License"), - Key: String("mit"), - URL: String("https://api.github.com/licenses/mit"), - Featured: Bool(true), + want := &RepositoryLicense{ + Name: String("LICENSE"), + Path: String("LICENSE"), + License: &License{ + Name: String("MIT License"), + Key: String("mit"), + SPDXID: String("MIT"), + URL: String("https://api.github.com/licenses/mit"), + Featured: Bool(true), + }, } + if !reflect.DeepEqual(got, want) { t.Errorf("Repositories.License returned %+v, want %+v", got, want) }