mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-06 23:16:21 +02:00
Added AddComment to IssueService
This commit is contained in:
parent
bc2f1e8320
commit
f40a31fe85
28
issue.go
28
issue.go
@ -192,6 +192,7 @@ type Comment struct {
|
|||||||
UpdateAuthor Assignee `json:"updateAuthor"`
|
UpdateAuthor Assignee `json:"updateAuthor"`
|
||||||
Updated string `json:"updated"`
|
Updated string `json:"updated"`
|
||||||
Created string `json:"created"`
|
Created string `json:"created"`
|
||||||
|
Visibility CommentVisibility `json:"visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixVersion represents a software release in which an issue is fixed.
|
// FixVersion represents a software release in which an issue is fixed.
|
||||||
@ -206,6 +207,13 @@ type FixVersion struct {
|
|||||||
UserReleaseDate string `json:"userReleaseDate,omitempty"`
|
UserReleaseDate string `json:"userReleaseDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommentVisibility represents he visibility of a comment.
|
||||||
|
// E.g. Type could be "role" and Value "Administrators"
|
||||||
|
type CommentVisibility struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
// Get returns a full representation of the issue for the given issue key.
|
// Get returns a full representation of the issue for the given issue key.
|
||||||
// JIRA will attempt to identify the issue by the issueIdOrKey path parameter.
|
// JIRA will attempt to identify the issue by the issueIdOrKey path parameter.
|
||||||
// This can be an issue id, or an issue key.
|
// This can be an issue id, or an issue key.
|
||||||
@ -249,22 +257,18 @@ func (s *IssueService) Create(issue *Issue) (*Issue, *http.Response, error) {
|
|||||||
return responseIssue, resp, nil
|
return responseIssue, resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IssueService) AddComment(issueID string, comment string) (*Issue, *http.Response, error) {
|
// AddComment adds a new comment to issueID.
|
||||||
|
//
|
||||||
|
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issue-addComment
|
||||||
|
func (s *IssueService) AddComment(issueID string, comment *Comment) (*Comment, *http.Response, error) {
|
||||||
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/comment", issueID)
|
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/comment", issueID)
|
||||||
|
req, err := s.client.NewRequest("POST", apiEndpoint, comment)
|
||||||
type CommentBody struct {
|
|
||||||
Body string `json:"body"`
|
|
||||||
}
|
|
||||||
|
|
||||||
params := CommentBody{Body: comment}
|
|
||||||
|
|
||||||
req, err := s.client.NewRequest("POST", apiEndpoint, params)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
responseIssue := new(Issue)
|
responseComment := new(Comment)
|
||||||
resp, _ := s.client.Do(req, responseIssue)
|
resp, _ := s.client.Do(req, responseComment)
|
||||||
|
|
||||||
return responseIssue, resp, nil
|
return responseComment, resp, nil
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ func TestIssueGet_Success(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssueCreate_Success(t *testing.T) {
|
func TestIssueCreate(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
testMux.HandleFunc("/rest/api/2/issue/", func(w http.ResponseWriter, r *http.Request) {
|
testMux.HandleFunc("/rest/api/2/issue/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -49,3 +49,30 @@ func TestIssueCreate_Success(t *testing.T) {
|
|||||||
t.Error("Error given: %s", err)
|
t.Error("Error given: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssueAddComment(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
testMux.HandleFunc("/rest/api/2/issue/10000/comment", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
testMethod(t, r, "POST")
|
||||||
|
testRequestURL(t, r, "/rest/api/2/issue/10000/comment")
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/issue/10010/comment/10000","id":"10000","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{
|
||||||
|
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.AddComment("10000", c)
|
||||||
|
if comment == nil {
|
||||||
|
t.Errorf("Expected Comment. Comment is nil")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error given: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user