1package gitlab
2
3import (
4 "fmt"
5)
6
7// LicenseTemplate represents a license template.
8//
9// GitLab API docs:
10// https://docs.gitlab.com/ce/api/templates/licenses.html
11type LicenseTemplate struct {
12 Key string `json:"key"`
13 Name string `json:"name"`
14 Nickname string `json:"nickname"`
15 Featured bool `json:"featured"`
16 HTMLURL string `json:"html_url"`
17 SourceURL string `json:"source_url"`
18 Description string `json:"description"`
19 Conditions []string `json:"conditions"`
20 Permissions []string `json:"permissions"`
21 Limitations []string `json:"limitations"`
22 Content string `json:"content"`
23}
24
25// LicenseTemplatesService handles communication with the license templates
26// related methods of the GitLab API.
27//
28// GitLab API docs: https://docs.gitlab.com/ce/api/templates/licenses.html
29type LicenseTemplatesService struct {
30 client *Client
31}
32
33// ListLicenseTemplatesOptions represents the available
34// ListLicenseTemplates() options.
35//
36// GitLab API docs:
37// https://docs.gitlab.com/ce/api/templates/licenses.html#list-license-templates
38type ListLicenseTemplatesOptions struct {
39 ListOptions
40 Popular *bool `url:"popular,omitempty" json:"popular,omitempty"`
41}
42
43// ListLicenseTemplates get all license templates.
44//
45// GitLab API docs:
46// https://docs.gitlab.com/ce/api/templates/licenses.html#list-license-templates
47func (s *LicenseTemplatesService) ListLicenseTemplates(opt *ListLicenseTemplatesOptions, options ...OptionFunc) ([]*LicenseTemplate, *Response, error) {
48 req, err := s.client.NewRequest("GET", "templates/licenses", opt, options)
49 if err != nil {
50 return nil, nil, err
51 }
52
53 var lts []*LicenseTemplate
54 resp, err := s.client.Do(req, <s)
55 if err != nil {
56 return nil, resp, err
57 }
58
59 return lts, resp, err
60}
61
62// GetLicenseTemplateOptions represents the available
63// GetLicenseTemplate() options.
64//
65// GitLab API docs:
66// https://docs.gitlab.com/ce/api/templates/licenses.html#single-license-template
67type GetLicenseTemplateOptions struct {
68 Project *string `url:"project,omitempty" json:"project,omitempty"`
69 Fullname *string `url:"fullname,omitempty" json:"fullname,omitempty"`
70}
71
72// GetLicenseTemplate get a single license template. You can pass parameters
73// to replace the license placeholder.
74//
75// GitLab API docs:
76// https://docs.gitlab.com/ce/api/templates/licenses.html#single-license-template
77func (s *LicenseTemplatesService) GetLicenseTemplate(template string, opt *GetLicenseTemplateOptions, options ...OptionFunc) (*LicenseTemplate, *Response, error) {
78 u := fmt.Sprintf("templates/licenses/%s", template)
79
80 req, err := s.client.NewRequest("GET", u, opt, options)
81 if err != nil {
82 return nil, nil, err
83 }
84
85 lt := new(LicenseTemplate)
86 resp, err := s.client.Do(req, lt)
87 if err != nil {
88 return nil, resp, err
89 }
90
91 return lt, resp, err
92}