1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-08-06 22:13:02 +02:00

Add RoleService

Add of RoleService with Get and GetList

Add corresponding tests + mocks
This commit is contained in:
Matthias Weiss
2018-11-20 12:59:23 +01:00
committed by Wes McNamee
parent 7e0dd0ed39
commit 5a7988ae5c
5 changed files with 171 additions and 0 deletions

69
role.go Normal file
View File

@ -0,0 +1,69 @@
package jira
import (
"fmt"
)
// RoleService handles roles for the JIRA instance / API.
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/3/role
type RoleService struct {
client *Client
}
// Role represents a JIRA product role
type Role struct {
Self string `json:"self" structs:"self"`
Name string `json:"name" structs:"name"`
ID int `json:"id" structs:"id"`
Description string `json:"description" structs:"description"`
Actors []*Actor `json:"actors" structs:"actors"`
}
// Actor represents a JIRA user
type Actor struct {
ID int `json:"id" structs:"id"`
DisplayName string `json:"displayName" structs:"displayName"`
Type string `json:"type" structs:"type"`
Name string `json:"name" structs:"name"`
AvatarURL string `json:"avatarUrl" structs:"avatarUrl"`
ActorUser *ActorUser `json:"actorUser" structs:"actoruser"`
}
// ActorUser contains the account id of the actor/user
type ActorUser struct {
AccountID string `json:"accountId" structs:"accountId"`
}
// GetList returns a list of all available project roles
func (s *RoleService) GetList() (*[]Role, *Response, error) {
apiEndpoint := "rest/api/3/role"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
roles := new([]Role)
resp, err := s.client.Do(req, roles)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return roles, resp, err
}
// Get retreives a single Role from Jira
func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/3/role/%d", roleID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
role := new(Role)
resp, err := s.client.Do(req, role)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return role, resp, err
}