-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
jira_user.go
60 lines (53 loc) 路 1.69 KB
/
jira_user.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
package jira
import (
"encoding/json"
"errors"
"github.com/mk-5/fjira/internal/app"
)
type User struct {
AccountId string `json:"accountId"`
Active bool `json:"active"`
AvatarUrls map[string]string `json:"avatarUrls"`
DisplayName string `json:"displayName"`
EmailAddress string `json:"emailAddress"`
Locale string `json:"locale"`
Self string `json:"self"`
TimeZone string `json:"timeZone"`
Key string `json:"key"` // field used by on-premise installation
Name string `json:"name"` // field used by on-premise installation
}
const (
FindUser = "/rest/api/2/user/assignable/search"
)
var UserSearchDeserializeErr = errors.New("Cannot deserialize jira user search response.")
type findUserQueryParams struct {
Project string `url:"project"`
MaxResults int `url:"maxResults"`
Query *string `url:"query"`
Username *string `url:"username"`
}
func (api *httpApi) FindUsers(project string) ([]User, error) {
return api.FindUsersWithQuery(project, "")
}
func (api *httpApi) FindUsersWithQuery(project string, query string) ([]User, error) {
queryParams := &findUserQueryParams{
Project: project,
MaxResults: 10000,
}
if query != "" && !api.IsJiraServer() {
queryParams.Query = &query
}
if query != "" && api.IsJiraServer() {
queryParams.Username = &query
}
response, err := api.jiraRequest("GET", FindUser, queryParams, nil)
if err != nil {
return nil, err
}
var users []User
if err := json.Unmarshal(response, &users); err != nil {
app.Error(err.Error())
return nil, UserSearchDeserializeErr
}
return users, nil
}