-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
50 lines (41 loc) · 1.17 KB
/
client.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
package goji
import (
"fmt"
"github.com/andygrunwald/go-jira"
)
type Client struct {
JiraClient *jira.Client
CurrentUser *jira.User
}
func NewClient(baseUrl string, username string, password string) (*Client, error) {
client := &Client{}
tp := jira.BasicAuthTransport{
Username: username,
Password: password,
}
jclient, err := jira.NewClient(tp.Client(), baseUrl)
if err != nil {
return nil, err
}
client.JiraClient = jclient
usr, _, err := client.JiraClient.User.Get(username)
if err != nil {
return nil, err
}
client.CurrentUser = usr
return client, nil
}
func (c Client) GetAssignedTasks(user string) ([]jira.Issue, error) {
if len(user) == 0 {
user = c.CurrentUser.Name
}
issues, _, err := c.JiraClient.Issue.Search(fmt.Sprintf("assignee in (%s)", user), nil)
return issues, err
}
func (c Client) GetCurrentUserWorklog(daysInThePast int) ([]jira.Issue, error) {
var jql string
hours := 24 * daysInThePast
jql = fmt.Sprintf("updatedDate >= startOfDay(\"-%dh\") and updatedDate < endOfDay(\"-%dh\") AND assignee was currentUser() ORDER BY updatedDate ASC", hours, hours)
issues, _, err := c.JiraClient.Issue.Search(jql, nil)
return issues, err
}