1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gitlab
17
18 import (
19 "fmt"
20 "net/http"
21 "net/url"
22 )
23
24
25
26
27
28 type WikisService struct {
29 client *Client
30 }
31
32
33
34
35 type Wiki struct {
36 Content string `json:"content"`
37 Encoding string `json:"encoding"`
38 Format WikiFormatValue `json:"format"`
39 Slug string `json:"slug"`
40 Title string `json:"title"`
41 }
42
43 func (w Wiki) String() string {
44 return Stringify(w)
45 }
46
47
48
49
50
51 type ListWikisOptions struct {
52 WithContent *bool `url:"with_content,omitempty" json:"with_content,omitempty"`
53 }
54
55
56
57
58
59
60 func (s *WikisService) ListWikis(pid interface{}, opt *ListWikisOptions, options ...RequestOptionFunc) ([]*Wiki, *Response, error) {
61 project, err := parseID(pid)
62 if err != nil {
63 return nil, nil, err
64 }
65 u := fmt.Sprintf("projects/%s/wikis", PathEscape(project))
66
67 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
68 if err != nil {
69 return nil, nil, err
70 }
71
72 var ws []*Wiki
73 resp, err := s.client.Do(req, &ws)
74 if err != nil {
75 return nil, resp, err
76 }
77
78 return ws, resp, nil
79 }
80
81
82
83
84
85 type GetWikiPageOptions struct {
86 RenderHTML *bool `url:"render_html,omitempty" json:"render_html,omitempty"`
87 Version *string `url:"version,omitempty" json:"version,omitempty"`
88 }
89
90
91
92
93
94 func (s *WikisService) GetWikiPage(pid interface{}, slug string, opt *GetWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) {
95 project, err := parseID(pid)
96 if err != nil {
97 return nil, nil, err
98 }
99 u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug))
100
101 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
102 if err != nil {
103 return nil, nil, err
104 }
105
106 w := new(Wiki)
107 resp, err := s.client.Do(req, w)
108 if err != nil {
109 return nil, resp, err
110 }
111
112 return w, resp, nil
113 }
114
115
116
117
118
119 type CreateWikiPageOptions struct {
120 Content *string `url:"content,omitempty" json:"content,omitempty"`
121 Title *string `url:"title,omitempty" json:"title,omitempty"`
122 Format *WikiFormatValue `url:"format,omitempty" json:"format,omitempty"`
123 }
124
125
126
127
128
129
130 func (s *WikisService) CreateWikiPage(pid interface{}, opt *CreateWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) {
131 project, err := parseID(pid)
132 if err != nil {
133 return nil, nil, err
134 }
135 u := fmt.Sprintf("projects/%s/wikis", PathEscape(project))
136
137 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
138 if err != nil {
139 return nil, nil, err
140 }
141
142 w := new(Wiki)
143 resp, err := s.client.Do(req, w)
144 if err != nil {
145 return nil, resp, err
146 }
147
148 return w, resp, nil
149 }
150
151
152
153
154
155 type EditWikiPageOptions struct {
156 Content *string `url:"content,omitempty" json:"content,omitempty"`
157 Title *string `url:"title,omitempty" json:"title,omitempty"`
158 Format *WikiFormatValue `url:"format,omitempty" json:"format,omitempty"`
159 }
160
161
162
163
164
165
166 func (s *WikisService) EditWikiPage(pid interface{}, slug string, opt *EditWikiPageOptions, options ...RequestOptionFunc) (*Wiki, *Response, error) {
167 project, err := parseID(pid)
168 if err != nil {
169 return nil, nil, err
170 }
171 u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug))
172
173 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
174 if err != nil {
175 return nil, nil, err
176 }
177
178 w := new(Wiki)
179 resp, err := s.client.Do(req, w)
180 if err != nil {
181 return nil, resp, err
182 }
183
184 return w, resp, nil
185 }
186
187
188
189
190
191 func (s *WikisService) DeleteWikiPage(pid interface{}, slug string, options ...RequestOptionFunc) (*Response, error) {
192 project, err := parseID(pid)
193 if err != nil {
194 return nil, err
195 }
196 u := fmt.Sprintf("projects/%s/wikis/%s", PathEscape(project), url.PathEscape(slug))
197
198 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
199 if err != nil {
200 return nil, err
201 }
202
203 return s.client.Do(req, nil)
204 }
205
View as plain text