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
84
issue.go
84
issue.go
@ -44,26 +44,26 @@ type IssueFields struct {
|
|||||||
// * "subtasks": [],
|
// * "subtasks": [],
|
||||||
// * "environment": null,
|
// * "environment": null,
|
||||||
// * "duedate": null,
|
// * "duedate": null,
|
||||||
Type IssueType `json:"issuetype"`
|
Type IssueType `json:"issuetype"`
|
||||||
Project Project `json:"project,omitempty"`
|
Project Project `json:"project,omitempty"`
|
||||||
Resolution *Resolution `json:"resolution,omitempty"`
|
Resolution *Resolution `json:"resolution,omitempty"`
|
||||||
Priority *Priority `json:"priority,omitempty"`
|
Priority *Priority `json:"priority,omitempty"`
|
||||||
Resolutiondate string `json:"resolutiondate,omitempty"`
|
Resolutiondate string `json:"resolutiondate,omitempty"`
|
||||||
Created string `json:"created,omitempty"`
|
Created string `json:"created,omitempty"`
|
||||||
Watches *Watches `json:"watches,omitempty"`
|
Watches *Watches `json:"watches,omitempty"`
|
||||||
Assignee *Assignee `json:"assignee,omitempty"`
|
Assignee *Assignee `json:"assignee,omitempty"`
|
||||||
Updated int `json:"updated,omitempty"`
|
Updated int `json:"updated,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
Creator *Assignee `json:"Creator,omitempty"`
|
Creator *Assignee `json:"Creator,omitempty"`
|
||||||
Reporter *Assignee `json:"reporter,omitempty"`
|
Reporter *Assignee `json:"reporter,omitempty"`
|
||||||
Components []*Component `json:"components,omitempty"`
|
Components []*Component `json:"components,omitempty"`
|
||||||
Status *Status `json:"status,omitempty"`
|
Status *Status `json:"status,omitempty"`
|
||||||
Progress *Progress `json:"progress,omitempty"`
|
Progress *Progress `json:"progress,omitempty"`
|
||||||
AggregateProgress *Progress `json:"aggregateprogress,omitempty"`
|
AggregateProgress *Progress `json:"aggregateprogress,omitempty"`
|
||||||
Worklog []*Worklog `json:"worklog,omitempty"`
|
Worklog []*Worklog `json:"worklog,omitempty"`
|
||||||
IssueLinks []*IssueLink `json:"issuelinks,omitempty"`
|
IssueLinks []*IssueLink `json:"issuelinks,omitempty"`
|
||||||
Comments []*Comment `json:"comment,omitempty"`
|
Comments []*Comment `json:"comment,omitempty"`
|
||||||
FixVersions []*FixVersion `json:"fixVersions,omitempty"`
|
FixVersions []*FixVersion `json:"fixVersions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,13 +185,14 @@ type IssueLinkType struct {
|
|||||||
|
|
||||||
// Comment represents a comment by a person to an issue in JIRA.
|
// Comment represents a comment by a person to an issue in JIRA.
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
Self string `json:"self"`
|
Self string `json:"self"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Author Assignee `json:"author"`
|
Author Assignee `json:"author"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
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