Skip to content

Commit f956e1b

Browse files
committed
Addressing comments from phil sturgeon
argument issues and initial commit explosions cleaned up.
1 parent 88c786e commit f956e1b

9 files changed

Lines changed: 97 additions & 61 deletions

File tree

cmd/console.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ func GetConsoleCommand() *cobra.Command {
177177
panic(er)
178178
}
179179

180+
return nil
181+
} else {
182+
pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.")
183+
pterm.Println()
184+
PrintHowToUse("console")
180185
return nil
181186
}
182187

@@ -231,6 +236,11 @@ func GetConsoleCommand() *cobra.Command {
231236
return errs[0]
232237
}
233238

239+
if len(commits) == 0 {
240+
pterm.Warning.Println("The file has no prior version to compare against — nothing to display")
241+
return nil
242+
}
243+
234244
// boot.
235245
app := tui.BuildApplication(commits, Version)
236246
if app == nil {
@@ -274,7 +284,9 @@ func GetConsoleCommand() *cobra.Command {
274284
return nil
275285
}
276286
}
277-
pterm.Error.Println("too many arguments, expecting two (2)")
287+
pterm.Error.Println("Too many arguments provided, expecting two (2)")
288+
pterm.Println()
289+
PrintHowToUse("console")
278290
return nil
279291
},
280292
}
@@ -345,9 +357,16 @@ func runGitHistoryConsole(gitPath, filePath, baseCommit string, latest bool, glo
345357
}
346358

347359
// populate history with changes and data
348-
git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)
360+
commitHistory, _ = git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)
361+
362+
if len(commitHistory) == 0 {
363+
model.SendProgressUpdate("extraction",
364+
"no comparable changes found in history", true, updateChan)
365+
close(updateChan)
366+
return nil, nil
367+
}
349368

350-
if latest {
369+
if latest && len(commitHistory) > 0 {
351370
commitHistory = commitHistory[:1]
352371
}
353372

cmd/html_report.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ func GetHTMLReportCommand() *cobra.Command {
190190
return er[0]
191191
}
192192
return writeReportFile(reportFile, report)
193+
} else {
194+
pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.")
195+
pterm.Println()
196+
PrintHowToUse("html-report")
197+
return nil
193198
}
194199

195200
} else {
@@ -274,7 +279,9 @@ func GetHTMLReportCommand() *cobra.Command {
274279
return writeReportFile(reportFile, report)
275280
}
276281
}
277-
pterm.Error.Println("wrong number of arguments, expecting two (2)")
282+
pterm.Error.Println("Too many arguments provided, expecting two (2)")
283+
pterm.Println()
284+
PrintHowToUse("html-report")
278285
return nil
279286
},
280287
}
@@ -341,7 +348,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath, baseCommit string, latest, useCD
341348
return nil, nil, err
342349
}
343350

344-
if latest {
351+
if latest && len(commitHistory) > 0 {
345352
commitHistory = commitHistory[:1]
346353
}
347354

cmd/markdown_report.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ func GetMarkdownReportCommand() *cobra.Command {
190190
return er[0]
191191
}
192192
return writeReportFile(reportFile, report)
193+
} else {
194+
pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.")
195+
pterm.Println()
196+
PrintHowToUse("markdown-report")
197+
return nil
193198
}
194199

195200
} else {
@@ -274,7 +279,9 @@ func GetMarkdownReportCommand() *cobra.Command {
274279
return writeReportFile(reportFile, report)
275280
}
276281
}
277-
pterm.Error.Println("wrong number of arguments, expecting two (2)")
282+
pterm.Error.Println("Too many arguments provided, expecting two (2)")
283+
pterm.Println()
284+
PrintHowToUse("markdown-report")
278285
return nil
279286
},
280287
}
@@ -315,7 +322,7 @@ func RunGitHistoryMarkdownReport(gitPath, filePath, baseCommit string, latest, u
315322
return nil, nil, err
316323
}
317324

318-
if latest {
325+
if latest && len(commitHistory) > 0 {
319326
commitHistory = commitHistory[:1]
320327
}
321328

cmd/report.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func GetReportCommand() *cobra.Command {
126126
jsonBytes, _ := json.MarshalIndent(flat, "", " ")
127127
fmt.Println(string(jsonBytes))
128128
return nil
129+
} else {
130+
pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.")
131+
pterm.Println()
132+
PrintHowToUse("report")
133+
return nil
129134
}
130135

131136
} else {
@@ -231,7 +236,9 @@ func GetReportCommand() *cobra.Command {
231236
return nil
232237
}
233238
}
234-
pterm.Error.Println("wrong number of arguments, expecting two (2)")
239+
pterm.Error.Println("Too many arguments provided, expecting two (2)")
240+
pterm.Println()
241+
PrintHowToUse("report")
235242
return nil
236243
},
237244
}
@@ -271,7 +278,7 @@ func runGitHistoryReport(gitPath, filePath, baseCommit string, latest bool,
271278
return nil, err
272279
}
273280

274-
if latest {
281+
if latest && len(commitHistory) > 0 {
275282
commitHistory = commitHistory[:1]
276283
}
277284

@@ -309,7 +316,7 @@ func runGithubHistoryReport(username, repo, filePath, baseCommit string, latest
309316
return nil, errs
310317
}
311318

312-
if latest {
319+
if latest && len(commitHistory) > 1 {
313320
commitHistory = commitHistory[:1]
314321
}
315322

cmd/summary.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func GetSummaryCommand() *cobra.Command {
201201
}
202202
return nil
203203
} else {
204-
pterm.Error.Println("When using a single argument (URL), only github.com is supported at this time. Please provide a github url")
204+
pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.")
205205
return nil
206206
}
207207

@@ -286,7 +286,7 @@ func GetSummaryCommand() *cobra.Command {
286286
return nil
287287
}
288288
}
289-
pterm.Error.Println("Invalid arguments")
289+
pterm.Error.Println("Too many arguments provided, expecting two (2)")
290290
pterm.Println()
291291
PrintHowToUse("summary")
292292
return nil
@@ -404,7 +404,7 @@ func runGithubHistorySummary(username, repo, filePath, baseCommit string, latest
404404
commitHistory, _ := git.ProcessGithubRepo(username, repo, filePath, baseCommit, progressChan, errorChan,
405405
false, limit, limitTime, base, remote, extRefs, breakingConfig)
406406

407-
if latest {
407+
if latest && len(commitHistory) > 1 {
408408
commitHistory = commitHistory[:1]
409409
}
410410

@@ -441,9 +441,17 @@ func runGitHistorySummary(gitPath, filePath, baseCommit string, latest bool,
441441
}
442442

443443
// populate history with changes and data
444-
git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)
444+
commitHistory, _ = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)
445445

446-
if latest {
446+
if len(commitHistory) == 0 {
447+
model.SendProgressUpdate("extraction",
448+
"no comparable changes found in history", true, updateChan)
449+
close(updateChan)
450+
pterm.Warning.Println("The file has no prior version to compare against — nothing to report")
451+
return nil
452+
}
453+
454+
if latest && len(commitHistory) > 0 {
447455
commitHistory = commitHistory[:1]
448456
}
449457

@@ -461,6 +469,10 @@ func printSummaryDetails(commitHistory []*model.Commit, markdown, errOnDiff bool
461469
pterm.Println()
462470
errorStyle := pterm.NewStyle(pterm.FgLightRed, pterm.Italic)
463471

472+
if len(commitHistory) == 0 {
473+
pterm.Info.Println("Nothing to report")
474+
return nil
475+
}
464476
if len(commitHistory) == 1 && commitHistory[0].Changes == nil {
465477
pterm.Success.Println("No changes found between specifications")
466478
return nil

git/read_local.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
287287
}
288288
}
289289
if len(oldBits) == 0 && len(newBits) > 0 {
290+
model.SendProgressWarning("building models",
291+
fmt.Sprintf("Commit %s is the first version of '%s' — no prior version to compare against, skipping",
292+
commitHistory[c].Hash, commitHistory[c].FilePath), progressChan)
290293
newDoc, err = libopenapi.NewDocumentWithConfiguration(newBits, docConfig)
291294
if err != nil {
292295
model.SendFatalError("building models", fmt.Sprintf("unable to create OpenAPI modified document: %s", err.Error()), errorChan)
@@ -300,7 +303,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
300303
if oldDoc != nil {
301304
commitHistory[c].OldDocument = oldDoc
302305
}
303-
if (c == len(commitHistory)-1) || commitHistory[c].Changes != nil {
306+
if commitHistory[c].Changes != nil {
304307
cleaned = append(cleaned, commitHistory[c])
305308
}
306309
}

git/read_local_test.go

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package git
55

66
import (
7-
"context"
87
"testing"
9-
"time"
108

119
"github.com/pb33f/openapi-changes/model"
1210
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
1312
)
1413

1514
func TestCheckLocalRepoAvailable(t *testing.T) {
@@ -18,40 +17,19 @@ func TestCheckLocalRepoAvailable(t *testing.T) {
1817
}
1918

2019
func TestExtractHistoryFromFile(t *testing.T) {
21-
22-
c := make(chan *model.ProgressUpdate)
23-
e := make(chan model.ProgressError)
24-
d := make(chan bool)
25-
go func() {
26-
iterations := 0
27-
for iterations < 26 {
28-
select {
29-
case <-c:
30-
31-
iterations++
32-
case <-e:
33-
34-
iterations++
35-
}
36-
}
37-
d <- true
38-
}()
39-
40-
// this shit times out in the pipeline (damn you github runners)
41-
ctx, cncl := context.WithTimeout(context.Background(), 5*time.Second)
42-
history, _ := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1)
43-
defer cncl()
44-
45-
select {
46-
47-
case <-d:
48-
assert.NotNil(t, history)
49-
assert.Equal(t, "A lot of clean up, after consuming the tool as a library.", history[len(history)-1].Message)
50-
return
51-
case <-ctx.Done():
52-
return
53-
}
54-
20+
c := make(chan *model.ProgressUpdate, 32)
21+
e := make(chan model.ProgressError, 32)
22+
23+
history, errs := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1)
24+
require.Empty(t, errs)
25+
require.NotEmpty(t, history)
26+
27+
oldest := history[len(history)-1]
28+
assert.Equal(t, "./", oldest.RepoDirectory)
29+
assert.Equal(t, "read_local.go", oldest.FilePath)
30+
assert.NotEmpty(t, oldest.Hash)
31+
assert.NotEmpty(t, oldest.Message)
32+
assert.False(t, oldest.CommitDate.IsZero())
5533
}
5634

5735
func TestExtractHistoryFromFile_Fail(t *testing.T) {

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ require (
66
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
77
github.com/gdamore/tcell/v2 v2.13.4
88
github.com/google/uuid v1.6.0
9-
github.com/pb33f/libopenapi v0.30.0
9+
github.com/pb33f/libopenapi v0.34.2
1010
github.com/pmezard/go-difflib v1.0.0
1111
github.com/pterm/pterm v0.12.82
1212
github.com/rivo/tview v0.42.0
1313
github.com/spf13/cobra v1.10.2
1414
github.com/stretchr/testify v1.11.1
15-
go.yaml.in/yaml/v4 v4.0.0-rc.3
15+
go.yaml.in/yaml/v4 v4.0.0-rc.4
1616
golang.org/x/text v0.32.0
1717
)
1818

@@ -30,12 +30,13 @@ require (
3030
github.com/lithammer/fuzzysearch v1.1.8 // indirect
3131
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
3232
github.com/mattn/go-runewidth v0.0.16 // indirect
33-
github.com/pb33f/jsonpath v0.7.0 // indirect
33+
github.com/pb33f/jsonpath v0.8.1 // indirect
3434
github.com/pb33f/ordered-map/v2 v2.3.0 // indirect
3535
github.com/rivo/uniseg v0.4.7 // indirect
3636
github.com/spf13/pflag v1.0.9 // indirect
3737
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
3838
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
39+
golang.org/x/sync v0.19.0 // indirect
3940
golang.org/x/sys v0.38.0 // indirect
4041
golang.org/x/term v0.37.0 // indirect
4142
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

go.sum

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
6262
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
6363
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
6464
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
65-
github.com/pb33f/jsonpath v0.7.0 h1:3oG6yu1RqNoMZpqnRjBMqi8fSIXWoDAKDrsB0QGTcoU=
66-
github.com/pb33f/jsonpath v0.7.0/go.mod h1:/+JlSIjWA2ijMVYGJ3IQPF4Q1nLMYbUTYNdk0exCDPQ=
67-
github.com/pb33f/libopenapi v0.30.0 h1:F5VmLZH/pJ7Cybe48Ya/5CA3TWE6XusR4KxrlrHA4R8=
68-
github.com/pb33f/libopenapi v0.30.0/go.mod h1:4MP76dnaTMY+DM+bRhKBneAIhVISEEZM6G6sd7A9pus=
65+
github.com/pb33f/jsonpath v0.8.1 h1:84C6QRyx6HcSm6PZnsMpcqYot3IsZ+m0n95+0NbBbvs=
66+
github.com/pb33f/jsonpath v0.8.1/go.mod h1:zBV5LJW4OQOPatmQE2QdKpGQJvhDTlE5IEj6ASaRNTo=
67+
github.com/pb33f/libopenapi v0.34.2 h1:ValgPCDIVSC1IzPY7rY6GPOslCzaAWEml40IuFGZXOc=
68+
github.com/pb33f/libopenapi v0.34.2/go.mod h1:YOP20KzYe3mhE5301aQzJtzQ9MnvhABBGO7RMttA4V4=
6969
github.com/pb33f/ordered-map/v2 v2.3.0 h1:k2OhVEQkhTCQMhAicQ3Z6iInzoZNQ7L9MVomwKBZ5WQ=
7070
github.com/pb33f/ordered-map/v2 v2.3.0/go.mod h1:oe5ue+6ZNhy7QN9cPZvPA23Hx0vMHnNVeMg4fGdCANw=
7171
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -106,8 +106,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
106106
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
107107
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
108108
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
109-
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
110-
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
109+
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
110+
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
111111
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
112112
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
113113
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 h1:1wqE9dj9NpSm04INVsJhhEUzhuDVjbcyKH91sVyPATw=
@@ -121,6 +121,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
121121
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
122122
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
123123
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
124+
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
125+
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
124126
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
125127
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
126128
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

0 commit comments

Comments
 (0)