@@ -46,6 +46,122 @@ func (s *pullService) List(ctx context.Context, repo string, opts scm.PullReques
46
46
return convertPullRequests (out ), res , err
47
47
}
48
48
49
+ type prCommentInput struct {
50
+ Content struct {
51
+ Raw string `json:"raw,omitempty"`
52
+ } `json:"content"`
53
+ }
54
+
55
+ type pullRequestComments struct {
56
+ pagination
57
+ Values []* prComment `json:"values"`
58
+ }
59
+
60
+ type prComment struct {
61
+ ID int `json:"id"`
62
+ Type string `json:"type"`
63
+ Links struct {
64
+ HTML struct {
65
+ Href string `json:"href"`
66
+ } `json:"html,omitempty"`
67
+ Self struct {
68
+ Href string `json:"href"`
69
+ } `json:"self,omitempty"`
70
+ Code struct {
71
+ Href string `json:"href"`
72
+ } `json:"code,omitempty"`
73
+ } `json:"links"`
74
+ PR struct {
75
+ Title string `json:"title"`
76
+ ID int `json:"id"`
77
+ Type string `json:"type"`
78
+ Links struct {
79
+ HTML struct {
80
+ Href string `json:"href"`
81
+ } `json:"html"`
82
+ Self struct {
83
+ Href string `json:"href"`
84
+ } `json:"self"`
85
+ } `json:"links"`
86
+ } `json:"pullrequest"`
87
+ User struct {
88
+ AccountID string `json:"account_id"`
89
+ DisplayName string `json:"display_name"`
90
+ UUID string `json:"uuid"`
91
+ Type string `json:"type"`
92
+ NickName string `json:"nickname"`
93
+ Links struct {
94
+ HTML struct {
95
+ Href string `json:"href"`
96
+ } `json:"html"`
97
+ Self struct {
98
+ Href string `json:"href"`
99
+ } `json:"self"`
100
+ Avatar struct {
101
+ Href string `json:"href"`
102
+ } `json:"avatar"`
103
+ } `json:"links"`
104
+ } `json:"user"`
105
+ Content struct {
106
+ Raw string `json:"raw"`
107
+ Markup string `json:"markup"`
108
+ HTML string `json:"html"`
109
+ Type string `json:"type"`
110
+ } `json:"content"`
111
+ Inline struct {
112
+ To int `json:"to,omitempty"`
113
+ From int `json:"from,omitempty"`
114
+ Path string `json:"path,omitempty"`
115
+ } `json:"inline,omitempty"`
116
+ Deleted bool `json:"deleted"`
117
+ UpdatedOn time.Time `json:"updated_on"`
118
+ CreatedOn time.Time `json:"created_on"`
119
+ }
120
+
121
+ func convertPRComment (from * prComment ) * scm.Comment {
122
+
123
+ return & scm.Comment {
124
+ ID : from .ID ,
125
+ Body : from .Content .Raw ,
126
+ Author : scm.User {
127
+ Login : from .User .DisplayName ,
128
+ Avatar : from .User .Links .Avatar .Href ,
129
+ },
130
+ Link : from .Links .HTML .Href ,
131
+ Created : from .CreatedOn ,
132
+ Updated : from .UpdatedOn ,
133
+ }
134
+ }
135
+
136
+ func (s * pullService ) CreateComment (ctx context.Context , repo string , number int , input * scm.CommentInput ) (* scm.Comment , * scm.Response , error ) {
137
+ path := fmt .Sprintf ("2.0/repositories/%s/pullrequests/%d/comments" , repo , number )
138
+ in := new (prCommentInput )
139
+ in .Content .Raw = input .Body
140
+ out := new (prComment )
141
+ res , err := s .client .do (ctx , "POST" , path , in , out )
142
+ return convertPRComment (out ), res , err
143
+ }
144
+
145
+ func (s * pullService ) DeleteComment (ctx context.Context , repo string , number , id int ) (* scm.Response , error ) {
146
+ path := fmt .Sprintf ("2.0/repositories/%s/pullrequests/%d/comments/%d" , repo , number , id )
147
+ return s .client .do (ctx , "DELETE" , path , nil , nil )
148
+ }
149
+
150
+ func convertPRCommentList (from * pullRequestComments ) []* scm.Comment {
151
+ to := []* scm.Comment {}
152
+ for _ , v := range from .Values {
153
+ to = append (to , convertPRComment (v ))
154
+ }
155
+ return to
156
+ }
157
+
158
+ func (s * pullService ) ListComments (ctx context.Context , repo string , index int , opts scm.ListOptions ) ([]* scm.Comment , * scm.Response , error ) {
159
+ path := fmt .Sprintf ("2.0/repositories/%s/pullrequests/%d/comments?%s" , repo , index , encodeListOptions (opts ))
160
+ out := new (pullRequestComments )
161
+ res , err := s .client .do (ctx , "GET" , path , nil , & out )
162
+ return convertPRCommentList (out ), res , err
163
+ }
164
+
49
165
func (s * pullService ) ListChanges (ctx context.Context , repo string , number int , opts scm.ListOptions ) ([]* scm.Change , * scm.Response , error ) {
50
166
path := fmt .Sprintf ("2.0/repositories/%s/pullrequests/%d/diffstat?%s" , repo , number , encodeListOptions (opts ))
51
167
out := new (diffstats )
0 commit comments