1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 )
23
24
25
26
27
28 type ProjectTemplatesService struct {
29 client *Client
30 }
31
32
33
34
35 type ProjectTemplate struct {
36 Key string `json:"key"`
37 Name string `json:"name"`
38 Nickname string `json:"nickname"`
39 Popular bool `json:"popular"`
40 HTMLURL string `json:"html_url"`
41 SourceURL string `json:"source_url"`
42 Description string `json:"description"`
43 Conditions []string `json:"conditions"`
44 Permissions []string `json:"permissions"`
45 Limitations []string `json:"limitations"`
46 Content string `json:"content"`
47 }
48
49 func (s ProjectTemplate) String() string {
50 return Stringify(s)
51 }
52
53
54
55
56
57 type ListProjectTemplatesOptions struct {
58 ListOptions
59 ID *int `url:"id,omitempty" json:"id,omitempty"`
60 Type *string `url:"type,omitempty" json:"type,omitempty"`
61 }
62
63
64
65
66 func (s *ProjectTemplatesService) ListTemplates(pid interface{}, templateType string, opt *ListProjectTemplatesOptions, options ...RequestOptionFunc) ([]*ProjectTemplate, *Response, error) {
67 project, err := parseID(pid)
68 if err != nil {
69 return nil, nil, err
70 }
71 u := fmt.Sprintf("projects/%s/templates/%s", PathEscape(project), templateType)
72
73 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
74 if err != nil {
75 return nil, nil, err
76 }
77
78 var pt []*ProjectTemplate
79 resp, err := s.client.Do(req, &pt)
80 if err != nil {
81 return nil, resp, err
82 }
83
84 return pt, resp, nil
85 }
86
87
88
89
90
91 func (s *ProjectTemplatesService) GetProjectTemplate(pid interface{}, templateType string, templateName string, options ...RequestOptionFunc) (*ProjectTemplate, *Response, error) {
92 project, err := parseID(pid)
93 if err != nil {
94 return nil, nil, err
95 }
96 u := fmt.Sprintf("projects/%s/templates/%s/%s", PathEscape(project), templateType, templateName)
97
98 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
99 if err != nil {
100 return nil, nil, err
101 }
102
103 ptd := new(ProjectTemplate)
104 resp, err := s.client.Do(req, ptd)
105 if err != nil {
106 return nil, resp, err
107 }
108
109 return ptd, resp, nil
110 }
111
View as plain text