Browse Source

Update License struct and add new RepositoryLicense struct

Update structs to reflect the new reponses returned from GitHub.

Fixes #471
Nick Miyake 9 years ago
parent
commit
59cf7e6efb
4 changed files with 47 additions and 18 deletions
  1. +26
    -5
      github/licenses.go
  2. +6
    -4
      github/licenses_test.go
  3. +3
    -3
      github/repos.go
  4. +12
    -6
      github/repos_test.go

+ 26
- 5
github/licenses.go View File

@ -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"`
}


+ 6
- 4
github/licenses_test.go View File

@ -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)


+ 3
- 3
github/repos.go View File

@ -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
}

+ 12
- 6
github/repos_test.go View File

@ -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)
}


Loading…
Cancel
Save