Compare commits

...

6 Commits

Author SHA1 Message Date
Cory Bennett 8c07442645 bump version 2015-02-19 10:31:20 -08:00
Cory Bennett f3feff796f [issue #8] detect X-Seraph-Loginreason: AUTHENTICATION_DENIED header to catch login failures 2015-02-19 10:05:51 -08:00
coryb 28bd1dffa5 Merge pull request #7 from jaybuff/empty-projects
validate project
2015-02-18 21:06:55 -08:00
Jay Buffington 5f7b46173a project should always be uppercase
Jira docs say as much:
https://confluence.atlassian.com/display/JIRA/Changing+the+Project+Key+Format#ChangingtheProjectKeyFormat-prerequisites
2015-02-18 19:26:36 -08:00
Jay Buffington 39a194b858 if response is 400, check json for errorMessages and log them 2015-02-18 17:39:37 -08:00
Jay Buffington 4b6329597b validate project 2015-02-18 17:32:56 -08:00
4 changed files with 41 additions and 9 deletions
+4
View File
@@ -32,6 +32,10 @@ func New(opts map[string]string) *Cli {
endpoint, _ := opts["endpoint"]
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
if project, ok := opts["project"]; ok {
opts["project"] = strings.ToUpper(project)
}
cli := &Cli{
endpoint: url,
opts: opts,
+24 -6
View File
@@ -27,14 +27,22 @@ func (c *Cli) CmdLogin() error {
// probably got this, need to redirect the user to login manually
// X-Authentication-Denied-Reason: CAPTCHA_CHALLENGE; login-url=https://jira/login.jsp
if reason := resp.Header.Get("X-Authentication-Denied-Reason"); reason != "" {
log.Error("Authentication Failed: %s", reason)
return fmt.Errorf("Authenticaion Failed: %s", reason)
err := fmt.Errorf("Authenticaion Failed: %s", reason)
log.Error("%s", err)
return err
}
log.Error("Authentication Failead: Unknown")
return fmt.Errorf("Authentication Failead")
err := fmt.Errorf("Authentication Failed: Unknown Reason")
log.Error("%s", err)
return err
}
if resp.StatusCode != 200 {
} else if resp.StatusCode == 200 {
// https://confluence.atlassian.com/display/JIRA043/JIRA+REST+API+%28Alpha%29+Tutorial#JIRARESTAPI%28Alpha%29Tutorial-CAPTCHAs
// probably bad password, try again
if reason := resp.Header.Get("X-Seraph-Loginreason"); reason == "AUTHENTICATION_DENIED" {
log.Warning("Authentication Failed: %s", reason)
continue
}
} else {
log.Warning("Login failed")
continue
}
@@ -220,6 +228,11 @@ func (c *Cli) CmdCreateMeta(project string, issuetype string) error {
}
if val, ok := data.(map[string]interface{})["projects"]; ok {
if len(val.([]interface{})) == 0 {
err = fmt.Errorf("Project '%s' or issuetype '%s' unknown. Unable to createmeta.", project, issuetype)
log.Error("%s", err)
return err
}
if val, ok = val.([]interface{})[0].(map[string]interface{})["issuetypes"]; ok {
data = val.([]interface{})[0]
}
@@ -253,6 +266,11 @@ func (c *Cli) CmdCreate(project string, issuetype string) error {
issueData["overrides"].(map[string]string)["issuetype"] = issuetype
if val, ok := data.(map[string]interface{})["projects"]; ok {
if len(val.([]interface{})) == 0 {
err = fmt.Errorf("Project '%s' or issuetype '%s' unknown. Unable to create issue.", project, issuetype)
log.Error("%s", err)
return err
}
if val, ok = val.([]interface{})[0].(map[string]interface{})["issuetypes"]; ok {
issueData["meta"] = val.([]interface{})[0]
}
+12 -2
View File
@@ -116,9 +116,19 @@ func runTemplate(templateContent string, data interface{}, out io.Writer) error
func responseToJson(resp *http.Response, err error) (interface{}, error) {
if err != nil {
return nil, err
} else {
return jsonDecode(resp.Body), nil
}
data := jsonDecode(resp.Body)
if resp.StatusCode == 400 {
if val, ok := data.(map[string]interface{})["errorMessages"]; ok {
for _,errMsg := range val.([]interface{}) {
log.Error("%s", errMsg)
}
}
}
return data, nil
}
func jsonDecode(io io.Reader) interface{} {
+1 -1
View File
@@ -72,7 +72,7 @@ Command Options:
or Watcher to search for
`, user, fmt.Sprintf("%s/.jira.d/templates", home), user)
args, err := docopt.Parse(usage, nil, true, "0.0.2", false, false)
args, err := docopt.Parse(usage, nil, true, "0.0.3", false, false)
if err != nil {
log.Error("Failed to parse options: %s", err)
os.Exit(1)