2015-10-13 00:01:07 -04:00
|
|
|
package main
|
|
|
|
|
2015-10-13 01:46:17 -04:00
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"encoding/csv"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var user = flag.String("user", "user", "jira username")
|
|
|
|
var pass = flag.String("pass", "NotAPassword1", "jira password")
|
|
|
|
var prj = flag.String("prj", "PROJ", "jira project to add stories to")
|
|
|
|
var svr = flag.String("svr", "https://jira.example.com", "jira server url")
|
|
|
|
|
2015-10-13 00:01:07 -04:00
|
|
|
func main() {
|
2015-10-13 01:46:17 -04:00
|
|
|
if len(os.Args) != 9 {
|
|
|
|
flag.PrintDefaults()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-10-30 00:02:04 -04:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// fmt.Printf("%v", os.Args)
|
|
|
|
// fmt.Printf(*svr)
|
|
|
|
|
2015-10-13 01:46:17 -04:00
|
|
|
bufrdr := bufio.NewReader(os.Stdin)
|
|
|
|
bufrdr.ReadLine()
|
2015-10-24 21:19:24 -04:00
|
|
|
// processIssue(csvrdr, printJSON)
|
|
|
|
|
|
|
|
processIssue(bufrdr, submitIssue, *user, *pass, *svr, *prj)
|
|
|
|
|
2015-10-13 01:46:17 -04:00
|
|
|
}
|
2015-10-13 00:01:07 -04:00
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
type procFunc func(i []string, user string, pass string, srv string, prj string) error
|
|
|
|
|
|
|
|
func processIssue(r io.Reader, process procFunc, user string, pass string, svr string, prj string) error {
|
|
|
|
|
|
|
|
csvrdr := csv.NewReader(r)
|
|
|
|
|
2015-10-13 01:46:17 -04:00
|
|
|
for {
|
2015-10-24 21:19:24 -04:00
|
|
|
record, err := csvrdr.Read()
|
2015-10-13 01:46:17 -04:00
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
err = process(record, user, pass, svr, prj)
|
2015-10-13 01:46:17 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-24 21:19:24 -04:00
|
|
|
func printCSV(issue []string, user string, pass string, svr string, prj string) error {
|
2015-10-13 01:46:17 -04:00
|
|
|
fmt.Println(issue)
|
|
|
|
return nil
|
|
|
|
}
|
2015-10-24 21:19:24 -04:00
|
|
|
func printJSON(issue []string, user string, pass string, svr string, prj string) error {
|
|
|
|
i := newIssue(issue, prj)
|
2015-10-13 02:16:05 -04:00
|
|
|
fmt.Println(string(toJSON(i)))
|
2015-10-13 01:46:17 -04:00
|
|
|
return nil
|
2015-10-13 00:01:07 -04:00
|
|
|
}
|