2018-11-20 12:59:23 +01:00
|
|
|
package jira
|
|
|
|
|
|
|
|
import (
|
2020-05-03 09:38:32 -04:00
|
|
|
"context"
|
2018-11-20 12:59:23 +01:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// RoleService handles roles for the Jira instance / API.
|
2018-11-20 12:59:23 +01:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-group-Role
|
2018-11-20 12:59:23 +01:00
|
|
|
type RoleService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// Role represents a Jira product role
|
2018-11-20 12:59:23 +01:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// Actor represents a Jira actor
|
2018-11-20 12:59:23 +01:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// GetListWithContext returns a list of all available project roles
|
2018-11-20 14:38:27 +01:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-get
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *RoleService) GetListWithContext(ctx context.Context) (*[]Role, *Response, error) {
|
2018-11-20 12:59:23 +01:00
|
|
|
apiEndpoint := "rest/api/3/role"
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2018-11-20 12:59:23 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-05-03 09:38:32 -04:00
|
|
|
// 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
|
2018-11-20 14:38:27 +01:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-role-id-get
|
2020-05-03 09:38:32 -04:00
|
|
|
func (s *RoleService) GetWithContext(ctx context.Context, roleID int) (*Role, *Response, error) {
|
2018-11-20 12:59:23 +01:00
|
|
|
apiEndpoint := fmt.Sprintf("rest/api/3/role/%d", roleID)
|
2020-05-03 09:38:32 -04:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2018-11-20 12:59:23 +01:00
|
|
|
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
|
|
|
|
}
|
2019-05-09 11:44:39 +02:00
|
|
|
if role.Self == "" {
|
style: Fix staticcheck (static analysis) errors for this library (#283)
* style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)"
staticcheck is a static analysis tool for go.
It reports several "error strings should not be capitalized (ST1005)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)"
staticcheck is a static analysis tool for go.
It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "type X is unused (U1000)"
staticcheck is a static analysis tool for go.
It reports several "type X is unused (U1000)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)"
staticcheck is a static analysis tool for go.
It reports several
- should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003)
- should use strings.EqualFold instead (SA6005)
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)"
staticcheck is a static analysis tool for go.
It report several "unnecessary use of fmt.Sprintf (S1039)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "redundant return statement (S1023)"
staticcheck is a static analysis tool for go.
It report several "redundant return statement (S1023)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)"
staticcheck is a static analysis tool for go.
It report several
file.go:Line:character: possible nil pointer dereference (SA5011)
file.go:Line:character: this check suggests that the pointer can be nil
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
2020-05-02 23:08:01 +02:00
|
|
|
return nil, resp, fmt.Errorf("no role with ID %d found", roleID)
|
2019-05-09 11:44:39 +02:00
|
|
|
}
|
2018-11-20 12:59:23 +01:00
|
|
|
|
|
|
|
return role, resp, err
|
|
|
|
}
|
2020-05-03 09:38:32 -04:00
|
|
|
|
|
|
|
// Get wraps GetWithContext using the background context.
|
|
|
|
func (s *RoleService) Get(roleID int) (*Role, *Response, error) {
|
|
|
|
return s.GetWithContext(context.Background(), roleID)
|
|
|
|
}
|