github.com/google/go-github/v70@v70.0.0/github/licenses.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 ) 12 13 // LicensesService handles communication with the license related 14 // methods of the GitHub API. 15 // 16 // GitHub API docs: https://docs.github.com/rest/licenses/ 17 type LicensesService service 18 19 // RepositoryLicense represents the license for a repository. 20 type RepositoryLicense struct { 21 Name *string `json:"name,omitempty"` 22 Path *string `json:"path,omitempty"` 23 24 SHA *string `json:"sha,omitempty"` 25 Size *int `json:"size,omitempty"` 26 URL *string `json:"url,omitempty"` 27 HTMLURL *string `json:"html_url,omitempty"` 28 GitURL *string `json:"git_url,omitempty"` 29 DownloadURL *string `json:"download_url,omitempty"` 30 Type *string `json:"type,omitempty"` 31 Content *string `json:"content,omitempty"` 32 Encoding *string `json:"encoding,omitempty"` 33 License *License `json:"license,omitempty"` 34 } 35 36 func (l RepositoryLicense) String() string { 37 return Stringify(l) 38 } 39 40 // License represents an open source license. 41 type License struct { 42 Key *string `json:"key,omitempty"` 43 Name *string `json:"name,omitempty"` 44 URL *string `json:"url,omitempty"` 45 46 SPDXID *string `json:"spdx_id,omitempty"` 47 HTMLURL *string `json:"html_url,omitempty"` 48 Featured *bool `json:"featured,omitempty"` 49 Description *string `json:"description,omitempty"` 50 Implementation *string `json:"implementation,omitempty"` 51 Permissions *[]string `json:"permissions,omitempty"` 52 Conditions *[]string `json:"conditions,omitempty"` 53 Limitations *[]string `json:"limitations,omitempty"` 54 Body *string `json:"body,omitempty"` 55 } 56 57 func (l License) String() string { 58 return Stringify(l) 59 } 60 61 // List popular open source licenses. 62 // 63 // GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-all-commonly-used-licenses 64 // 65 //meta:operation GET /licenses 66 func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) { 67 req, err := s.client.NewRequest("GET", "licenses", nil) 68 if err != nil { 69 return nil, nil, err 70 } 71 72 var licenses []*License 73 resp, err := s.client.Do(ctx, req, &licenses) 74 if err != nil { 75 return nil, resp, err 76 } 77 78 return licenses, resp, nil 79 } 80 81 // Get extended metadata for one license. 82 // 83 // GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-a-license 84 // 85 //meta:operation GET /licenses/{license} 86 func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) { 87 u := fmt.Sprintf("licenses/%s", licenseName) 88 89 req, err := s.client.NewRequest("GET", u, nil) 90 if err != nil { 91 return nil, nil, err 92 } 93 94 license := new(License) 95 resp, err := s.client.Do(ctx, req, license) 96 if err != nil { 97 return nil, resp, err 98 } 99 100 return license, resp, nil 101 }