From fe70b5c8368815658150ceed7b1dd070b9fa2436 Mon Sep 17 00:00:00 2001 From: attack7 Date: Tue, 26 Jul 2016 16:18:58 -0400 Subject: [PATCH 1/3] Add the ability to get all issues in a sprint --- mocks/issues_in_sprint.json | 115 ++++++++++++++++++++++++++++++++++++ sprint.go | 22 +++++++ sprint_test.go | 30 ++++++++++ 3 files changed, 167 insertions(+) create mode 100644 mocks/issues_in_sprint.json diff --git a/mocks/issues_in_sprint.json b/mocks/issues_in_sprint.json new file mode 100644 index 0000000..adc42bc --- /dev/null +++ b/mocks/issues_in_sprint.json @@ -0,0 +1,115 @@ +{ + "expand": "schema,names", + "startAt": 0, + "maxResults": 50, + "total": 10, + "issues": [ + { + "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields", + "id": "12338", + "self": "https://example.atlassian.net/rest/agile/1.0/issue/12338", + "key": "AR-86", + "fields": { + "issuetype": { + "self": "https://example.atlassian.net/rest/api/2/issuetype/3", + "id": "3", + "description": "A task that needs to be done.", + "iconUrl": "https://example.atlassian.net/secure/viewavatar?size=xsmall&avatarId=10418&avatarType=issuetype", + "name": "Task", + "subtask": false, + "avatarId": 10418 + }, + "timespent": null, + "project": { + "self": "https://example.atlassian.net/rest/api/2/project/10302", + "id": "10302", + "key": "AR", + "name": "Team Argon", + "avatarUrls": { + "48x48": "https://example.atlassian.net/secure/projectavatar?pid=10302&avatarId=10610", + "24x24": "https://example.atlassian.net/secure/projectavatar?size=small&pid=10302&avatarId=10610", + "16x16": "https://example.atlassian.net/secure/projectavatar?size=xsmall&pid=10302&avatarId=10610", + "32x32": "https://example.atlassian.net/secure/projectavatar?size=medium&pid=10302&avatarId=10610" + } + }, + "fixVersions": [], + "customfield_11200": "0|0zzzzd:vi", + "aggregatetimespent": null, + "resolution": { + "self": "https://example.atlassian.net/rest/api/2/resolution/6", + "id": "6", + "description": "", + "name": "Done" + }, + "customfield_11401": null, + "customfield_11400": null, + "customfield_10105": 13.0, + "customfield_10700": "AR-37", + "resolutiondate": "2015-12-07T14:19:13.000-0800", + "workratio": -1, + "lastViewed": null, + "watches": { + "self": "https://example.atlassian.net/rest/api/2/issue/AR-86/watchers", + "watchCount": 2, + "isWatching": true + }, + "created": "2015-12-02T07:39:15.000-0800", + "epic": { + "id": 11900, + "key": "AR-37", + "self": "https://example.atlassian.net/rest/agile/1.0/epic/11900", + "name": "Moderation: Design", + "summary": "Moderation design", + "color": { + "key": "color_8" + }, + "done": true + }, + "priority": { + "self": "https://example.atlassian.net/rest/api/2/priority/3", + "iconUrl": "https://example.atlassian.net/images/icons/priorities/major.svg", + "name": "Major", + "id": "3" + }, + "customfield_10102": null, + "customfield_10103": null, + "labels": [], + "customfield_11700": null, + "timeestimate": null, + "aggregatetimeoriginalestimate": null, + "versions": [], + "issuelinks": [], + "assignee": { + "self": "https://example.atlassian.net/rest/api/2/user?username=mister.morris", + "name": "mister.morris", + "key": "mister.morris", + "emailAddress": "mister.morris@uservoice.com", + "avatarUrls": { + "48x48": "https://example.atlassian.net/secure/useravatar?ownerId=mister.morris&avatarId=10604", + "24x24": "https://example.atlassian.net/secure/useravatar?size=small&ownerId=mister.morris&avatarId=10604", + "16x16": "https://example.atlassian.net/secure/useravatar?size=xsmall&ownerId=mister.morris&avatarId=10604", + "32x32": "https://example.atlassian.net/secure/useravatar?size=medium&ownerId=mister.morris&avatarId=10604" + }, + "displayName": "mister Morris", + "active": true, + "timeZone": "America/New_York" + }, + "updated": "2016-02-01T08:17:04.000-0800", + "status": { + "self": "https://example.atlassian.net/rest/api/2/status/10000", + "description": "Ready to move to dev team for grooming", + "iconUrl": "https://example.atlassian.net/images/icons/statuses/closed.png", + "name": "Ready", + "id": "10000", + "statusCategory": { + "self": "https://example.atlassian.net/rest/api/2/statuscategory/2", + "id": 2, + "key": "new", + "colorName": "blue-gray", + "name": "To Do" + } + } + } + } + ] +} \ No newline at end of file diff --git a/sprint.go b/sprint.go index a2f7877..4b6f85f 100644 --- a/sprint.go +++ b/sprint.go @@ -15,6 +15,11 @@ type IssuesWrapper struct { Issues []string `json:"issues"` } +// Wrapper struct for search result +type IssuesInSprintResult struct { + Issues []Issue `json:"issues"` +} + // MoveIssuesToSprint moves issues to a sprint, for a given sprint Id. // Issues can only be moved to open or active sprints. // The maximum number of issues that can be moved in one operation is 50. @@ -34,3 +39,20 @@ func (s *SprintService) MoveIssuesToSprint(sprintID int, issueIDs []string) (*Re resp, err := s.client.Do(req, nil) return resp, err } + +// For a given sprint Id, return all issues currently associated with that sprint +// +// JIRA API Docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint-getIssuesForSprint +func (s *SprintService) GetIssuesInSprint(sprintID int) ([]Issue, *Response, error) { + apiEndpoint := fmt.Sprintf("rest/agile/1.0/sprint/%d/issue", sprintID) + + req, err := s.client.NewRequest("GET", apiEndpoint, nil) + + if err != nil { + return nil, nil, err + } + + result := new(IssuesInSprintResult) + resp, err := s.client.Do(req, result) + return result.Issues, resp, err +} diff --git a/sprint_test.go b/sprint_test.go index 8045b79..c2cf988 100644 --- a/sprint_test.go +++ b/sprint_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "net/http" "testing" + "io/ioutil" + "fmt" ) func TestSprintService_MoveIssuesToSprint(t *testing.T) { @@ -35,3 +37,31 @@ func TestSprintService_MoveIssuesToSprint(t *testing.T) { t.Errorf("Got error: %v", err) } } + +func TestSprintService_GetIssuesInSprint(t *testing.T) { + setup() + defer teardown() + testAPIEdpoint := "/rest/agile/1.0/sprint/123/issue" + + raw, err := ioutil.ReadFile("./mocks/issues_in_sprint.json") + if err != nil { + t.Error(err.Error()) + } + testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testRequestURL(t, r, testAPIEdpoint) + fmt.Fprint(w, string(raw)) + }) + + issues, _, err := testClient.Sprint.GetIssuesInSprint(123) + if err != nil { + t.Errorf("Error given: %v", err) + } + if issues == nil { + t.Error("Expected issues in sprint list. Issues list is nil") + } + if len(issues) != 1 { + t.Errorf("Expect there to be 1 issue in the sprint, found %v", len(issues)) + } + +} From 5a0fb0ba05780b13b7bda5bb1ccee86f16455ed5 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Fri, 29 Jul 2016 19:43:34 +0200 Subject: [PATCH 2/3] Renamed API method to (like JIRA API) and fixed `go doc` --- sprint.go | 10 ++++++---- sprint_test.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sprint.go b/sprint.go index 4b6f85f..a101eb9 100644 --- a/sprint.go +++ b/sprint.go @@ -15,7 +15,7 @@ type IssuesWrapper struct { Issues []string `json:"issues"` } -// Wrapper struct for search result +// IssuesInSprintResult represents a wrapper struct for search result type IssuesInSprintResult struct { Issues []Issue `json:"issues"` } @@ -40,10 +40,12 @@ func (s *SprintService) MoveIssuesToSprint(sprintID int, issueIDs []string) (*Re return resp, err } -// For a given sprint Id, return all issues currently associated with that sprint +// GetIssuesForSprint returns all issues in a sprint, for a given sprint Id. +// This only includes issues that the user has permission to view. +// By default, the returned issues are ordered by rank. // -// JIRA API Docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board/{boardId}/sprint-getIssuesForSprint -func (s *SprintService) GetIssuesInSprint(sprintID int) ([]Issue, *Response, error) { +// JIRA API Docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/sprint-getIssuesForSprint +func (s *SprintService) GetIssuesForSprint(sprintID int) ([]Issue, *Response, error) { apiEndpoint := fmt.Sprintf("rest/agile/1.0/sprint/%d/issue", sprintID) req, err := s.client.NewRequest("GET", apiEndpoint, nil) diff --git a/sprint_test.go b/sprint_test.go index c2cf988..317e6be 100644 --- a/sprint_test.go +++ b/sprint_test.go @@ -38,7 +38,7 @@ func TestSprintService_MoveIssuesToSprint(t *testing.T) { } } -func TestSprintService_GetIssuesInSprint(t *testing.T) { +func TestSprintService_GetIssuesForSprint(t *testing.T) { setup() defer teardown() testAPIEdpoint := "/rest/agile/1.0/sprint/123/issue" @@ -53,7 +53,7 @@ func TestSprintService_GetIssuesInSprint(t *testing.T) { fmt.Fprint(w, string(raw)) }) - issues, _, err := testClient.Sprint.GetIssuesInSprint(123) + issues, _, err := testClient.Sprint.GetIssuesForSprint(123) if err != nil { t.Errorf("Error given: %v", err) } From ecc4b0986407a80e0f3851b200772e770752a913 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Fri, 29 Jul 2016 19:45:03 +0200 Subject: [PATCH 3/3] go fmt --- sprint_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sprint_test.go b/sprint_test.go index 317e6be..40f0546 100644 --- a/sprint_test.go +++ b/sprint_test.go @@ -2,10 +2,10 @@ package jira import ( "encoding/json" + "fmt" + "io/ioutil" "net/http" "testing" - "io/ioutil" - "fmt" ) func TestSprintService_MoveIssuesToSprint(t *testing.T) {