mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-01-03 22:52:17 +02:00
Merge pull request #119 from zenixls2/master
add Sprint column for issue. Fix get group member function to return all members.
This commit is contained in:
commit
7f227a275b
42
group.go
42
group.go
@ -2,6 +2,7 @@ package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GroupService handles Groups for the JIRA instance / API.
|
||||
@ -48,13 +49,21 @@ type GroupMember struct {
|
||||
TimeZone string `json:"timeZone,omitempty"`
|
||||
}
|
||||
|
||||
type GroupSearchOptions struct {
|
||||
StartAt int
|
||||
MaxResults int
|
||||
IncludeInactiveUsers bool
|
||||
}
|
||||
|
||||
// Get returns a paginated list of users who are members of the specified group and its subgroups.
|
||||
// Users in the page are ordered by user names.
|
||||
// User of this resource is required to have sysadmin or admin permissions.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup
|
||||
//
|
||||
// WARNING: This API only returns the first page of group members
|
||||
func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/group/member?groupname=%s", name)
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name))
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -69,6 +78,37 @@ func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
|
||||
return group.Members, resp, nil
|
||||
}
|
||||
|
||||
// Get returns a paginated list of members of the specified group and its subgroups.
|
||||
// Users in the page are ordered by user names.
|
||||
// User of this resource is required to have sysadmin or admin permissions.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup
|
||||
func (s *GroupService) GetWithOptions(name string, options *GroupSearchOptions) ([]GroupMember, *Response, error) {
|
||||
var apiEndpoint string
|
||||
if options == nil {
|
||||
apiEndpoint = fmt.Sprintf("/rest/api/2/group/member?groupname=%s", url.QueryEscape(name))
|
||||
} else {
|
||||
apiEndpoint = fmt.Sprintf(
|
||||
"/rest/api/2/group/member?groupname=%s&startAt=%d&maxResults=%d&includeInactiveUsers=%t",
|
||||
url.QueryEscape(name),
|
||||
options.StartAt,
|
||||
options.MaxResults,
|
||||
options.IncludeInactiveUsers,
|
||||
)
|
||||
}
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
group := new(groupMembersResult)
|
||||
resp, err := s.client.Do(req, group)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return group.Members, resp, nil
|
||||
}
|
||||
|
||||
// Add adds user to group
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup
|
||||
|
@ -21,6 +21,61 @@ func TestGroupService_Get(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupService_GetPage(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/group/member", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, "/rest/api/2/group/member?groupname=default")
|
||||
startAt := r.URL.Query().Get("startAt")
|
||||
if startAt == "0" {
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=0","nextPage":"`+testServer.URL+`/rest/api/2/group/member?groupname=default&includeInactiveUsers=false&maxResults=2&startAt=2","maxResults":2,"startAt":0,"total":4,"isLast":false,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
} else if startAt == "2" {
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=2","maxResults":2,"startAt":2,"total":4,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
} else {
|
||||
t.Errorf("startAt %s", startAt)
|
||||
}
|
||||
})
|
||||
if page, resp, err := testClient.Group.GetWithOptions("default", &GroupSearchOptions{
|
||||
StartAt: 0,
|
||||
MaxResults: 2,
|
||||
IncludeInactiveUsers: false,
|
||||
}); err != nil {
|
||||
t.Errorf("Error given: %s %s", err, testServer.URL)
|
||||
} else if page == nil || len(page) != 2 {
|
||||
t.Error("Expected members. Group.Members is not 2 or is nil")
|
||||
} else {
|
||||
if resp.StartAt != 0 {
|
||||
t.Errorf("Expect Result StartAt to be 0, but is %d", resp.StartAt)
|
||||
}
|
||||
if resp.MaxResults != 2 {
|
||||
t.Errorf("Expect Result MaxResults to be 2, but is %d", resp.MaxResults)
|
||||
}
|
||||
if resp.Total != 4 {
|
||||
t.Errorf("Expect Result Total to be 4, but is %d", resp.Total)
|
||||
}
|
||||
if page, resp, err := testClient.Group.GetWithOptions("default", &GroupSearchOptions{
|
||||
StartAt: 2,
|
||||
MaxResults: 2,
|
||||
IncludeInactiveUsers: false,
|
||||
}); err != nil {
|
||||
t.Errorf("Error give: %s %s", err, testServer.URL)
|
||||
} else if page == nil || len(page) != 2 {
|
||||
t.Error("Expected members. Group.Members is not 2 or is nil")
|
||||
} else {
|
||||
if resp.StartAt != 2 {
|
||||
t.Errorf("Expect Result StartAt to be 2, but is %d", resp.StartAt)
|
||||
}
|
||||
if resp.MaxResults != 2 {
|
||||
t.Errorf("Expect Result MaxResults to be 2, but is %d", resp.MaxResults)
|
||||
}
|
||||
if resp.Total != 4 {
|
||||
t.Errorf("Expect Result Total to be 4, but is %d", resp.Total)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupService_Add(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
1
issue.go
1
issue.go
@ -127,6 +127,7 @@ type IssueFields struct {
|
||||
Subtasks []*Subtasks `json:"subtasks,omitempty" structs:"subtasks,omitempty"`
|
||||
Attachments []*Attachment `json:"attachment,omitempty" structs:"attachment,omitempty"`
|
||||
Epic *Epic `json:"epic,omitempty" structs:"epic,omitempty"`
|
||||
Sprint *Sprint `json:"sprint,omitempty" structs:"sprint,omitempty"`
|
||||
Parent *Parent `json:"parent,omitempty" structs:"parent,omitempty"`
|
||||
Unknowns tcontainer.MarshalMap
|
||||
}
|
||||
|
4
jira.go
4
jira.go
@ -280,6 +280,10 @@ func (r *Response) populatePageValues(v interface{}) {
|
||||
r.StartAt = value.StartAt
|
||||
r.MaxResults = value.MaxResults
|
||||
r.Total = value.Total
|
||||
case *groupMembersResult:
|
||||
r.StartAt = value.StartAt
|
||||
r.MaxResults = value.MaxResults
|
||||
r.Total = value.Total
|
||||
}
|
||||
return
|
||||
}
|
||||
|
39
sprint.go
39
sprint.go
@ -2,6 +2,7 @@ package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/go-querystring/query"
|
||||
)
|
||||
|
||||
// SprintService handles sprints in JIRA Agile API.
|
||||
@ -65,3 +66,41 @@ func (s *SprintService) GetIssuesForSprint(sprintID int) ([]Issue, *Response, er
|
||||
|
||||
return result.Issues, resp, err
|
||||
}
|
||||
|
||||
// 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.
|
||||
// This can be an issue id, or an issue key.
|
||||
// If the issue cannot be found via an exact match, JIRA will also look for the issue in a case-insensitive way, or by looking to see if the issue was moved.
|
||||
//
|
||||
// The given options will be appended to the query string
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/issue-getIssue
|
||||
//
|
||||
// TODO: create agile service for holding all agile apis' implementation
|
||||
func (s *SprintService) GetIssue(issueID string, options *GetQueryOptions) (*Issue, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/agile/1.0/issue/%s", issueID)
|
||||
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
q, err := query.Values(options)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req.URL.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
issue := new(Issue)
|
||||
resp, err := s.client.Do(req, issue)
|
||||
|
||||
if err != nil {
|
||||
jerr := NewJiraError(resp, err)
|
||||
return nil, resp, jerr
|
||||
}
|
||||
|
||||
return issue, resp, nil
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user