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
|
|
|
)
|
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
var client *http.Client
|
2015-10-13 02:16:05 -04:00
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
func init() {
|
2015-10-30 00:02:04 -04:00
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
client = &http.Client{
|
2015-10-13 02:16:05 -04:00
|
|
|
Transport: &http.Transport{
|
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
2015-10-24 21:19:24 -04:00
|
|
|
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-24 21:19:24 -04:00
|
|
|
|
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))
|
|
|
|
}
|