Skip to content

Commit 343e899

Browse files
authored
Add ability to add PR comments (#161)
1 parent ed05dc5 commit 343e899

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

bitbucket.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ type PullRequestsOptions struct {
276276
Sort string `json:"sort"`
277277
}
278278

279+
type PullRequestCommentOptions struct {
280+
Owner string `json:"owner"`
281+
RepoSlug string `json:"repo_slug"`
282+
PullRequestID string `json:"id"`
283+
Content string `json:"content"`
284+
}
285+
279286
type IssuesOptions struct {
280287
ID string `json:"id"`
281288
Owner string `json:"owner"`

pullrequests.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ func (p *PullRequests) UnRequestChanges(po *PullRequestsOptions) (interface{}, e
127127
return p.c.execute("DELETE", urlStr, "")
128128
}
129129

130+
func (p *PullRequests) AddComment(co *PullRequestCommentOptions) (interface{}, error) {
131+
data, err := p.buildPullRequestCommentBody(co)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
urlStr := p.c.requestUrl("/repositories/%s/%s/pullrequests/%s/comments", co.Owner, co.RepoSlug, co.PullRequestID)
137+
return p.c.execute("POST", urlStr, data)
138+
}
139+
130140
func (p *PullRequests) GetComments(po *PullRequestsOptions) (interface{}, error) {
131141
urlStr := p.c.GetApiBaseURL() + "/repositories/" + po.Owner + "/" + po.RepoSlug + "/pullrequests/" + po.ID + "/comments/"
132142
return p.c.execute("GET", urlStr, "")
@@ -221,3 +231,17 @@ func (p *PullRequests) buildPullRequestBody(po *PullRequestsOptions) string {
221231

222232
return string(data)
223233
}
234+
235+
func (p *PullRequests) buildPullRequestCommentBody(co *PullRequestCommentOptions) (string, error) {
236+
body := map[string]interface{}{}
237+
body["content"] = map[string]interface{}{
238+
"raw": co.Content,
239+
}
240+
241+
data, err := json.Marshal(body)
242+
if err != nil {
243+
return "", err
244+
}
245+
246+
return string(data), nil
247+
}

0 commit comments

Comments
 (0)