2020-03-01 11:42:36 +01:00
|
|
|
package jira
|
|
|
|
|
|
|
|
import (
|
2020-03-04 22:13:55 +01:00
|
|
|
jira "gopkg.in/andygrunwald/go-jira.v1"
|
2020-03-01 11:42:36 +01:00
|
|
|
)
|
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
const defaultUrl = "https://mattermost.atlassian.net"
|
2020-03-01 13:02:52 +01:00
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
type JiraClient struct {
|
|
|
|
*jira.Client
|
2020-03-01 11:42:36 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
func NewClient(username, token string) (*JiraClient, error) {
|
|
|
|
tp := jira.BasicAuthTransport{
|
2020-03-01 11:42:36 +01:00
|
|
|
Username: username,
|
2020-03-04 22:13:55 +01:00
|
|
|
Password: token,
|
2020-03-01 12:30:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
client, err := jira.NewClient(tp.Client(), defaultUrl)
|
2020-03-01 12:30:49 +01:00
|
|
|
if err != nil {
|
2020-03-04 22:13:55 +01:00
|
|
|
return nil, err
|
2020-03-01 12:30:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
return &JiraClient{client}, nil
|
2020-03-01 13:02:52 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
func (c *JiraClient) CreateIssue(epicId, team, summary, description string) (string, error) {
|
|
|
|
/*
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"fields": map[string]interface{}{
|
|
|
|
"project": map[string]interface{}{"key": "MM"},
|
|
|
|
"summary": summary,
|
|
|
|
"description": description,
|
|
|
|
"issuetype": map[string]interface{}{"name": "Story"},
|
|
|
|
"customfield_10007": epicId,
|
|
|
|
"customfield_11101": map[string]interface{}{"value": team},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
body, err := json.Marshal(data)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := http.DoPost(c.Username, c.Token, c.Url+"issue/", body)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
issue, err := IssueFromJson(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return issue.Key, nil
|
|
|
|
*/
|
|
|
|
return "", nil
|
|
|
|
}
|
2020-03-01 12:30:49 +01:00
|
|
|
|
2020-03-04 22:13:55 +01:00
|
|
|
func (c *JiraClient) GetIssue(issueNo string) (*jira.Issue, error) {
|
|
|
|
issue, _, err := c.Issue.Get(issueNo, nil)
|
2020-03-01 13:02:52 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return issue, nil
|
2020-03-01 11:42:36 +01:00
|
|
|
}
|