forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.go
87 lines (77 loc) · 2.68 KB
/
role.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package jira
import (
"context"
"fmt"
)
// RoleService handles roles for the Jira instance / API.
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-group-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 actor
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"`
}
// GetListWithContext returns a list of all available project roles
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-get
func (s *RoleService) GetListWithContext(ctx context.Context) (*[]Role, *Response, error) {
apiEndpoint := "rest/api/3/role"
req, err := s.client.NewRequestWithContext(ctx, "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
}
// GetList wraps GetListWithContext using the background context.
func (s *RoleService) GetList() (*[]Role, *Response, error) {
return s.GetListWithContext(context.Background())
}
// GetWithContext retreives a single Role from Jira
//
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-id-get
func (s *RoleService) GetWithContext(ctx context.Context, roleID int) (*Role, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/3/role/%d", roleID)
req, err := s.client.NewRequestWithContext(ctx, "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
}
if role.Self == "" {
return nil, resp, fmt.Errorf("no role with ID %d found", roleID)
}
return role, resp, err
}
// Get wraps GetWithContext using the background context.
func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
return s.GetWithContext(context.Background(), roleID)
}