mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-01-05 22:53:53 +02:00
Merge pull request #107 from robiball/add_worklog_methods
Added method & tests for logging time against an issue
This commit is contained in:
commit
0bb8204adc
43
issue.go
43
issue.go
@ -387,19 +387,18 @@ type Worklog struct {
|
||||
|
||||
// WorklogRecord represents one entry of a Worklog
|
||||
type WorklogRecord struct {
|
||||
Self string `json:"self" structs:"self"`
|
||||
Author User `json:"author" structs:"author"`
|
||||
UpdateAuthor User `json:"updateAuthor" structs:"updateAuthor"`
|
||||
Comment string `json:"comment" structs:"comment"`
|
||||
Created Time `json:"created" structs:"created"`
|
||||
Updated Time `json:"updated" structs:"updated"`
|
||||
Started Time `json:"started" structs:"started"`
|
||||
TimeSpent string `json:"timeSpent" structs:"timeSpent"`
|
||||
TimeSpentSeconds int `json:"timeSpentSeconds" structs:"timeSpentSeconds"`
|
||||
ID string `json:"id" structs:"id"`
|
||||
IssueID string `json:"issueId" structs:"issueId"`
|
||||
Self string `json:"self,omitempty" structs:"self,omitempty"`
|
||||
Author *User `json:"author,omitempty" structs:"author,omitempty"`
|
||||
UpdateAuthor *User `json:"updateAuthor,omitempty" structs:"updateAuthor,omitempty"`
|
||||
Comment string `json:"comment,omitempty" structs:"comment,omitempty"`
|
||||
Created *Time `json:"created,omitempty" structs:"created,omitempty"`
|
||||
Updated *Time `json:"updated,omitempty" structs:"updated,omitempty"`
|
||||
Started *Time `json:"started,omitempty" structs:"started,omitempty"`
|
||||
TimeSpent string `json:"timeSpent,omitempty" structs:"timeSpent,omitempty"`
|
||||
TimeSpentSeconds int `json:"timeSpentSeconds,omitempty" structs:"timeSpentSeconds,omitempty"`
|
||||
ID string `json:"id,omitempty" structs:"id,omitempty"`
|
||||
IssueID string `json:"issueId,omitempty" structs:"issueId,omitempty"`
|
||||
}
|
||||
|
||||
// TimeTracking represents the timetracking fields of a JIRA issue.
|
||||
type TimeTracking struct {
|
||||
OriginalEstimate string `json:"originalEstimate,omitempty" structs:"originalEstimate,omitempty"`
|
||||
@ -738,6 +737,26 @@ func (s *IssueService) UpdateComment(issueID string, comment *Comment) (*Comment
|
||||
return responseComment, resp, nil
|
||||
}
|
||||
|
||||
// AddWorklogRecord adds a new worklog record to issueID.
|
||||
//
|
||||
// https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-worklog-post
|
||||
func (s *IssueService) AddWorklogRecord(issueID string, record *WorklogRecord) (*WorklogRecord, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s/worklog", issueID)
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, record)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
responseRecord := new(WorklogRecord)
|
||||
resp, err := s.client.Do(req, responseRecord)
|
||||
if err != nil {
|
||||
jerr := NewJiraError(resp, err)
|
||||
return nil, resp, jerr
|
||||
}
|
||||
|
||||
return responseRecord, resp, nil
|
||||
}
|
||||
|
||||
// AddLink adds a link between two issues.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/issueLink
|
||||
|
@ -181,6 +181,28 @@ func TestIssueService_UpdateComment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueService_AddWorklogRecord(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/issue/10000/worklog", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "POST")
|
||||
testRequestURL(t, r, "/rest/api/2/issue/10000/worklog")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000","author":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"updateAuthor":{"self":"http://www.example.com/jira/rest/api/2/user?username=fred","name":"fred","displayName":"Fred F. User","active":false},"comment":"I did some work here.","updated":"2018-02-14T22:14:46.003+0000","visibility":{"type":"group","value":"jira-developers"},"started":"2018-02-14T22:14:46.003+0000","timeSpent":"3h 20m","timeSpentSeconds":12000,"id":"100028","issueId":"10002"}`)
|
||||
})
|
||||
r := &WorklogRecord{
|
||||
TimeSpent: "1h",
|
||||
}
|
||||
record, _, err := testClient.Issue.AddWorklogRecord("10000", r)
|
||||
if record == nil {
|
||||
t.Error("Expected Record. Record is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueService_AddLink(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
Loading…
Reference in New Issue
Block a user