Skip to content

Commit 31c113d

Browse files
committed
all: unindent some code
1 parent 9bcdcc1 commit 31c113d

File tree

7 files changed

+136
-138
lines changed

7 files changed

+136
-138
lines changed

issue.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,24 @@ func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, iss
255255
}
256256
defer resp.Body.Close()
257257

258-
if resp.StatusCode == 200 {
259-
results := &jiradata.CreateMeta{}
260-
err = json.NewDecoder(resp.Body).Decode(results)
261-
if err != nil {
262-
return nil, err
258+
if resp.StatusCode != 200 {
259+
return nil, responseError(resp)
260+
}
261+
results := &jiradata.CreateMeta{}
262+
if err := json.NewDecoder(resp.Body).Decode(results); err != nil {
263+
return nil, err
264+
}
265+
for _, project := range results.Projects {
266+
if project.Key != projectKey {
267+
continue
263268
}
264-
for _, project := range results.Projects {
265-
if project.Key == projectKey {
266-
for _, issueType := range project.IssueTypes {
267-
if issueType.Name == issueTypeName {
268-
return issueType, nil
269-
}
270-
}
269+
for _, issueType := range project.IssueTypes {
270+
if issueType.Name == issueTypeName {
271+
return issueType, nil
271272
}
272273
}
273-
return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
274274
}
275-
return nil, responseError(resp)
275+
return nil, fmt.Errorf("project %s and IssueType %s not found", projectKey, issueTypeName)
276276
}
277277

278278
type LinkIssueProvider interface {

jiracli/cli.go

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -150,43 +150,39 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
150150
app.Flag("user", "user name used within the Jira service").Short('u').SetValue(&globals.User)
151151
app.Flag("login", "login name that corresponds to the user used for authentication").SetValue(&globals.Login)
152152

153-
o = o.WithPreCallback(
154-
func(req *http.Request) (*http.Request, error) {
155-
if globals.AuthMethod() == "api-token" {
156-
// need to set basic auth header with user@domain:api-token
157-
token := globals.GetPass()
158-
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
159-
req.Header.Add("Authorization", authHeader)
160-
}
161-
return req, nil
162-
},
163-
)
164-
165-
o = o.WithPostCallback(
166-
func(req *http.Request, resp *http.Response) (*http.Response, error) {
167-
if globals.AuthMethod() == "session" {
168-
authUser := resp.Header.Get("X-Ausername")
169-
if authUser == "" || authUser == "anonymous" {
170-
// preserve the --quiet value, we need to temporarily disable it so
171-
// the normal login output is surpressed
172-
defer func(quiet bool) {
173-
globals.Quiet.Value = quiet
174-
}(globals.Quiet.Value)
175-
globals.Quiet.Value = true
176-
177-
// we are not logged in, so force login now by running the "login" command
178-
app.Parse([]string{"login"})
179-
180-
// rerun the original request
181-
return o.Do(req)
182-
}
183-
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
184-
globals.SetPass("")
153+
o = o.WithPreCallback(func(req *http.Request) (*http.Request, error) {
154+
if globals.AuthMethod() == "api-token" {
155+
// need to set basic auth header with user@domain:api-token
156+
token := globals.GetPass()
157+
authHeader := fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", globals.Login.Value, token))))
158+
req.Header.Add("Authorization", authHeader)
159+
}
160+
return req, nil
161+
})
162+
163+
o = o.WithPostCallback(func(req *http.Request, resp *http.Response) (*http.Response, error) {
164+
if globals.AuthMethod() == "session" {
165+
authUser := resp.Header.Get("X-Ausername")
166+
if authUser == "" || authUser == "anonymous" {
167+
// preserve the --quiet value, we need to temporarily disable it so
168+
// the normal login output is surpressed
169+
defer func(quiet bool) {
170+
globals.Quiet.Value = quiet
171+
}(globals.Quiet.Value)
172+
globals.Quiet.Value = true
173+
174+
// we are not logged in, so force login now by running the "login" command
175+
app.Parse([]string{"login"})
176+
177+
// rerun the original request
185178
return o.Do(req)
186179
}
187-
return resp, nil
188-
},
189-
)
180+
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
181+
globals.SetPass("")
182+
return o.Do(req)
183+
}
184+
return resp, nil
185+
})
190186

191187
for _, command := range globalCommandRegistry {
192188
copy := command
@@ -238,14 +234,12 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
238234
copy.Entry.UsageFunc(fig, cmd)
239235
}
240236

241-
cmd.Action(
242-
func(_ *kingpin.ParseContext) error {
243-
if logging.GetLevel("") > logging.DEBUG {
244-
o = o.WithTrace(true)
245-
}
246-
return copy.Entry.ExecuteFunc(o, &globals)
247-
},
248-
)
237+
cmd.Action(func(_ *kingpin.ParseContext) error {
238+
if logging.GetLevel("") > logging.DEBUG {
239+
o = o.WithTrace(true)
240+
}
241+
return copy.Entry.ExecuteFunc(o, &globals)
242+
})
249243
}
250244
}
251245

@@ -321,35 +315,42 @@ func (o *CommonOptions) editFile(fileName string) (changes bool, err error) {
321315
}
322316

323317
// now we just need to diff the files to see if there are any changes
324-
var oldHandle, newHandle *os.File
325-
var oldStat, newStat os.FileInfo
326-
if oldHandle, err = os.Open(tmpFileNameOrig); err == nil {
327-
if newHandle, err = os.Open(fileName); err == nil {
328-
if oldStat, err = oldHandle.Stat(); err == nil {
329-
if newStat, err = newHandle.Stat(); err == nil {
330-
// different sizes, so must have changes
331-
if oldStat.Size() != newStat.Size() {
332-
return true, err
333-
}
334-
oldBuf, newBuf := make([]byte, 1024), make([]byte, 1024)
335-
var oldCount, newCount int
336-
// loop though 1024 bytes at a time comparing the buffers for changes
337-
for err != io.EOF {
338-
oldCount, _ = oldHandle.Read(oldBuf)
339-
newCount, err = newHandle.Read(newBuf)
340-
if oldCount != newCount {
341-
return true, nil
342-
}
343-
if !bytes.Equal(oldBuf[:oldCount], newBuf[:newCount]) {
344-
return true, nil
345-
}
346-
}
347-
return false, nil
348-
}
349-
}
318+
f1, err := os.Open(tmpFileNameOrig)
319+
if err != nil {
320+
return false, err
321+
}
322+
f2, err := os.Open(fileName)
323+
if err != nil {
324+
return false, err
325+
}
326+
327+
stat1, err := f1.Stat()
328+
if err != nil {
329+
return false, err
330+
}
331+
stat2, err := f2.Stat()
332+
if err != nil {
333+
return false, err
334+
}
335+
// different sizes, so must have changes
336+
if stat1.Size() != stat2.Size() {
337+
return true, nil
338+
}
339+
340+
p1, p2 := make([]byte, 1024), make([]byte, 1024)
341+
var n1, n2 int
342+
// loop though 1024 bytes at a time comparing the buffers for changes
343+
for err != io.EOF {
344+
n1, _ = f1.Read(p1)
345+
n2, err = f2.Read(p2)
346+
if n1 != n2 {
347+
return true, nil
348+
}
349+
if !bytes.Equal(p1[:n1], p2[:n2]) {
350+
return true, nil
350351
}
351352
}
352-
return false, err
353+
return false, nil
353354
}
354355

355356
var EditLoopAbort = fmt.Errorf("edit Loop aborted by request")

jiracli/templates.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func getTemplate(name string) (string, error) {
4444
b, err := findTemplate(name)
4545
if err != nil {
4646
return "", err
47-
} else if b != nil {
47+
}
48+
if b != nil {
4849
return string(b), nil
4950
}
5051
if s, ok := AllTemplates[name]; ok {

jiracli/usage.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,12 @@ func ParseCommandLine(app *kingpin.Application, args []string) {
187187
if _, ok := err.(*Error); ok {
188188
log.Errorf("%s", err)
189189
panic(Exit{Code: 1})
190-
} else {
191-
ctx, _ := app.ParseContext(os.Args[1:])
192-
if ctx != nil {
193-
app.UsageForContext(ctx)
194-
}
195-
log.Errorf("Invalid Usage: %s", err)
196-
panic(Exit{Code: 1})
197190
}
191+
ctx, _ := app.ParseContext(os.Args[1:])
192+
if ctx != nil {
193+
app.UsageForContext(ctx)
194+
}
195+
log.Errorf("Invalid Usage: %s", err)
196+
panic(Exit{Code: 1})
198197
}
199198
}

jiracmd/dup.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,31 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
7676
}
7777
for _, trans := range []string{"close", "done", "cancel", "start", "stop"} {
7878
transMeta := meta.Transitions.Find(trans)
79-
if transMeta != nil {
80-
issueUpdate := jiradata.IssueUpdate{
81-
Transition: transMeta,
82-
}
83-
resolution := defaultResolution(transMeta)
84-
if resolution != "" {
85-
issueUpdate.Fields = map[string]interface{}{
86-
"resolution": map[string]interface{}{
87-
"name": resolution,
88-
},
89-
}
90-
}
91-
if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
92-
return err
93-
}
94-
if trans != "start" {
95-
break
96-
}
97-
// if we are here then we must be stopping, so need to reset the meta
98-
meta, err = jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
99-
if err != nil {
100-
return err
79+
if transMeta == nil {
80+
continue
81+
}
82+
issueUpdate := jiradata.IssueUpdate{
83+
Transition: transMeta,
84+
}
85+
resolution := defaultResolution(transMeta)
86+
if resolution != "" {
87+
issueUpdate.Fields = map[string]interface{}{
88+
"resolution": map[string]interface{}{
89+
"name": resolution,
90+
},
10191
}
10292
}
93+
if err = jira.TransitionIssue(o, globals.Endpoint.Value, opts.InwardIssue.Key, &issueUpdate); err != nil {
94+
return err
95+
}
96+
if trans != "start" {
97+
break
98+
}
99+
// if we are here then we must be stopping, so need to reset the meta
100+
meta, err = jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
101+
if err != nil {
102+
return err
103+
}
103104
}
104105

105106
if !globals.Quiet.Value {

jiracmd/edit.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,20 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
124124
err = jiracli.EditLoop(&opts.CommonOptions, &input, &issueUpdate, func() error {
125125
return jira.EditIssue(o, globals.Endpoint.Value, issueData.Key, &issueUpdate)
126126
})
127-
if err == jiracli.EditLoopAbort {
128-
if len(results.Issues) > i+1 {
129-
var answer bool
130-
survey.AskOne(
131-
&survey.Confirm{
132-
Message: fmt.Sprintf("Continue to edit next issue %s?", results.Issues[i+1].Key),
133-
Default: true,
134-
},
135-
&answer,
136-
nil,
137-
)
138-
if answer {
139-
continue
140-
}
141-
panic(jiracli.Exit{1})
127+
if err == jiracli.EditLoopAbort && len(results.Issues) > i+1 {
128+
var answer bool
129+
survey.AskOne(
130+
&survey.Confirm{
131+
Message: fmt.Sprintf("Continue to edit next issue %s?", results.Issues[i+1].Key),
132+
Default: true,
133+
},
134+
&answer,
135+
nil,
136+
)
137+
if answer {
138+
continue
142139
}
140+
panic(jiracli.Exit{1})
143141
}
144142
if err != nil {
145143
return err

jiracmd/transition.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
110110
}
111111

112112
// need to default the Resolution, usually Fixed works but sometime need Done
113-
if opts.Resolution == "" {
114-
if resField, ok := transMeta.Fields["resolution"]; ok {
115-
for _, allowedValueRaw := range resField.AllowedValues {
116-
if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok {
117-
if allowedValue["name"] == "Fixed" {
118-
opts.Resolution = "Fixed"
119-
} else if allowedValue["name"] == "Done" {
120-
opts.Resolution = "Done"
121-
}
113+
if resField, ok := transMeta.Fields["resolution"]; ok && opts.Resolution == "" {
114+
for _, allowedValueRaw := range resField.AllowedValues {
115+
if allowedValue, ok := allowedValueRaw.(map[string]interface{}); ok {
116+
if allowedValue["name"] == "Fixed" {
117+
opts.Resolution = "Fixed"
118+
} else if allowedValue["name"] == "Done" {
119+
opts.Resolution = "Done"
122120
}
123121
}
124122
}

0 commit comments

Comments
 (0)