mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
all: unindent some code
This commit is contained in:
@@ -255,25 +255,25 @@ func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, iss
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 200 {
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, responseError(resp)
|
||||
}
|
||||
results := &jiradata.CreateMeta{}
|
||||
err = json.NewDecoder(resp.Body).Decode(results)
|
||||
if err != nil {
|
||||
if err := json.NewDecoder(resp.Body).Decode(results); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, project := range results.Projects {
|
||||
if project.Key == projectKey {
|
||||
if project.Key != projectKey {
|
||||
continue
|
||||
}
|
||||
for _, issueType := range project.IssueTypes {
|
||||
if issueType.Name == issueTypeName {
|
||||
return issueType, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
|
||||
}
|
||||
return nil, responseError(resp)
|
||||
}
|
||||
|
||||
type LinkIssueProvider interface {
|
||||
ProvideLinkIssueRequest() *jiradata.LinkIssueRequest
|
||||
|
||||
+35
-34
@@ -150,8 +150,7 @@ 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("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login)
|
||||
|
||||
o = o.WithPreCallback(
|
||||
func(req *http.Request) (*http.Request, error) {
|
||||
o = o.WithPreCallback(func(req *http.Request) (*http.Request, error) {
|
||||
if globals.AuthMethod() == "api-token" {
|
||||
// need to set basic auth header with user@domain:api-token
|
||||
token := globals.GetPass()
|
||||
@@ -159,11 +158,9 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
|
||||
req.Header.Add("Authorization", authHeader)
|
||||
}
|
||||
return req, nil
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
o = o.WithPostCallback(
|
||||
func(req *http.Request, resp *http.Response) (*http.Response, error) {
|
||||
o = o.WithPostCallback(func(req *http.Request, resp *http.Response) (*http.Response, error) {
|
||||
if globals.AuthMethod() == "session" {
|
||||
authUser := resp.Header.Get("X-Ausername")
|
||||
if authUser == "" || authUser == "anonymous" {
|
||||
@@ -185,8 +182,7 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
|
||||
return o.Do(req)
|
||||
}
|
||||
return resp, nil
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
for _, command := range globalCommandRegistry {
|
||||
copy := command
|
||||
@@ -238,14 +234,12 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
|
||||
copy.Entry.UsageFunc(fig, cmd)
|
||||
}
|
||||
|
||||
cmd.Action(
|
||||
func(_ *kingpin.ParseContext) error {
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
if logging.GetLevel("") > logging.DEBUG {
|
||||
o = o.WithTrace(true)
|
||||
}
|
||||
return copy.Entry.ExecuteFunc(o, &globals)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,36 +315,43 @@ 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
|
||||
var oldHandle, newHandle *os.File
|
||||
var oldStat, newStat os.FileInfo
|
||||
if oldHandle, err = os.Open(tmpFileNameOrig); err == nil {
|
||||
if newHandle, err = os.Open(fileName); err == nil {
|
||||
if oldStat, err = oldHandle.Stat(); err == nil {
|
||||
if newStat, err = newHandle.Stat(); err == nil {
|
||||
// different sizes, so must have changes
|
||||
if oldStat.Size() != newStat.Size() {
|
||||
return true, err
|
||||
f1, err := os.Open(tmpFileNameOrig)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
oldBuf, newBuf := make([]byte, 1024), make([]byte, 1024)
|
||||
var oldCount, newCount int
|
||||
// loop though 1024 bytes at a time comparing the buffers for changes
|
||||
for err != io.EOF {
|
||||
oldCount, _ = oldHandle.Read(oldBuf)
|
||||
newCount, err = newHandle.Read(newBuf)
|
||||
if oldCount != newCount {
|
||||
f2, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
stat1, err := f1.Stat()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
stat2, err := f2.Stat()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
// different sizes, so must have changes
|
||||
if stat1.Size() != stat2.Size() {
|
||||
return true, nil
|
||||
}
|
||||
if !bytes.Equal(oldBuf[:oldCount], newBuf[:newCount]) {
|
||||
|
||||
p1, p2 := make([]byte, 1024), make([]byte, 1024)
|
||||
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, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
var EditLoopAbort = fmt.Errorf("edit Loop aborted by request")
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ func getTemplate(name string) (string, error) {
|
||||
b, err := findTemplate(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
} else if b != nil {
|
||||
}
|
||||
if b != nil {
|
||||
return string(b), nil
|
||||
}
|
||||
if s, ok := AllTemplates[name]; ok {
|
||||
|
||||
+1
-2
@@ -187,7 +187,7 @@ func ParseCommandLine(app *kingpin.Application, args []string) {
|
||||
if _, ok := err.(*Error); ok {
|
||||
log.Errorf("%s", err)
|
||||
panic(Exit{Code: 1})
|
||||
} else {
|
||||
}
|
||||
ctx, _ := app.ParseContext(os.Args[1:])
|
||||
if ctx != nil {
|
||||
app.UsageForContext(ctx)
|
||||
@@ -196,4 +196,3 @@ func ParseCommandLine(app *kingpin.Application, args []string) {
|
||||
panic(Exit{Code: 1})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -76,7 +76,9 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
|
||||
}
|
||||
for _, trans := range []string{"close", "done", "cancel", "start", "stop"} {
|
||||
transMeta := meta.Transitions.Find(trans)
|
||||
if transMeta != nil {
|
||||
if transMeta == nil {
|
||||
continue
|
||||
}
|
||||
issueUpdate := jiradata.IssueUpdate{
|
||||
Transition: transMeta,
|
||||
}
|
||||
@@ -100,7 +102,6 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !globals.Quiet.Value {
|
||||
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
|
||||
|
||||
+1
-3
@@ -124,8 +124,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
|
||||
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
|
||||
})
|
||||
if err == jiracli.EditLoopAbort {
|
||||
if len(results.Issues) > i+1 {
|
||||
if err == jiracli.EditLoopAbort && len(results.Issues) > i+1 {
|
||||
var answer bool
|
||||
survey.AskOne(
|
||||
&survey.Confirm{
|
||||
@@ -140,7 +139,6 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
|
||||
}
|
||||
panic(jiracli.Exit{1})
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -110,8 +110,7 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
|
||||
}
|
||||
|
||||
// need to default the Resolution, usually Fixed works but sometime need Done
|
||||
if opts.Resolution == "" {
|
||||
if resField, ok := transMeta.Fields["resolution"]; ok {
|
||||
if resField, ok := transMeta.Fields["resolution"]; ok && opts.Resolution == "" {
|
||||
for _, allowedValueRaw := range resField.AllowedValues {
|
||||
if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok {
|
||||
if allowedValue["name"] == "Fixed" {
|
||||
@@ -122,7 +121,6 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opts.Overrides["resolution"] = opts.Resolution
|
||||
|
||||
type templateInput struct {
|
||||
|
||||
Reference in New Issue
Block a user