Skip to content

Commit e6abbe6

Browse files
use Comment type as argument instead io.Reader in UpdateComment function
1 parent 6a18de9 commit e6abbe6

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

README.md

+21-9
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,28 @@ if err != nil {
8080
os.Exit(1)
8181
}
8282
// Prepare comment
83-
var b = []byte(`{
84-
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
85-
"visibility": {
86-
"type": "role",
87-
"value": "Administrators"
88-
}
89-
}`)
90-
newComment := bytes.NewBuffer(b)
91-
comment, err := issue.SetComments(newComment)
83+
newComment := &gojira.Comment{Body: "test comment"}
84+
85+
comment, err := issue.SetComment(newComment)
86+
if err != nil {
87+
fmt.Printf("%s\n", err)
88+
os.Exit(1)
89+
}
90+
```
91+
92+
#### Update existing comment in issue
93+
9294
// You also may use UpdateComment(id int, comment io.Reader) to update exist comment by id
95+
```go
96+
issue, err := gojira.GetIssue("TEST-123")
97+
if err != nil {
98+
fmt.Printf("%s\n", err)
99+
os.Exit(1)
100+
}
101+
// Prepare comment
102+
newComment := &gojira.Comment{Body: "test comment"}
103+
104+
comment, err := issue.UpdateComment(123456, newComment)
93105
if err != nil {
94106
fmt.Printf("%s\n", err)
95107
os.Exit(1)

issue.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,15 @@ func (issue *Issue) SetComment(comment *Comment) (*Comment, error) {
247247

248248
// UpdateComment - update existing comment by id
249249
func (issue *Issue) UpdateComment(
250-
id int, comment io.Reader,
250+
id int, comment *Comment,
251251
) (*Comment, error) {
252+
252253
url := fmt.Sprintf("%s/issue/%s/comment/%d", BaseURL, issue.Key, id)
253-
code, body := execRequest("PUT", url, comment)
254+
encodedParams, err := json.Marshal(comment)
255+
if err != nil {
256+
return nil, err
257+
}
258+
code, body := execRequest("PUT", url, bytes.NewBuffer(encodedParams))
254259
if code == http.StatusOK {
255260
var jiraComment Comment
256261
err := json.Unmarshal(body, &jiraComment)

0 commit comments

Comments
 (0)