1
2
3
4
5
6 package github
7
8 import (
9 "bytes"
10 "context"
11 "fmt"
12 "net/url"
13 )
14
15
16 type MarkdownOptions struct {
17
18
19
20
21
22
23
24
25
26
27 Mode string
28
29
30
31 Context string
32 }
33
34 type markdownRequest struct {
35 Text *string `json:"text,omitempty"`
36 Mode *string `json:"mode,omitempty"`
37 Context *string `json:"context,omitempty"`
38 }
39
40
41
42
43 func (c *Client) Markdown(ctx context.Context, text string, opts *MarkdownOptions) (string, *Response, error) {
44 request := &markdownRequest{Text: String(text)}
45 if opts != nil {
46 if opts.Mode != "" {
47 request.Mode = String(opts.Mode)
48 }
49 if opts.Context != "" {
50 request.Context = String(opts.Context)
51 }
52 }
53
54 req, err := c.NewRequest("POST", "markdown", request)
55 if err != nil {
56 return "", nil, err
57 }
58
59 buf := new(bytes.Buffer)
60 resp, err := c.Do(ctx, req, buf)
61 if err != nil {
62 return "", resp, err
63 }
64
65 return buf.String(), resp, nil
66 }
67
68
69
70
71 func (c *Client) ListEmojis(ctx context.Context) (map[string]string, *Response, error) {
72 req, err := c.NewRequest("GET", "emojis", nil)
73 if err != nil {
74 return nil, nil, err
75 }
76
77 var emoji map[string]string
78 resp, err := c.Do(ctx, req, &emoji)
79 if err != nil {
80 return nil, resp, err
81 }
82
83 return emoji, resp, nil
84 }
85
86
87 type CodeOfConduct struct {
88 Name *string `json:"name,omitempty"`
89 Key *string `json:"key,omitempty"`
90 URL *string `json:"url,omitempty"`
91 Body *string `json:"body,omitempty"`
92 }
93
94 func (c *CodeOfConduct) String() string {
95 return Stringify(c)
96 }
97
98
99
100
101 func (c *Client) ListCodesOfConduct(ctx context.Context) ([]*CodeOfConduct, *Response, error) {
102 req, err := c.NewRequest("GET", "codes_of_conduct", nil)
103 if err != nil {
104 return nil, nil, err
105 }
106
107
108 req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
109
110 var cs []*CodeOfConduct
111 resp, err := c.Do(ctx, req, &cs)
112 if err != nil {
113 return nil, resp, err
114 }
115
116 return cs, resp, nil
117 }
118
119
120
121
122 func (c *Client) GetCodeOfConduct(ctx context.Context, key string) (*CodeOfConduct, *Response, error) {
123 u := fmt.Sprintf("codes_of_conduct/%s", key)
124 req, err := c.NewRequest("GET", u, nil)
125 if err != nil {
126 return nil, nil, err
127 }
128
129
130 req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
131
132 coc := new(CodeOfConduct)
133 resp, err := c.Do(ctx, req, coc)
134 if err != nil {
135 return nil, resp, err
136 }
137
138 return coc, resp, nil
139 }
140
141
142 type APIMeta struct {
143
144
145 Hooks []string `json:"hooks,omitempty"`
146
147
148
149 Git []string `json:"git,omitempty"`
150
151
152
153
154
155
156 VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"`
157
158
159
160 Pages []string `json:"pages,omitempty"`
161
162
163
164 Importer []string `json:"importer,omitempty"`
165
166
167
168 Actions []string `json:"actions,omitempty"`
169
170
171
172 Dependabot []string `json:"dependabot,omitempty"`
173
174
175 SSHKeyFingerprints map[string]string `json:"ssh_key_fingerprints,omitempty"`
176
177
178 SSHKeys []string `json:"ssh_keys,omitempty"`
179
180
181
182 Web []string `json:"web,omitempty"`
183
184
185
186 API []string `json:"api,omitempty"`
187 }
188
189
190
191
192
193
194 func (c *Client) APIMeta(ctx context.Context) (*APIMeta, *Response, error) {
195 req, err := c.NewRequest("GET", "meta", nil)
196 if err != nil {
197 return nil, nil, err
198 }
199
200 meta := new(APIMeta)
201 resp, err := c.Do(ctx, req, meta)
202 if err != nil {
203 return nil, resp, err
204 }
205
206 return meta, resp, nil
207 }
208
209
210
211 func (c *Client) Octocat(ctx context.Context, message string) (string, *Response, error) {
212 u := "octocat"
213 if message != "" {
214 u = fmt.Sprintf("%s?s=%s", u, url.QueryEscape(message))
215 }
216
217 req, err := c.NewRequest("GET", u, nil)
218 if err != nil {
219 return "", nil, err
220 }
221
222 buf := new(bytes.Buffer)
223 resp, err := c.Do(ctx, req, buf)
224 if err != nil {
225 return "", resp, err
226 }
227
228 return buf.String(), resp, nil
229 }
230
231
232
233
234 func (c *Client) Zen(ctx context.Context) (string, *Response, error) {
235 req, err := c.NewRequest("GET", "zen", nil)
236 if err != nil {
237 return "", nil, err
238 }
239
240 buf := new(bytes.Buffer)
241 resp, err := c.Do(ctx, req, buf)
242 if err != nil {
243 return "", resp, err
244 }
245
246 return buf.String(), resp, nil
247 }
248
249
250
251 type ServiceHook struct {
252 Name *string `json:"name,omitempty"`
253 Events []string `json:"events,omitempty"`
254 SupportedEvents []string `json:"supported_events,omitempty"`
255 Schema [][]string `json:"schema,omitempty"`
256 }
257
258 func (s *ServiceHook) String() string {
259 return Stringify(s)
260 }
261
262
263
264
265 func (c *Client) ListServiceHooks(ctx context.Context) ([]*ServiceHook, *Response, error) {
266 u := "hooks"
267 req, err := c.NewRequest("GET", u, nil)
268 if err != nil {
269 return nil, nil, err
270 }
271
272 var hooks []*ServiceHook
273 resp, err := c.Do(ctx, req, &hooks)
274 if err != nil {
275 return nil, resp, err
276 }
277
278 return hooks, resp, nil
279 }
280
View as plain text