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 "time"
23 )
24
25
26
27
28
29 type NotesService struct {
30 client *Client
31 }
32
33
34
35
36 type Note struct {
37 ID int `json:"id"`
38 Type NoteTypeValue `json:"type"`
39 Body string `json:"body"`
40 Attachment string `json:"attachment"`
41 Title string `json:"title"`
42 FileName string `json:"file_name"`
43 Author struct {
44 ID int `json:"id"`
45 Username string `json:"username"`
46 Email string `json:"email"`
47 Name string `json:"name"`
48 State string `json:"state"`
49 AvatarURL string `json:"avatar_url"`
50 WebURL string `json:"web_url"`
51 } `json:"author"`
52 System bool `json:"system"`
53 CreatedAt *time.Time `json:"created_at"`
54 UpdatedAt *time.Time `json:"updated_at"`
55 ExpiresAt *time.Time `json:"expires_at"`
56 CommitID string `json:"commit_id"`
57 Position *NotePosition `json:"position"`
58 NoteableID int `json:"noteable_id"`
59 NoteableType string `json:"noteable_type"`
60 ProjectID int `json:"project_id"`
61 NoteableIID int `json:"noteable_iid"`
62 Resolvable bool `json:"resolvable"`
63 Resolved bool `json:"resolved"`
64 ResolvedAt *time.Time `json:"resolved_at"`
65 ResolvedBy struct {
66 ID int `json:"id"`
67 Username string `json:"username"`
68 Email string `json:"email"`
69 Name string `json:"name"`
70 State string `json:"state"`
71 AvatarURL string `json:"avatar_url"`
72 WebURL string `json:"web_url"`
73 } `json:"resolved_by"`
74 Confidential bool `json:"confidential"`
75 Internal bool `json:"internal"`
76 }
77
78
79 type NotePosition struct {
80 BaseSHA string `json:"base_sha"`
81 StartSHA string `json:"start_sha"`
82 HeadSHA string `json:"head_sha"`
83 PositionType string `json:"position_type"`
84 NewPath string `json:"new_path,omitempty"`
85 NewLine int `json:"new_line,omitempty"`
86 OldPath string `json:"old_path,omitempty"`
87 OldLine int `json:"old_line,omitempty"`
88 LineRange *LineRange `json:"line_range,omitempty"`
89 }
90
91
92 type LineRange struct {
93 StartRange *LinePosition `json:"start"`
94 EndRange *LinePosition `json:"end"`
95 }
96
97
98 type LinePosition struct {
99 LineCode string `json:"line_code"`
100 Type string `json:"type"`
101 OldLine int `json:"old_line"`
102 NewLine int `json:"new_line"`
103 }
104
105 func (n Note) String() string {
106 return Stringify(n)
107 }
108
109
110
111
112
113 type ListIssueNotesOptions struct {
114 ListOptions
115 OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
116 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
117 }
118
119
120
121
122
123 func (s *NotesService) ListIssueNotes(pid interface{}, issue int, opt *ListIssueNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
124 project, err := parseID(pid)
125 if err != nil {
126 return nil, nil, err
127 }
128 u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue)
129
130 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
131 if err != nil {
132 return nil, nil, err
133 }
134
135 var n []*Note
136 resp, err := s.client.Do(req, &n)
137 if err != nil {
138 return nil, resp, err
139 }
140
141 return n, resp, nil
142 }
143
144
145
146
147
148 func (s *NotesService) GetIssueNote(pid interface{}, issue, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
149 project, err := parseID(pid)
150 if err != nil {
151 return nil, nil, err
152 }
153 u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
154
155 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
156 if err != nil {
157 return nil, nil, err
158 }
159
160 n := new(Note)
161 resp, err := s.client.Do(req, n)
162 if err != nil {
163 return nil, resp, err
164 }
165
166 return n, resp, nil
167 }
168
169
170
171
172
173
174 type CreateIssueNoteOptions struct {
175 Body *string `url:"body,omitempty" json:"body,omitempty"`
176 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
177 }
178
179
180
181
182
183 func (s *NotesService) CreateIssueNote(pid interface{}, issue int, opt *CreateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
184 project, err := parseID(pid)
185 if err != nil {
186 return nil, nil, err
187 }
188 u := fmt.Sprintf("projects/%s/issues/%d/notes", PathEscape(project), issue)
189
190 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
191 if err != nil {
192 return nil, nil, err
193 }
194
195 n := new(Note)
196 resp, err := s.client.Do(req, n)
197 if err != nil {
198 return nil, resp, err
199 }
200
201 return n, resp, nil
202 }
203
204
205
206
207
208
209 type UpdateIssueNoteOptions struct {
210 Body *string `url:"body,omitempty" json:"body,omitempty"`
211 }
212
213
214
215
216
217 func (s *NotesService) UpdateIssueNote(pid interface{}, issue, note int, opt *UpdateIssueNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
218 project, err := parseID(pid)
219 if err != nil {
220 return nil, nil, err
221 }
222 u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
223
224 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
225 if err != nil {
226 return nil, nil, err
227 }
228
229 n := new(Note)
230 resp, err := s.client.Do(req, n)
231 if err != nil {
232 return nil, resp, err
233 }
234
235 return n, resp, nil
236 }
237
238
239
240
241
242 func (s *NotesService) DeleteIssueNote(pid interface{}, issue, note int, options ...RequestOptionFunc) (*Response, error) {
243 project, err := parseID(pid)
244 if err != nil {
245 return nil, err
246 }
247 u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", PathEscape(project), issue, note)
248
249 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
250 if err != nil {
251 return nil, err
252 }
253
254 return s.client.Do(req, nil)
255 }
256
257
258
259
260
261 type ListSnippetNotesOptions struct {
262 ListOptions
263 OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
264 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
265 }
266
267
268
269
270
271
272 func (s *NotesService) ListSnippetNotes(pid interface{}, snippet int, opt *ListSnippetNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
273 project, err := parseID(pid)
274 if err != nil {
275 return nil, nil, err
276 }
277 u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet)
278
279 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
280 if err != nil {
281 return nil, nil, err
282 }
283
284 var n []*Note
285 resp, err := s.client.Do(req, &n)
286 if err != nil {
287 return nil, resp, err
288 }
289
290 return n, resp, nil
291 }
292
293
294
295
296
297 func (s *NotesService) GetSnippetNote(pid interface{}, snippet, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
298 project, err := parseID(pid)
299 if err != nil {
300 return nil, nil, err
301 }
302 u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
303
304 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
305 if err != nil {
306 return nil, nil, err
307 }
308
309 n := new(Note)
310 resp, err := s.client.Do(req, n)
311 if err != nil {
312 return nil, resp, err
313 }
314
315 return n, resp, nil
316 }
317
318
319
320
321
322
323 type CreateSnippetNoteOptions struct {
324 Body *string `url:"body,omitempty" json:"body,omitempty"`
325 }
326
327
328
329
330
331
332 func (s *NotesService) CreateSnippetNote(pid interface{}, snippet int, opt *CreateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
333 project, err := parseID(pid)
334 if err != nil {
335 return nil, nil, err
336 }
337 u := fmt.Sprintf("projects/%s/snippets/%d/notes", PathEscape(project), snippet)
338
339 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
340 if err != nil {
341 return nil, nil, err
342 }
343
344 n := new(Note)
345 resp, err := s.client.Do(req, n)
346 if err != nil {
347 return nil, resp, err
348 }
349
350 return n, resp, nil
351 }
352
353
354
355
356
357
358 type UpdateSnippetNoteOptions struct {
359 Body *string `url:"body,omitempty" json:"body,omitempty"`
360 }
361
362
363
364
365
366 func (s *NotesService) UpdateSnippetNote(pid interface{}, snippet, note int, opt *UpdateSnippetNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
367 project, err := parseID(pid)
368 if err != nil {
369 return nil, nil, err
370 }
371 u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
372
373 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
374 if err != nil {
375 return nil, nil, err
376 }
377
378 n := new(Note)
379 resp, err := s.client.Do(req, n)
380 if err != nil {
381 return nil, resp, err
382 }
383
384 return n, resp, nil
385 }
386
387
388
389
390
391 func (s *NotesService) DeleteSnippetNote(pid interface{}, snippet, note int, options ...RequestOptionFunc) (*Response, error) {
392 project, err := parseID(pid)
393 if err != nil {
394 return nil, err
395 }
396 u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", PathEscape(project), snippet, note)
397
398 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
399 if err != nil {
400 return nil, err
401 }
402
403 return s.client.Do(req, nil)
404 }
405
406
407
408
409
410
411 type ListMergeRequestNotesOptions struct {
412 ListOptions
413 OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
414 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
415 }
416
417
418
419
420
421 func (s *NotesService) ListMergeRequestNotes(pid interface{}, mergeRequest int, opt *ListMergeRequestNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
422 project, err := parseID(pid)
423 if err != nil {
424 return nil, nil, err
425 }
426 u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest)
427
428 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
429 if err != nil {
430 return nil, nil, err
431 }
432
433 var n []*Note
434 resp, err := s.client.Do(req, &n)
435 if err != nil {
436 return nil, resp, err
437 }
438
439 return n, resp, nil
440 }
441
442
443
444
445
446 func (s *NotesService) GetMergeRequestNote(pid interface{}, mergeRequest, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
447 project, err := parseID(pid)
448 if err != nil {
449 return nil, nil, err
450 }
451 u := fmt.Sprintf("projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
452
453 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
454 if err != nil {
455 return nil, nil, err
456 }
457
458 n := new(Note)
459 resp, err := s.client.Do(req, n)
460 if err != nil {
461 return nil, resp, err
462 }
463
464 return n, resp, nil
465 }
466
467
468
469
470
471
472 type CreateMergeRequestNoteOptions struct {
473 Body *string `url:"body,omitempty" json:"body,omitempty"`
474 }
475
476
477
478
479
480 func (s *NotesService) CreateMergeRequestNote(pid interface{}, mergeRequest int, opt *CreateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
481 project, err := parseID(pid)
482 if err != nil {
483 return nil, nil, err
484 }
485 u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", PathEscape(project), mergeRequest)
486
487 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
488 if err != nil {
489 return nil, nil, err
490 }
491
492 n := new(Note)
493 resp, err := s.client.Do(req, n)
494 if err != nil {
495 return nil, resp, err
496 }
497
498 return n, resp, nil
499 }
500
501
502
503
504
505
506 type UpdateMergeRequestNoteOptions struct {
507 Body *string `url:"body,omitempty" json:"body,omitempty"`
508 }
509
510
511
512
513
514 func (s *NotesService) UpdateMergeRequestNote(pid interface{}, mergeRequest, note int, opt *UpdateMergeRequestNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
515 project, err := parseID(pid)
516 if err != nil {
517 return nil, nil, err
518 }
519 u := fmt.Sprintf(
520 "projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
521 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
522 if err != nil {
523 return nil, nil, err
524 }
525
526 n := new(Note)
527 resp, err := s.client.Do(req, n)
528 if err != nil {
529 return nil, resp, err
530 }
531
532 return n, resp, nil
533 }
534
535
536
537
538
539 func (s *NotesService) DeleteMergeRequestNote(pid interface{}, mergeRequest, note int, options ...RequestOptionFunc) (*Response, error) {
540 project, err := parseID(pid)
541 if err != nil {
542 return nil, err
543 }
544 u := fmt.Sprintf(
545 "projects/%s/merge_requests/%d/notes/%d", PathEscape(project), mergeRequest, note)
546
547 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
548 if err != nil {
549 return nil, err
550 }
551
552 return s.client.Do(req, nil)
553 }
554
555
556
557
558
559 type ListEpicNotesOptions struct {
560 ListOptions
561 OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
562 Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
563 }
564
565
566
567
568
569 func (s *NotesService) ListEpicNotes(gid interface{}, epic int, opt *ListEpicNotesOptions, options ...RequestOptionFunc) ([]*Note, *Response, error) {
570 group, err := parseID(gid)
571 if err != nil {
572 return nil, nil, err
573 }
574 u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic)
575
576 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
577 if err != nil {
578 return nil, nil, err
579 }
580
581 var n []*Note
582 resp, err := s.client.Do(req, &n)
583 if err != nil {
584 return nil, resp, err
585 }
586
587 return n, resp, nil
588 }
589
590
591
592
593
594 func (s *NotesService) GetEpicNote(gid interface{}, epic, note int, options ...RequestOptionFunc) (*Note, *Response, error) {
595 group, err := parseID(gid)
596 if err != nil {
597 return nil, nil, err
598 }
599 u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
600
601 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
602 if err != nil {
603 return nil, nil, err
604 }
605
606 n := new(Note)
607 resp, err := s.client.Do(req, n)
608 if err != nil {
609 return nil, resp, err
610 }
611
612 return n, resp, nil
613 }
614
615
616
617
618
619 type CreateEpicNoteOptions struct {
620 Body *string `url:"body,omitempty" json:"body,omitempty"`
621 }
622
623
624
625
626
627 func (s *NotesService) CreateEpicNote(gid interface{}, epic int, opt *CreateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
628 group, err := parseID(gid)
629 if err != nil {
630 return nil, nil, err
631 }
632 u := fmt.Sprintf("groups/%s/epics/%d/notes", PathEscape(group), epic)
633
634 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
635 if err != nil {
636 return nil, nil, err
637 }
638
639 n := new(Note)
640 resp, err := s.client.Do(req, n)
641 if err != nil {
642 return nil, resp, err
643 }
644
645 return n, resp, nil
646 }
647
648
649
650
651
652 type UpdateEpicNoteOptions struct {
653 Body *string `url:"body,omitempty" json:"body,omitempty"`
654 }
655
656
657
658
659 func (s *NotesService) UpdateEpicNote(gid interface{}, epic, note int, opt *UpdateEpicNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
660 group, err := parseID(gid)
661 if err != nil {
662 return nil, nil, err
663 }
664 u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
665
666 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
667 if err != nil {
668 return nil, nil, err
669 }
670
671 n := new(Note)
672 resp, err := s.client.Do(req, n)
673 if err != nil {
674 return nil, resp, err
675 }
676
677 return n, resp, nil
678 }
679
680
681
682
683 func (s *NotesService) DeleteEpicNote(gid interface{}, epic, note int, options ...RequestOptionFunc) (*Response, error) {
684 group, err := parseID(gid)
685 if err != nil {
686 return nil, err
687 }
688 u := fmt.Sprintf("groups/%s/epics/%d/notes/%d", PathEscape(group), epic, note)
689
690 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
691 if err != nil {
692 return nil, err
693 }
694
695 return s.client.Do(req, nil)
696 }
697
View as plain text