Replace direct usage of the API with go-jira
This commit is contained in:
parent
ae4b6e6620
commit
4933ed1147
57 changed files with 7699 additions and 114 deletions
106
jira/jira.go
106
jira/jira.go
|
@ -1,91 +1,67 @@
|
|||
package jira
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"git.ctrlz.es/mgdelacroix/campaigner/http"
|
||||
jira "gopkg.in/andygrunwald/go-jira.v1"
|
||||
)
|
||||
|
||||
const defaultUrl = "https://mattermost.atlassian.net"
|
||||
|
||||
type JiraClient struct {
|
||||
Username string
|
||||
Token string
|
||||
Url string
|
||||
*jira.Client
|
||||
}
|
||||
|
||||
type JiraIssueFieldsStatus struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
func NewClient(username, token string) (*JiraClient, error) {
|
||||
tp := jira.BasicAuthTransport{
|
||||
Username: username,
|
||||
Password: token,
|
||||
}
|
||||
|
||||
type JiraIssueFields struct {
|
||||
Status JiraIssueFieldsStatus `json:"status"`
|
||||
Summary string `json:"summary"`
|
||||
}
|
||||
|
||||
type JiraIssue struct {
|
||||
Key string `json:"key"`
|
||||
Fields JiraIssueFields `json:"fields"`
|
||||
}
|
||||
|
||||
func IssueFromJson(body io.Reader) (*JiraIssue, error) {
|
||||
var issue JiraIssue
|
||||
if err := json.NewDecoder(body).Decode(&issue); err != nil {
|
||||
client, err := jira.NewClient(tp.Client(), defaultUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &issue, nil
|
||||
}
|
||||
|
||||
func NewClient(username, token string) *JiraClient {
|
||||
return &JiraClient{
|
||||
Username: username,
|
||||
Token: token,
|
||||
Url: "https://mattermost.atlassian.net/rest/api/2/",
|
||||
}
|
||||
return &JiraClient{client}, nil
|
||||
}
|
||||
|
||||
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},
|
||||
},
|
||||
}
|
||||
/*
|
||||
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
|
||||
}
|
||||
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()
|
||||
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
|
||||
}
|
||||
issue, err := IssueFromJson(res.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return issue.Key, nil
|
||||
return issue.Key, nil
|
||||
*/
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (c *JiraClient) GetIssue(issueNo string) (*JiraIssue, error) {
|
||||
res, err := http.DoGet(c.Username, c.Token, c.Url+"issue/"+issueNo)
|
||||
func (c *JiraClient) GetIssue(issueNo string) (*jira.Issue, error) {
|
||||
issue, _, err := c.Issue.Get(issueNo, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
issue, err := IssueFromJson(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return issue, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue