mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Bump version to 5.11.0
This commit is contained in:
parent
a32510b8e6
commit
510e1bd0bd
370 changed files with 18825 additions and 5454 deletions
157
vendor/github.com/andygrunwald/go-jira/user.go
generated
vendored
157
vendor/github.com/andygrunwald/go-jira/user.go
generated
vendored
|
@ -1,25 +1,24 @@
|
|||
package jira
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// UserService handles users for the JIRA instance / API.
|
||||
// UserService handles users for the Jira instance / API.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-group-Users
|
||||
type UserService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// User represents a JIRA user.
|
||||
// User represents a Jira user.
|
||||
type User struct {
|
||||
Self string `json:"self,omitempty" structs:"self,omitempty"`
|
||||
AccountID string `json:"accountId,omitempty" structs:"accountId,omitempty"`
|
||||
AccountType string `json:"accountType,omitempty" structs:"accountType,omitempty"`
|
||||
// TODO: name & key are deprecated, see:
|
||||
// https://developer.atlassian.com/cloud/jira/platform/api-changes-for-user-privacy-announcement/
|
||||
Self string `json:"self,omitempty" structs:"self,omitempty"`
|
||||
AccountID string `json:"accountId,omitempty" structs:"accountId,omitempty"`
|
||||
AccountType string `json:"accountType,omitempty" structs:"accountType,omitempty"`
|
||||
Name string `json:"name,omitempty" structs:"name,omitempty"`
|
||||
Key string `json:"key,omitempty" structs:"key,omitempty"`
|
||||
Password string `json:"-"`
|
||||
|
@ -47,12 +46,12 @@ type userSearch []userSearchParam
|
|||
|
||||
type userSearchF func(userSearch) userSearch
|
||||
|
||||
// Get gets user info from JIRA
|
||||
// GetWithContext gets user info from Jira using its Account Id
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-getUser
|
||||
func (s *UserService) Get(username string) (*User, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user?username=%s", username)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-user-get
|
||||
func (s *UserService) GetWithContext(ctx context.Context, accountId string) (*User, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user?accountId=%s", accountId)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -65,12 +64,41 @@ func (s *UserService) Get(username string) (*User, *Response, error) {
|
|||
return user, resp, nil
|
||||
}
|
||||
|
||||
// Create creates an user in JIRA.
|
||||
// Get wraps GetWithContext using the background context.
|
||||
func (s *UserService) Get(accountId string) (*User, *Response, error) {
|
||||
return s.GetWithContext(context.Background(), accountId)
|
||||
}
|
||||
|
||||
// GetByAccountIDWithContext gets user info from Jira
|
||||
// Searching by another parameter that is not accountId is deprecated,
|
||||
// but this method is kept for backwards compatibility
|
||||
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-getUser
|
||||
func (s *UserService) GetByAccountIDWithContext(ctx context.Context, accountID string) (*User, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user?accountId=%s", accountID)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
user := new(User)
|
||||
resp, err := s.client.Do(req, user)
|
||||
if err != nil {
|
||||
return nil, resp, NewJiraError(resp, err)
|
||||
}
|
||||
return user, resp, nil
|
||||
}
|
||||
|
||||
// GetByAccountID wraps GetByAccountIDWithContext using the background context.
|
||||
func (s *UserService) GetByAccountID(accountID string) (*User, *Response, error) {
|
||||
return s.GetByAccountIDWithContext(context.Background(), accountID)
|
||||
}
|
||||
|
||||
// CreateWithContext creates an user in Jira.
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-createUser
|
||||
func (s *UserService) Create(user *User) (*User, *Response, error) {
|
||||
// Jira API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-createUser
|
||||
func (s *UserService) CreateWithContext(ctx context.Context, user *User) (*User, *Response, error) {
|
||||
apiEndpoint := "/rest/api/2/user"
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, user)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "POST", apiEndpoint, user)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -84,24 +112,30 @@ func (s *UserService) Create(user *User) (*User, *Response, error) {
|
|||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
e := fmt.Errorf("Could not read the returned data")
|
||||
e := fmt.Errorf("could not read the returned data")
|
||||
return nil, resp, NewJiraError(resp, e)
|
||||
}
|
||||
err = json.Unmarshal(data, responseUser)
|
||||
if err != nil {
|
||||
e := fmt.Errorf("Could not unmarshall the data into struct")
|
||||
e := fmt.Errorf("could not unmarshall the data into struct")
|
||||
return nil, resp, NewJiraError(resp, e)
|
||||
}
|
||||
return responseUser, resp, nil
|
||||
}
|
||||
|
||||
// Delete deletes an user from JIRA.
|
||||
// Create wraps CreateWithContext using the background context.
|
||||
func (s *UserService) Create(user *User) (*User, *Response, error) {
|
||||
return s.CreateWithContext(context.Background(), user)
|
||||
}
|
||||
|
||||
// DeleteWithContext deletes an user from Jira.
|
||||
// Returns http.StatusNoContent on success.
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-user-delete
|
||||
func (s *UserService) Delete(username string) (*Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user?username=%s", username)
|
||||
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-user-delete
|
||||
// Caller must close resp.Body
|
||||
func (s *UserService) DeleteWithContext(ctx context.Context, accountId string) (*Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user?accountId=%s", accountId)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "DELETE", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -113,12 +147,18 @@ func (s *UserService) Delete(username string) (*Response, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
// GetGroups returns the groups which the user belongs to
|
||||
// Delete wraps DeleteWithContext using the background context.
|
||||
// Caller must close resp.Body
|
||||
func (s *UserService) Delete(accountId string) (*Response, error) {
|
||||
return s.DeleteWithContext(context.Background(), accountId)
|
||||
}
|
||||
|
||||
// GetGroupsWithContext returns the groups which the user belongs to
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-getUserGroups
|
||||
func (s *UserService) GetGroups(username string) (*[]UserGroup, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user/groups?username=%s", username)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-user-groups-get
|
||||
func (s *UserService) GetGroupsWithContext(ctx context.Context, accountId string) (*[]UserGroup, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user/groups?accountId=%s", accountId)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -131,12 +171,17 @@ func (s *UserService) GetGroups(username string) (*[]UserGroup, *Response, error
|
|||
return userGroups, resp, nil
|
||||
}
|
||||
|
||||
// Get information about the current logged-in user
|
||||
// GetGroups wraps GetGroupsWithContext using the background context.
|
||||
func (s *UserService) GetGroups(accountId string) (*[]UserGroup, *Response, error) {
|
||||
return s.GetGroupsWithContext(context.Background(), accountId)
|
||||
}
|
||||
|
||||
// GetSelfWithContext information about the current logged-in user
|
||||
//
|
||||
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-myself-get
|
||||
func (s *UserService) GetSelf() (*User, *Response, error) {
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-myself-get
|
||||
func (s *UserService) GetSelfWithContext(ctx context.Context) (*User, *Response, error) {
|
||||
const apiEndpoint = "rest/api/2/myself"
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -148,6 +193,11 @@ func (s *UserService) GetSelf() (*User, *Response, error) {
|
|||
return &user, resp, nil
|
||||
}
|
||||
|
||||
// GetSelf wraps GetSelfWithContext using the background context.
|
||||
func (s *UserService) GetSelf() (*User, *Response, error) {
|
||||
return s.GetSelfWithContext(context.Background())
|
||||
}
|
||||
|
||||
// WithMaxResults sets the max results to return
|
||||
func WithMaxResults(maxResults int) userSearchF {
|
||||
return func(s userSearch) userSearch {
|
||||
|
@ -180,14 +230,38 @@ func WithInactive(inactive bool) userSearchF {
|
|||
}
|
||||
}
|
||||
|
||||
// Find searches for user info from JIRA:
|
||||
// It can find users by email, username or name
|
||||
// WithUsername sets the username to search
|
||||
func WithUsername(username string) userSearchF {
|
||||
return func(s userSearch) userSearch {
|
||||
s = append(s, userSearchParam{name: "username", value: username})
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// WithAccountId sets the account id to search
|
||||
func WithAccountId(accountId string) userSearchF {
|
||||
return func(s userSearch) userSearch {
|
||||
s = append(s, userSearchParam{name: "accountId", value: accountId})
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// WithProperty sets the property (Property keys are specified by path) to search
|
||||
func WithProperty(property string) userSearchF {
|
||||
return func(s userSearch) userSearch {
|
||||
s = append(s, userSearchParam{name: "property", value: property})
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// FindWithContext searches for user info from Jira:
|
||||
// It can find users by email or display name using the query parameter
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-findUsers
|
||||
func (s *UserService) Find(property string, tweaks ...userSearchF) ([]User, *Response, error) {
|
||||
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-user-search-get
|
||||
func (s *UserService) FindWithContext(ctx context.Context, property string, tweaks ...userSearchF) ([]User, *Response, error) {
|
||||
search := []userSearchParam{
|
||||
{
|
||||
name: "username",
|
||||
name: "query",
|
||||
value: property,
|
||||
},
|
||||
}
|
||||
|
@ -201,7 +275,7 @@ func (s *UserService) Find(property string, tweaks ...userSearchF) ([]User, *Res
|
|||
}
|
||||
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/user/search?%s", queryString[:len(queryString)-1])
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -213,3 +287,8 @@ func (s *UserService) Find(property string, tweaks ...userSearchF) ([]User, *Res
|
|||
}
|
||||
return users, resp, nil
|
||||
}
|
||||
|
||||
// Find wraps FindWithContext using the background context.
|
||||
func (s *UserService) Find(property string, tweaks ...userSearchF) ([]User, *Response, error) {
|
||||
return s.FindWithContext(context.Background(), property, tweaks...)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue