本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.8KB

  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. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // LicensesService handles communication with the license related
  11. // methods of the GitHub API.
  12. //
  13. // GitHub API docs: https://developer.github.com/v3/licenses/
  14. type LicensesService service
  15. // RepositoryLicense represents the license for a repository.
  16. type RepositoryLicense struct {
  17. Name *string `json:"name,omitempty"`
  18. Path *string `json:"path,omitempty"`
  19. SHA *string `json:"sha,omitempty"`
  20. Size *int `json:"size,omitempty"`
  21. URL *string `json:"url,omitempty"`
  22. HTMLURL *string `json:"html_url,omitempty"`
  23. GitURL *string `json:"git_url,omitempty"`
  24. DownloadURL *string `json:"download_url,omitempty"`
  25. Type *string `json:"type,omitempty"`
  26. Content *string `json:"content,omitempty"`
  27. Encoding *string `json:"encoding,omitempty"`
  28. License *License `json:"license,omitempty"`
  29. }
  30. func (l RepositoryLicense) String() string {
  31. return Stringify(l)
  32. }
  33. // License represents an open source license.
  34. type License struct {
  35. Key *string `json:"key,omitempty"`
  36. Name *string `json:"name,omitempty"`
  37. URL *string `json:"url,omitempty"`
  38. SPDXID *string `json:"spdx_id,omitempty"`
  39. HTMLURL *string `json:"html_url,omitempty"`
  40. Featured *bool `json:"featured,omitempty"`
  41. Description *string `json:"description,omitempty"`
  42. Implementation *string `json:"implementation,omitempty"`
  43. Permissions *[]string `json:"permissions,omitempty"`
  44. Conditions *[]string `json:"conditions,omitempty"`
  45. Limitations *[]string `json:"limitations,omitempty"`
  46. Body *string `json:"body,omitempty"`
  47. }
  48. func (l License) String() string {
  49. return Stringify(l)
  50. }
  51. // List popular open source licenses.
  52. //
  53. // GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses
  54. func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
  55. req, err := s.client.NewRequest("GET", "licenses", nil)
  56. if err != nil {
  57. return nil, nil, err
  58. }
  59. var licenses []*License
  60. resp, err := s.client.Do(ctx, req, &licenses)
  61. if err != nil {
  62. return nil, resp, err
  63. }
  64. return licenses, resp, nil
  65. }
  66. // Get extended metadata for one license.
  67. //
  68. // GitHub API docs: https://developer.github.com/v3/licenses/#get-an-individual-license
  69. func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) {
  70. u := fmt.Sprintf("licenses/%s", licenseName)
  71. req, err := s.client.NewRequest("GET", u, nil)
  72. if err != nil {
  73. return nil, nil, err
  74. }
  75. license := new(License)
  76. resp, err := s.client.Do(ctx, req, license)
  77. if err != nil {
  78. return nil, resp, err
  79. }
  80. return license, resp, nil
  81. }
上海开阖软件有限公司 沪ICP备12045867号-1