Add get-jira-ticket command
This commit is contained in:
parent
5d727b8995
commit
0ae0c6ffdf
4 changed files with 72 additions and 13 deletions
48
jira/jira.go
48
jira/jira.go
|
@ -2,7 +2,7 @@ package jira
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
|
||||
"git.ctrlz.es/mgdelacroix/campaigner/http"
|
||||
)
|
||||
|
@ -13,19 +13,37 @@ type JiraClient struct {
|
|||
Url string
|
||||
}
|
||||
|
||||
type JiraIssueFieldsStatus struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type JiraIssueFields struct {
|
||||
Status JiraIssueFieldsStatus `json:"status"`
|
||||
}
|
||||
|
||||
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 {
|
||||
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",
|
||||
Url: "https://mattermost.atlassian.net/rest/api/2/",
|
||||
}
|
||||
}
|
||||
|
||||
func (c *JiraClient) CreateTicket(epicId, team, summary, description string) (string, error) {
|
||||
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"},
|
||||
|
@ -42,21 +60,31 @@ func (c *JiraClient) CreateTicket(epicId, team, summary, description string) (st
|
|||
return "", err
|
||||
}
|
||||
|
||||
res, err := http.DoPost(c.Username, c.Token, c.Url+"/issue/", body)
|
||||
res, err := http.DoPost(c.Username, c.Token, c.Url+"issue/", body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
respBody, err := ioutil.ReadAll(res.Body)
|
||||
issue, err := IssueFromJson(res.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var issue JiraIssue
|
||||
if err := json.Unmarshal(respBody, &issue); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return issue.Key, nil
|
||||
}
|
||||
|
||||
func (c *JiraClient) GetIssue(issueNo string) (*JiraIssue, error) {
|
||||
res, err := http.DoGet(c.Username, c.Token, c.Url+"issue/"+issueNo)
|
||||
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