mirror of
https://github.com/interviewstreet/go-jira.git
synced 2024-11-24 08:22:42 +02:00
Added basic version of Group API (Thanks to @aviz)
This commit is contained in:
parent
fddc90f9f2
commit
8a4b1aca33
53
group.go
Normal file
53
group.go
Normal file
@ -0,0 +1,53 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GroupService handles Groups for the JIRA instance / API.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group
|
||||
type GroupService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// groupMembersResult is only a small wrapper around the Group* methods
|
||||
// to be able to parse the results
|
||||
type groupMembersResult struct {
|
||||
StartAt int `json:"startAt"`
|
||||
MaxResults int `json:"maxResults"`
|
||||
Total int `json:"total"`
|
||||
Members []GroupMember `json:"values"`
|
||||
}
|
||||
|
||||
// GroupMember reflects a single member of a group
|
||||
type GroupMember struct {
|
||||
Self string `json:"self,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
EmailAddress string `json:"emailAddress,omitempty"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
TimeZone string `json:"timeZone,omitempty"`
|
||||
}
|
||||
|
||||
// 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
|
||||
func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/group/member?groupname=%s", name)
|
||||
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
|
||||
}
|
2
issue.go
2
issue.go
@ -438,7 +438,7 @@ type SearchOptions struct {
|
||||
Expand string `url:expand,omitempty"`
|
||||
}
|
||||
|
||||
// searchResult is only a small wrapper arround the Search (with JQL) method
|
||||
// searchResult is only a small wrapper around the Search (with JQL) method
|
||||
// to be able to parse the results
|
||||
type searchResult struct {
|
||||
Issues []Issue `json:"issues" structs:"issues"`
|
||||
|
2
jira.go
2
jira.go
@ -30,6 +30,7 @@ type Client struct {
|
||||
Board *BoardService
|
||||
Sprint *SprintService
|
||||
User *UserService
|
||||
Group *GroupService
|
||||
}
|
||||
|
||||
// NewClient returns a new JIRA API client.
|
||||
@ -59,6 +60,7 @@ func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
|
||||
c.Board = &BoardService{client: c}
|
||||
c.Sprint = &SprintService{client: c}
|
||||
c.User = &UserService{client: c}
|
||||
c.Group = &GroupService{client: c}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -106,6 +106,12 @@ func TestNewClient_WithServices(t *testing.T) {
|
||||
if c.Sprint == nil {
|
||||
t.Error("No SprintService provided")
|
||||
}
|
||||
if c.User == nil {
|
||||
t.Error("No UserService provided")
|
||||
}
|
||||
if c.Group == nil {
|
||||
t.Error("No GroupService provided")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckResponse(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user