mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-17 20:47:57 +02:00
Merge pull request #82 from LyonesGamer/update-comment
Add explicit UpdateComment method
This commit is contained in:
commit
1c664343c3
24
issue.go
24
issue.go
@ -646,6 +646,30 @@ func (s *IssueService) AddComment(issueID string, comment *Comment) (*Comment, *
|
||||
return responseComment, resp, nil
|
||||
}
|
||||
|
||||
// UpdateComment updates the body of a comment, identified by comment.ID, on the issueID.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/comment-updateComment
|
||||
func (s *IssueService) UpdateComment(issueID string, comment *Comment) (*Comment, *Response, error) {
|
||||
reqBody := struct {
|
||||
Body string `json:"body"`
|
||||
}{
|
||||
Body: comment.Body,
|
||||
}
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/comment/%s", issueID, comment.ID)
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, reqBody)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
responseComment := new(Comment)
|
||||
resp, err := s.client.Do(req, responseComment)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return responseComment, resp, nil
|
||||
}
|
||||
|
||||
// AddLink adds a link between two issues.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
|
||||
|
@ -153,6 +153,34 @@ func TestIssueService_AddComment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueService_UpdateComment(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/issue/10000/comment/10001", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "POST")
|
||||
testRequestURL(t, r, "/rest/api/2/issue/10000/comment/10001")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/issue/10010/comment/10001","id":"10001","author":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"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.","updateAuthor":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"created":"2016-03-16T04:22:37.356+0000","updated":"2016-03-16T04:22:37.356+0000","visibility":{"type":"role","value":"Administrators"}}`)
|
||||
})
|
||||
|
||||
c := &Comment{
|
||||
ID: "10001",
|
||||
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.",
|
||||
Visibility: CommentVisibility{
|
||||
Type: "role",
|
||||
Value: "Administrators",
|
||||
},
|
||||
}
|
||||
comment, _, err := testClient.Issue.UpdateComment("10000", c)
|
||||
if comment == nil {
|
||||
t.Error("Expected Comment. Comment is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueService_AddLink(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
Loading…
x
Reference in New Issue
Block a user