all: unindent some code

This commit is contained in:
Daniel Martí
2019-05-27 19:14:13 +01:00
committed by Cory Bennett
parent 17003717d9
commit bb9790f287
7 changed files with 133 additions and 135 deletions
+14 -14
View File
@@ -255,24 +255,24 @@ func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, iss
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == 200 { if resp.StatusCode != 200 {
results := &jiradata.CreateMeta{} return nil, responseError(resp)
err = json.NewDecoder(resp.Body).Decode(results) }
if err != nil { results := &jiradata.CreateMeta{}
return nil, err if err := json.NewDecoder(resp.Body).Decode(results); err != nil {
return nil, err
}
for _, project := range results.Projects {
if project.Key != projectKey {
continue
} }
for _, project := range results.Projects { for _, issueType := range project.IssueTypes {
if project.Key == projectKey { if issueType.Name == issueTypeName {
for _, issueType := range project.IssueTypes { return issueType, nil
if issueType.Name == issueTypeName {
return issueType, nil
}
}
} }
} }
return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
} }
return nil, responseError(resp) return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
} }
type LinkIssueProvider interface { type LinkIssueProvider interface {
+68 -67
View File
@@ -150,43 +150,39 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
app.Flag("user", "user name used within the Jira service").Short('u').SetValue(&globals.User) app.Flag("user", "user name used within the Jira service").Short('u').SetValue(&globals.User)
app.Flag("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login) app.Flag("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login)
o = o.WithPreCallback( o = o.WithPreCallback(func(req *http.Request) (*http.Request, error) {
func(req *http.Request) (*http.Request, error) { if globals.AuthMethod() == "api-token" {
if globals.AuthMethod() == "api-token" { // need to set basic auth header with user@domain:api-token
// need to set basic auth header with user@domain:api-token token := globals.GetPass()
token := globals.GetPass() authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token)))) req.Header.Add("Authorization", authHeader)
req.Header.Add("Authorization", authHeader) }
} return req, nil
return req, nil })
},
)
o = o.WithPostCallback( o = o.WithPostCallback(func(req *http.Request, resp *http.Response) (*http.Response, error) {
func(req *http.Request, resp *http.Response) (*http.Response, error) { if globals.AuthMethod() == "session" {
if globals.AuthMethod() == "session" { authUser := resp.Header.Get("X-Ausername")
authUser := resp.Header.Get("X-Ausername") if authUser == "" || authUser == "anonymous" {
if authUser == "" || authUser == "anonymous" { // preserve the --quiet value, we need to temporarily disable it so
// preserve the --quiet value, we need to temporarily disable it so // the normal login output is surpressed
// the normal login output is surpressed defer func(quiet bool) {
defer func(quiet bool) { globals.Quiet.Value = quiet
globals.Quiet.Value = quiet }(globals.Quiet.Value)
}(globals.Quiet.Value) globals.Quiet.Value = true
globals.Quiet.Value = true
// we are not logged in, so force login now by running the "login" command // we are not logged in, so force login now by running the "login" command
app.Parse([]string{"login"}) app.Parse([]string{"login"})
// rerun the original request // rerun the original request
return o.Do(req)
}
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
globals.SetPass("")
return o.Do(req) return o.Do(req)
} }
return resp, nil } else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
}, globals.SetPass("")
) return o.Do(req)
}
return resp, nil
})
for _, command := range globalCommandRegistry { for _, command := range globalCommandRegistry {
copy := command copy := command
@@ -238,14 +234,12 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
copy.Entry.UsageFunc(fig, cmd) copy.Entry.UsageFunc(fig, cmd)
} }
cmd.Action( cmd.Action(func(_ *kingpin.ParseContext) error {
func(_ *kingpin.ParseContext) error { if logging.GetLevel("") > logging.DEBUG {
if logging.GetLevel("") > logging.DEBUG { o = o.WithTrace(true)
o = o.WithTrace(true) }
} return copy.Entry.ExecuteFunc(o, &globals)
return copy.Entry.ExecuteFunc(o, &globals) })
},
)
} }
} }
@@ -321,35 +315,42 @@ func (o *CommonOptions) editFile(fileName string) (changes bool, err error) {
} }
// now we just need to diff the files to see if there are any changes // now we just need to diff the files to see if there are any changes
var oldHandle, newHandle *os.File f1, err := os.Open(tmpFileNameOrig)
var oldStat, newStat os.FileInfo if err != nil {
if oldHandle, err = os.Open(tmpFileNameOrig); err == nil { return false, err
if newHandle, err = os.Open(fileName); err == nil { }
if oldStat, err = oldHandle.Stat(); err == nil { f2, err := os.Open(fileName)
if newStat, err = newHandle.Stat(); err == nil { if err != nil {
// different sizes, so must have changes return false, err
if oldStat.Size() != newStat.Size() { }
return true, err
} stat1, err := f1.Stat()
oldBuf, newBuf := make([]byte, 1024), make([]byte, 1024) if err != nil {
var oldCount, newCount int return false, err
// loop though 1024 bytes at a time comparing the buffers for changes }
for err != io.EOF { stat2, err := f2.Stat()
oldCount, _ = oldHandle.Read(oldBuf) if err != nil {
newCount, err = newHandle.Read(newBuf) return false, err
if oldCount != newCount { }
return true, nil // different sizes, so must have changes
} if stat1.Size() != stat2.Size() {
if !bytes.Equal(oldBuf[:oldCount], newBuf[:newCount]) { return true, nil
return true, nil }
}
} p1, p2 := make([]byte, 1024), make([]byte, 1024)
return false, nil var n1, n2 int
} // loop though 1024 bytes at a time comparing the buffers for changes
} for err != io.EOF {
n1, _ = f1.Read(p1)
n2, err = f2.Read(p2)
if n1 != n2 {
return true, nil
}
if !bytes.Equal(p1[:n1], p2[:n2]) {
return true, nil
} }
} }
return false, err return false, nil
} }
var EditLoopAbort = fmt.Errorf("edit Loop aborted by request") var EditLoopAbort = fmt.Errorf("edit Loop aborted by request")
+2 -1
View File
@@ -44,7 +44,8 @@ func getTemplate(name string) (string, error) {
b, err := findTemplate(name) b, err := findTemplate(name)
if err != nil { if err != nil {
return "", err return "", err
} else if b != nil { }
if b != nil {
return string(b), nil return string(b), nil
} }
if s, ok := AllTemplates[name]; ok { if s, ok := AllTemplates[name]; ok {
+6 -7
View File
@@ -187,13 +187,12 @@ func ParseCommandLine(app *kingpin.Application, args []string) {
if _, ok := err.(*Error); ok { if _, ok := err.(*Error); ok {
log.Errorf("%s", err) log.Errorf("%s", err)
panic(Exit{Code: 1}) panic(Exit{Code: 1})
} else {
ctx, _ := app.ParseContext(os.Args[1:])
if ctx != nil {
app.UsageForContext(ctx)
}
log.Errorf("Invalid Usage: %s", err)
panic(Exit{Code: 1})
} }
ctx, _ := app.ParseContext(os.Args[1:])
if ctx != nil {
app.UsageForContext(ctx)
}
log.Errorf("Invalid Usage: %s", err)
panic(Exit{Code: 1})
} }
} }
+23 -22
View File
@@ -76,30 +76,31 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
} }
for _, trans := range []string{"close", "done", "cancel", "start", "stop"} { for _, trans := range []string{"close", "done", "cancel", "start", "stop"} {
transMeta := meta.Transitions.Find(trans) transMeta := meta.Transitions.Find(trans)
if transMeta != nil { if transMeta == nil {
issueUpdate := jiradata.IssueUpdate{ continue
Transition: transMeta, }
} issueUpdate := jiradata.IssueUpdate{
resolution := defaultResolution(transMeta) Transition: transMeta,
if resolution != "" { }
issueUpdate.Fields = map[string]interface{}{ resolution := defaultResolution(transMeta)
"resolution": map[string]interface{}{ if resolution != "" {
"name": resolution, issueUpdate.Fields = map[string]interface{}{
}, "resolution": map[string]interface{}{
} "name": resolution,
} },
if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
return err
}
if trans != "start" {
break
}
// if we are here then we must be stopping, so need to reset the meta
meta, err = jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil {
return err
} }
} }
if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
return err
}
if trans != "start" {
break
}
// if we are here then we must be stopping, so need to reset the meta
meta, err = jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
if err != nil {
return err
}
} }
if !globals.Quiet.Value { if !globals.Quiet.Value {
+13 -15
View File
@@ -124,22 +124,20 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error { err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate) return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
}) })
if err == jiracli.EditLoopAbort { if err == jiracli.EditLoopAbort && len(results.Issues) > i+1 {
if len(results.Issues) > i+1 { var answer bool
var answer bool survey.AskOne(
survey.AskOne( &survey.Confirm{
&survey.Confirm{ Message: fmt.Sprintf("Continue to edit next issue %s?", results.Issues[i+1].Key),
Message: fmt.Sprintf("Continue to edit next issue %s?", results.Issues[i+1].Key), Default: true,
Default: true, },
}, &answer,
&answer, nil,
nil, )
) if answer {
if answer { continue
continue
}
panic(jiracli.Exit{1})
} }
panic(jiracli.Exit{1})
} }
if err != nil { if err != nil {
return err return err
+7 -9
View File
@@ -110,15 +110,13 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
} }
// need to default the Resolution, usually Fixed works but sometime need Done // need to default the Resolution, usually Fixed works but sometime need Done
if opts.Resolution == "" { if resField, ok := transMeta.Fields["resolution"]; ok && opts.Resolution == "" {
if resField, ok := transMeta.Fields["resolution"]; ok { for _, allowedValueRaw := range resField.AllowedValues {
for _, allowedValueRaw := range resField.AllowedValues { if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok {
if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok { if allowedValue["name"] == "Fixed" {
if allowedValue["name"] == "Fixed" { opts.Resolution = "Fixed"
opts.Resolution = "Fixed" } else if allowedValue["name"] == "Done" {
} else if allowedValue["name"] == "Done" { opts.Resolution = "Done"
opts.Resolution = "Done"
}
} }
} }
} }