summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/google/go-github/v24/github/licenses.go
blob: 1176d3a8bf7bc913f6c6cb843c1cddc8b9363308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	"context"
	"fmt"
)

// LicensesService handles communication with the license related
// methods of the GitHub API.
//
// 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"`
	Implementation *string   `json:"implementation,omitempty"`
	Permissions    *[]string `json:"permissions,omitempty"`
	Conditions     *[]string `json:"conditions,omitempty"`
	Limitations    *[]string `json:"limitations,omitempty"`
	Body           *string   `json:"body,omitempty"`
}

func (l License) String() string {
	return Stringify(l)
}

// List popular open source licenses.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses
func (s *LicensesService) List(ctx context.Context) ([]*License, *Response, error) {
	req, err := s.client.NewRequest("GET", "licenses", nil)
	if err != nil {
		return nil, nil, err
	}

	var licenses []*License
	resp, err := s.client.Do(ctx, req, &licenses)
	if err != nil {
		return nil, resp, err
	}

	return licenses, resp, nil
}

// Get extended metadata for one license.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#get-an-individual-license
func (s *LicensesService) Get(ctx context.Context, licenseName string) (*License, *Response, error) {
	u := fmt.Sprintf("licenses/%s", licenseName)

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	license := new(License)
	resp, err := s.client.Do(ctx, req, license)
	if err != nil {
		return nil, resp, err
	}

	return license, resp, nil
}