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 DiscussionsService struct {
30 client *Client
31 }
32
33
34
35
36 type Discussion struct {
37 ID string `json:"id"`
38 IndividualNote bool `json:"individual_note"`
39 Notes []*Note `json:"notes"`
40 }
41
42 func (d Discussion) String() string {
43 return Stringify(d)
44 }
45
46
47
48
49
50
51 type ListIssueDiscussionsOptions ListOptions
52
53
54
55
56
57
58 func (s *DiscussionsService) ListIssueDiscussions(pid interface{}, issue int, opt *ListIssueDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
59 project, err := parseID(pid)
60 if err != nil {
61 return nil, nil, err
62 }
63 u := fmt.Sprintf("projects/%s/issues/%d/discussions", PathEscape(project), issue)
64
65 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
66 if err != nil {
67 return nil, nil, err
68 }
69
70 var ds []*Discussion
71 resp, err := s.client.Do(req, &ds)
72 if err != nil {
73 return nil, resp, err
74 }
75
76 return ds, resp, nil
77 }
78
79
80
81
82
83 func (s *DiscussionsService) GetIssueDiscussion(pid interface{}, issue int, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
84 project, err := parseID(pid)
85 if err != nil {
86 return nil, nil, err
87 }
88 u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s",
89 PathEscape(project),
90 issue,
91 discussion,
92 )
93
94 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
95 if err != nil {
96 return nil, nil, err
97 }
98
99 d := new(Discussion)
100 resp, err := s.client.Do(req, d)
101 if err != nil {
102 return nil, resp, err
103 }
104
105 return d, resp, nil
106 }
107
108
109
110
111
112
113 type CreateIssueDiscussionOptions struct {
114 Body *string `url:"body,omitempty" json:"body,omitempty"`
115 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
116 }
117
118
119
120
121
122 func (s *DiscussionsService) CreateIssueDiscussion(pid interface{}, issue int, opt *CreateIssueDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
123 project, err := parseID(pid)
124 if err != nil {
125 return nil, nil, err
126 }
127 u := fmt.Sprintf("projects/%s/issues/%d/discussions", PathEscape(project), issue)
128
129 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
130 if err != nil {
131 return nil, nil, err
132 }
133
134 d := new(Discussion)
135 resp, err := s.client.Do(req, d)
136 if err != nil {
137 return nil, resp, err
138 }
139
140 return d, resp, nil
141 }
142
143
144
145
146
147
148 type AddIssueDiscussionNoteOptions struct {
149 Body *string `url:"body,omitempty" json:"body,omitempty"`
150 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
151 }
152
153
154
155
156
157 func (s *DiscussionsService) AddIssueDiscussionNote(pid interface{}, issue int, discussion string, opt *AddIssueDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
158 project, err := parseID(pid)
159 if err != nil {
160 return nil, nil, err
161 }
162 u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes",
163 PathEscape(project),
164 issue,
165 discussion,
166 )
167
168 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
169 if err != nil {
170 return nil, nil, err
171 }
172
173 n := new(Note)
174 resp, err := s.client.Do(req, n)
175 if err != nil {
176 return nil, resp, err
177 }
178
179 return n, resp, nil
180 }
181
182
183
184
185
186
187 type UpdateIssueDiscussionNoteOptions struct {
188 Body *string `url:"body,omitempty" json:"body,omitempty"`
189 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
190 }
191
192
193
194
195
196 func (s *DiscussionsService) UpdateIssueDiscussionNote(pid interface{}, issue int, discussion string, note int, opt *UpdateIssueDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
197 project, err := parseID(pid)
198 if err != nil {
199 return nil, nil, err
200 }
201 u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes/%d",
202 PathEscape(project),
203 issue,
204 discussion,
205 note,
206 )
207
208 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
209 if err != nil {
210 return nil, nil, err
211 }
212
213 n := new(Note)
214 resp, err := s.client.Do(req, n)
215 if err != nil {
216 return nil, resp, err
217 }
218
219 return n, resp, nil
220 }
221
222
223
224
225
226 func (s *DiscussionsService) DeleteIssueDiscussionNote(pid interface{}, issue int, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
227 project, err := parseID(pid)
228 if err != nil {
229 return nil, err
230 }
231 u := fmt.Sprintf("projects/%s/issues/%d/discussions/%s/notes/%d",
232 PathEscape(project),
233 issue,
234 discussion,
235 note,
236 )
237
238 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
239 if err != nil {
240 return nil, err
241 }
242
243 return s.client.Do(req, nil)
244 }
245
246
247
248
249
250
251 type ListSnippetDiscussionsOptions ListOptions
252
253
254
255
256
257
258 func (s *DiscussionsService) ListSnippetDiscussions(pid interface{}, snippet int, opt *ListSnippetDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
259 project, err := parseID(pid)
260 if err != nil {
261 return nil, nil, err
262 }
263 u := fmt.Sprintf("projects/%s/snippets/%d/discussions", PathEscape(project), snippet)
264
265 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
266 if err != nil {
267 return nil, nil, err
268 }
269
270 var ds []*Discussion
271 resp, err := s.client.Do(req, &ds)
272 if err != nil {
273 return nil, resp, err
274 }
275
276 return ds, resp, nil
277 }
278
279
280
281
282
283 func (s *DiscussionsService) GetSnippetDiscussion(pid interface{}, snippet int, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
284 project, err := parseID(pid)
285 if err != nil {
286 return nil, nil, err
287 }
288 u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s",
289 PathEscape(project),
290 snippet,
291 discussion,
292 )
293
294 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
295 if err != nil {
296 return nil, nil, err
297 }
298
299 d := new(Discussion)
300 resp, err := s.client.Do(req, d)
301 if err != nil {
302 return nil, resp, err
303 }
304
305 return d, resp, nil
306 }
307
308
309
310
311
312
313 type CreateSnippetDiscussionOptions struct {
314 Body *string `url:"body,omitempty" json:"body,omitempty"`
315 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
316 }
317
318
319
320
321
322
323 func (s *DiscussionsService) CreateSnippetDiscussion(pid interface{}, snippet int, opt *CreateSnippetDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
324 project, err := parseID(pid)
325 if err != nil {
326 return nil, nil, err
327 }
328 u := fmt.Sprintf("projects/%s/snippets/%d/discussions", PathEscape(project), snippet)
329
330 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
331 if err != nil {
332 return nil, nil, err
333 }
334
335 d := new(Discussion)
336 resp, err := s.client.Do(req, d)
337 if err != nil {
338 return nil, resp, err
339 }
340
341 return d, resp, nil
342 }
343
344
345
346
347
348
349 type AddSnippetDiscussionNoteOptions struct {
350 Body *string `url:"body,omitempty" json:"body,omitempty"`
351 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
352 }
353
354
355
356
357
358
359 func (s *DiscussionsService) AddSnippetDiscussionNote(pid interface{}, snippet int, discussion string, opt *AddSnippetDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
360 project, err := parseID(pid)
361 if err != nil {
362 return nil, nil, err
363 }
364 u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes",
365 PathEscape(project),
366 snippet,
367 discussion,
368 )
369
370 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
371 if err != nil {
372 return nil, nil, err
373 }
374
375 n := new(Note)
376 resp, err := s.client.Do(req, n)
377 if err != nil {
378 return nil, resp, err
379 }
380
381 return n, resp, nil
382 }
383
384
385
386
387
388
389 type UpdateSnippetDiscussionNoteOptions struct {
390 Body *string `url:"body,omitempty" json:"body,omitempty"`
391 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
392 }
393
394
395
396
397
398 func (s *DiscussionsService) UpdateSnippetDiscussionNote(pid interface{}, snippet int, discussion string, note int, opt *UpdateSnippetDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
399 project, err := parseID(pid)
400 if err != nil {
401 return nil, nil, err
402 }
403 u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes/%d",
404 PathEscape(project),
405 snippet,
406 discussion,
407 note,
408 )
409
410 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
411 if err != nil {
412 return nil, nil, err
413 }
414
415 n := new(Note)
416 resp, err := s.client.Do(req, n)
417 if err != nil {
418 return nil, resp, err
419 }
420
421 return n, resp, nil
422 }
423
424
425
426
427
428 func (s *DiscussionsService) DeleteSnippetDiscussionNote(pid interface{}, snippet int, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
429 project, err := parseID(pid)
430 if err != nil {
431 return nil, err
432 }
433 u := fmt.Sprintf("projects/%s/snippets/%d/discussions/%s/notes/%d",
434 PathEscape(project),
435 snippet,
436 discussion,
437 note,
438 )
439
440 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
441 if err != nil {
442 return nil, err
443 }
444
445 return s.client.Do(req, nil)
446 }
447
448
449
450
451
452
453 type ListGroupEpicDiscussionsOptions ListOptions
454
455
456
457
458
459
460 func (s *DiscussionsService) ListGroupEpicDiscussions(gid interface{}, epic int, opt *ListGroupEpicDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
461 group, err := parseID(gid)
462 if err != nil {
463 return nil, nil, err
464 }
465 u := fmt.Sprintf("groups/%s/epics/%d/discussions",
466 PathEscape(group),
467 epic,
468 )
469
470 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
471 if err != nil {
472 return nil, nil, err
473 }
474
475 var ds []*Discussion
476 resp, err := s.client.Do(req, &ds)
477 if err != nil {
478 return nil, resp, err
479 }
480
481 return ds, resp, nil
482 }
483
484
485
486
487
488 func (s *DiscussionsService) GetEpicDiscussion(gid interface{}, epic int, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
489 group, err := parseID(gid)
490 if err != nil {
491 return nil, nil, err
492 }
493 u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s",
494 PathEscape(group),
495 epic,
496 discussion,
497 )
498
499 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
500 if err != nil {
501 return nil, nil, err
502 }
503
504 d := new(Discussion)
505 resp, err := s.client.Do(req, d)
506 if err != nil {
507 return nil, resp, err
508 }
509
510 return d, resp, nil
511 }
512
513
514
515
516
517
518 type CreateEpicDiscussionOptions struct {
519 Body *string `url:"body,omitempty" json:"body,omitempty"`
520 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
521 }
522
523
524
525
526
527
528 func (s *DiscussionsService) CreateEpicDiscussion(gid interface{}, epic int, opt *CreateEpicDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
529 group, err := parseID(gid)
530 if err != nil {
531 return nil, nil, err
532 }
533 u := fmt.Sprintf("groups/%s/epics/%d/discussions",
534 PathEscape(group),
535 epic,
536 )
537
538 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
539 if err != nil {
540 return nil, nil, err
541 }
542
543 d := new(Discussion)
544 resp, err := s.client.Do(req, d)
545 if err != nil {
546 return nil, resp, err
547 }
548
549 return d, resp, nil
550 }
551
552
553
554
555
556
557 type AddEpicDiscussionNoteOptions struct {
558 Body *string `url:"body,omitempty" json:"body,omitempty"`
559 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
560 }
561
562
563
564
565
566 func (s *DiscussionsService) AddEpicDiscussionNote(gid interface{}, epic int, discussion string, opt *AddEpicDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
567 group, err := parseID(gid)
568 if err != nil {
569 return nil, nil, err
570 }
571 u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes",
572 PathEscape(group),
573 epic,
574 discussion,
575 )
576
577 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
578 if err != nil {
579 return nil, nil, err
580 }
581
582 n := new(Note)
583 resp, err := s.client.Do(req, n)
584 if err != nil {
585 return nil, resp, err
586 }
587
588 return n, resp, nil
589 }
590
591
592
593
594
595
596 type UpdateEpicDiscussionNoteOptions struct {
597 Body *string `url:"body,omitempty" json:"body,omitempty"`
598 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
599 }
600
601
602
603
604
605 func (s *DiscussionsService) UpdateEpicDiscussionNote(gid interface{}, epic int, discussion string, note int, opt *UpdateEpicDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
606 group, err := parseID(gid)
607 if err != nil {
608 return nil, nil, err
609 }
610 u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes/%d",
611 PathEscape(group),
612 epic,
613 discussion,
614 note,
615 )
616
617 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
618 if err != nil {
619 return nil, nil, err
620 }
621
622 n := new(Note)
623 resp, err := s.client.Do(req, n)
624 if err != nil {
625 return nil, resp, err
626 }
627
628 return n, resp, nil
629 }
630
631
632
633
634
635 func (s *DiscussionsService) DeleteEpicDiscussionNote(gid interface{}, epic int, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
636 group, err := parseID(gid)
637 if err != nil {
638 return nil, err
639 }
640 u := fmt.Sprintf("groups/%s/epics/%d/discussions/%s/notes/%d",
641 PathEscape(group),
642 epic,
643 discussion,
644 note,
645 )
646
647 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
648 if err != nil {
649 return nil, err
650 }
651
652 return s.client.Do(req, nil)
653 }
654
655
656
657
658
659
660 type ListMergeRequestDiscussionsOptions ListOptions
661
662
663
664
665
666
667 func (s *DiscussionsService) ListMergeRequestDiscussions(pid interface{}, mergeRequest int, opt *ListMergeRequestDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
668 project, err := parseID(pid)
669 if err != nil {
670 return nil, nil, err
671 }
672 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions",
673 PathEscape(project),
674 mergeRequest,
675 )
676
677 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
678 if err != nil {
679 return nil, nil, err
680 }
681
682 var ds []*Discussion
683 resp, err := s.client.Do(req, &ds)
684 if err != nil {
685 return nil, resp, err
686 }
687
688 return ds, resp, nil
689 }
690
691
692
693
694
695
696 func (s *DiscussionsService) GetMergeRequestDiscussion(pid interface{}, mergeRequest int, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
697 project, err := parseID(pid)
698 if err != nil {
699 return nil, nil, err
700 }
701 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s",
702 PathEscape(project),
703 mergeRequest,
704 discussion,
705 )
706
707 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
708 if err != nil {
709 return nil, nil, err
710 }
711
712 d := new(Discussion)
713 resp, err := s.client.Do(req, d)
714 if err != nil {
715 return nil, resp, err
716 }
717
718 return d, resp, nil
719 }
720
721
722
723
724
725
726 type CreateMergeRequestDiscussionOptions struct {
727 Body *string `url:"body,omitempty" json:"body,omitempty"`
728 CommitID *string `url:"commit_id,omitempty" json:"commit_id,omitempty"`
729 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
730 Position *PositionOptions `url:"position,omitempty" json:"position,omitempty"`
731 }
732
733
734 type PositionOptions struct {
735 BaseSHA *string `url:"base_sha,omitempty" json:"base_sha,omitempty"`
736 HeadSHA *string `url:"head_sha,omitempty" json:"head_sha,omitempty"`
737 StartSHA *string `url:"start_sha,omitempty" json:"start_sha,omitempty"`
738 NewPath *string `url:"new_path,omitempty" json:"new_path,omitempty"`
739 OldPath *string `url:"old_path,omitempty" json:"old_path,omitempty"`
740 PositionType *string `url:"position_type,omitempty" json:"position_type"`
741 NewLine *int `url:"new_line,omitempty" json:"new_line,omitempty"`
742 OldLine *int `url:"old_line,omitempty" json:"old_line,omitempty"`
743 LineRange *LineRangeOptions `url:"line_range,omitempty" json:"line_range,omitempty"`
744 Width *int `url:"width,omitempty" json:"width,omitempty"`
745 Height *int `url:"height,omitempty" json:"height,omitempty"`
746 X *float64 `url:"x,omitempty" json:"x,omitempty"`
747 Y *float64 `url:"y,omitempty" json:"y,omitempty"`
748 }
749
750
751 type LineRangeOptions struct {
752 Start *LinePositionOptions `url:"start,omitempty" json:"start,omitempty"`
753 End *LinePositionOptions `url:"end,omitempty" json:"end,omitempty"`
754 }
755
756
757 type LinePositionOptions struct {
758 LineCode *string `url:"line_code,omitempty" json:"line_code,omitempty"`
759 Type *string `url:"type,omitempty" json:"type,omitempty"`
760 }
761
762
763
764
765
766
767 func (s *DiscussionsService) CreateMergeRequestDiscussion(pid interface{}, mergeRequest int, opt *CreateMergeRequestDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
768 project, err := parseID(pid)
769 if err != nil {
770 return nil, nil, err
771 }
772 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions",
773 PathEscape(project),
774 mergeRequest,
775 )
776
777 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
778 if err != nil {
779 return nil, nil, err
780 }
781
782 d := new(Discussion)
783 resp, err := s.client.Do(req, d)
784 if err != nil {
785 return nil, resp, err
786 }
787
788 return d, resp, nil
789 }
790
791
792
793
794
795
796 type ResolveMergeRequestDiscussionOptions struct {
797 Resolved *bool `url:"resolved,omitempty" json:"resolved,omitempty"`
798 }
799
800
801
802
803
804
805 func (s *DiscussionsService) ResolveMergeRequestDiscussion(pid interface{}, mergeRequest int, discussion string, opt *ResolveMergeRequestDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
806 project, err := parseID(pid)
807 if err != nil {
808 return nil, nil, err
809 }
810 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s",
811 PathEscape(project),
812 mergeRequest,
813 discussion,
814 )
815
816 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
817 if err != nil {
818 return nil, nil, err
819 }
820
821 d := new(Discussion)
822 resp, err := s.client.Do(req, d)
823 if err != nil {
824 return nil, resp, err
825 }
826
827 return d, resp, nil
828 }
829
830
831
832
833
834
835 type AddMergeRequestDiscussionNoteOptions struct {
836 Body *string `url:"body,omitempty" json:"body,omitempty"`
837 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
838 }
839
840
841
842
843
844
845 func (s *DiscussionsService) AddMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, opt *AddMergeRequestDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
846 project, err := parseID(pid)
847 if err != nil {
848 return nil, nil, err
849 }
850 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes",
851 PathEscape(project),
852 mergeRequest,
853 discussion,
854 )
855
856 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
857 if err != nil {
858 return nil, nil, err
859 }
860
861 n := new(Note)
862 resp, err := s.client.Do(req, n)
863 if err != nil {
864 return nil, resp, err
865 }
866
867 return n, resp, nil
868 }
869
870
871
872
873
874
875 type UpdateMergeRequestDiscussionNoteOptions struct {
876 Body *string `url:"body,omitempty" json:"body,omitempty"`
877 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
878 Resolved *bool `url:"resolved,omitempty" json:"resolved,omitempty"`
879 }
880
881
882
883
884
885
886 func (s *DiscussionsService) UpdateMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, opt *UpdateMergeRequestDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
887 project, err := parseID(pid)
888 if err != nil {
889 return nil, nil, err
890 }
891 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes/%d",
892 PathEscape(project),
893 mergeRequest,
894 discussion,
895 note,
896 )
897
898 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
899 if err != nil {
900 return nil, nil, err
901 }
902
903 n := new(Note)
904 resp, err := s.client.Do(req, n)
905 if err != nil {
906 return nil, resp, err
907 }
908
909 return n, resp, nil
910 }
911
912
913
914
915
916
917 func (s *DiscussionsService) DeleteMergeRequestDiscussionNote(pid interface{}, mergeRequest int, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
918 project, err := parseID(pid)
919 if err != nil {
920 return nil, err
921 }
922 u := fmt.Sprintf("projects/%s/merge_requests/%d/discussions/%s/notes/%d",
923 PathEscape(project),
924 mergeRequest,
925 discussion,
926 note,
927 )
928
929 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
930 if err != nil {
931 return nil, err
932 }
933
934 return s.client.Do(req, nil)
935 }
936
937
938
939
940
941
942 type ListCommitDiscussionsOptions ListOptions
943
944
945
946
947
948
949 func (s *DiscussionsService) ListCommitDiscussions(pid interface{}, commit string, opt *ListCommitDiscussionsOptions, options ...RequestOptionFunc) ([]*Discussion, *Response, error) {
950 project, err := parseID(pid)
951 if err != nil {
952 return nil, nil, err
953 }
954 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions",
955 PathEscape(project),
956 commit,
957 )
958
959 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
960 if err != nil {
961 return nil, nil, err
962 }
963
964 var ds []*Discussion
965 resp, err := s.client.Do(req, &ds)
966 if err != nil {
967 return nil, resp, err
968 }
969
970 return ds, resp, nil
971 }
972
973
974
975
976
977
978 func (s *DiscussionsService) GetCommitDiscussion(pid interface{}, commit string, discussion string, options ...RequestOptionFunc) (*Discussion, *Response, error) {
979 project, err := parseID(pid)
980 if err != nil {
981 return nil, nil, err
982 }
983 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s",
984 PathEscape(project),
985 commit,
986 discussion,
987 )
988
989 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
990 if err != nil {
991 return nil, nil, err
992 }
993
994 d := new(Discussion)
995 resp, err := s.client.Do(req, d)
996 if err != nil {
997 return nil, resp, err
998 }
999
1000 return d, resp, nil
1001 }
1002
1003
1004
1005
1006
1007
1008 type CreateCommitDiscussionOptions struct {
1009 Body *string `url:"body,omitempty" json:"body,omitempty"`
1010 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
1011 Position *NotePosition `url:"position,omitempty" json:"position,omitempty"`
1012 }
1013
1014
1015
1016
1017
1018 func (s *DiscussionsService) CreateCommitDiscussion(pid interface{}, commit string, opt *CreateCommitDiscussionOptions, options ...RequestOptionFunc) (*Discussion, *Response, error) {
1019 project, err := parseID(pid)
1020 if err != nil {
1021 return nil, nil, err
1022 }
1023 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions",
1024 PathEscape(project),
1025 commit,
1026 )
1027
1028 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
1029 if err != nil {
1030 return nil, nil, err
1031 }
1032
1033 d := new(Discussion)
1034 resp, err := s.client.Do(req, d)
1035 if err != nil {
1036 return nil, resp, err
1037 }
1038
1039 return d, resp, nil
1040 }
1041
1042
1043
1044
1045
1046
1047 type AddCommitDiscussionNoteOptions struct {
1048 Body *string `url:"body,omitempty" json:"body,omitempty"`
1049 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
1050 }
1051
1052
1053
1054
1055
1056 func (s *DiscussionsService) AddCommitDiscussionNote(pid interface{}, commit string, discussion string, opt *AddCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
1057 project, err := parseID(pid)
1058 if err != nil {
1059 return nil, nil, err
1060 }
1061 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes",
1062 PathEscape(project),
1063 commit,
1064 discussion,
1065 )
1066
1067 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
1068 if err != nil {
1069 return nil, nil, err
1070 }
1071
1072 n := new(Note)
1073 resp, err := s.client.Do(req, n)
1074 if err != nil {
1075 return nil, resp, err
1076 }
1077
1078 return n, resp, nil
1079 }
1080
1081
1082
1083
1084
1085
1086 type UpdateCommitDiscussionNoteOptions struct {
1087 Body *string `url:"body,omitempty" json:"body,omitempty"`
1088 CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
1089 }
1090
1091
1092
1093
1094
1095 func (s *DiscussionsService) UpdateCommitDiscussionNote(pid interface{}, commit string, discussion string, note int, opt *UpdateCommitDiscussionNoteOptions, options ...RequestOptionFunc) (*Note, *Response, error) {
1096 project, err := parseID(pid)
1097 if err != nil {
1098 return nil, nil, err
1099 }
1100 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes/%d",
1101 PathEscape(project),
1102 commit,
1103 discussion,
1104 note,
1105 )
1106
1107 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
1108 if err != nil {
1109 return nil, nil, err
1110 }
1111
1112 n := new(Note)
1113 resp, err := s.client.Do(req, n)
1114 if err != nil {
1115 return nil, resp, err
1116 }
1117
1118 return n, resp, nil
1119 }
1120
1121
1122
1123
1124
1125 func (s *DiscussionsService) DeleteCommitDiscussionNote(pid interface{}, commit string, discussion string, note int, options ...RequestOptionFunc) (*Response, error) {
1126 project, err := parseID(pid)
1127 if err != nil {
1128 return nil, err
1129 }
1130 u := fmt.Sprintf("projects/%s/repository/commits/%s/discussions/%s/notes/%d",
1131 PathEscape(project),
1132 commit,
1133 discussion,
1134 note,
1135 )
1136
1137 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
1138 if err != nil {
1139 return nil, err
1140 }
1141
1142 return s.client.Do(req, nil)
1143 }
1144
View as plain text