mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-20 13:13:27 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c07442645 | |||
| f3feff796f | |||
| 28bd1dffa5 | |||
| 5f7b46173a | |||
| 39a194b858 | |||
| 4b6329597b |
@@ -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
@@ -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
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user