prolific2jira/jira.go

62 lines
1.1 KiB
Go
Raw Normal View History

2015-10-13 02:16:05 -04:00
package main
import (
"bytes"
"crypto/tls"
2015-10-30 00:02:04 -04:00
"encoding/json"
2015-10-13 02:16:05 -04:00
"fmt"
2015-10-30 00:02:04 -04:00
"io/ioutil"
2015-10-13 02:16:05 -04:00
"net/http"
2015-10-30 00:02:04 -04:00
"net/http/httputil"
2015-10-13 02:16:05 -04:00
)
var client *http.Client
2015-10-13 02:16:05 -04:00
func init() {
2015-10-30 00:02:04 -04:00
client = &http.Client{
2015-10-13 02:16:05 -04:00
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
}
func submitIssue(i []string, user string, pass string, svr string, prj string) error {
issue := newIssue(i, prj)
2015-10-13 02:16:05 -04:00
issueJSON := toJSON(issue)
2015-10-30 00:02:04 -04:00
fmt.Printf("* %s :", issue.Fields.Title)
2015-10-13 02:16:05 -04:00
uri := fmt.Sprintf("%s/rest/api/2/issue/", svr)
req, _ := http.NewRequest("POST", uri, bytes.NewBuffer(issueJSON))
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(user, pass)
resp, err := client.Do(req)
2015-10-13 02:16:05 -04:00
if err != nil {
return err
}
2015-10-30 00:02:04 -04:00
r := make(map[string]interface{})
defer resp.Body.Close()
contents, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(contents, &r)
if err != nil {
return err
}
fmt.Printf(" created as %s", r["key"])
// printResponse(resp)
2015-10-13 02:16:05 -04:00
return nil
}
2015-10-30 00:02:04 -04:00
func printResponse(resp *http.Response) {
r, _ := httputil.DumpResponse(resp, true)
fmt.Printf(string(r))
}