Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ builds:
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
- "386"
archives:
- name_template: >-
{{ .ProjectName }}_
Expand Down
25 changes: 22 additions & 3 deletions cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ func GetConsoleCommand() *cobra.Command {
panic(er)
}

return nil
} else {
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.")
pterm.Println()
PrintHowToUse("console")
return nil
}

Expand Down Expand Up @@ -231,6 +236,11 @@ func GetConsoleCommand() *cobra.Command {
return errs[0]
}

if len(commits) == 0 {
pterm.Warning.Println("The file has no prior version to compare against — nothing to display")
return nil
}

// boot.
app := tui.BuildApplication(commits, Version)
if app == nil {
Expand Down Expand Up @@ -274,7 +284,9 @@ func GetConsoleCommand() *cobra.Command {
return nil
}
}
pterm.Error.Println("too many arguments, expecting two (2)")
pterm.Error.Println("Too many arguments provided, expecting two (2)")
pterm.Println()
PrintHowToUse("console")
return nil
},
}
Expand Down Expand Up @@ -345,9 +357,16 @@ func runGitHistoryConsole(gitPath, filePath, baseCommit string, latest bool, glo
}

// populate history with changes and data
git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)
commitHistory, _ = git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig)

if len(commitHistory) == 0 {
model.SendProgressUpdate("extraction",
"no comparable changes found in history", true, updateChan)
close(updateChan)
return nil, nil
}

if latest {
if latest && len(commitHistory) > 0 {
commitHistory = commitHistory[:1]
}

Expand Down
11 changes: 9 additions & 2 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func GetHTMLReportCommand() *cobra.Command {
return er[0]
}
return writeReportFile(reportFile, report)
} else {
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.")
pterm.Println()
PrintHowToUse("html-report")
return nil
}

} else {
Expand Down Expand Up @@ -274,7 +279,9 @@ func GetHTMLReportCommand() *cobra.Command {
return writeReportFile(reportFile, report)
}
}
pterm.Error.Println("wrong number of arguments, expecting two (2)")
pterm.Error.Println("Too many arguments provided, expecting two (2)")
pterm.Println()
PrintHowToUse("html-report")
return nil
},
}
Expand Down Expand Up @@ -341,7 +348,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath, baseCommit string, latest, useCD
return nil, nil, err
}

if latest {
if latest && len(commitHistory) > 0 {
commitHistory = commitHistory[:1]
}

Expand Down
11 changes: 9 additions & 2 deletions cmd/markdown_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func GetMarkdownReportCommand() *cobra.Command {
return er[0]
}
return writeReportFile(reportFile, report)
} else {
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.")
pterm.Println()
PrintHowToUse("markdown-report")
return nil
}

} else {
Expand Down Expand Up @@ -274,7 +279,9 @@ func GetMarkdownReportCommand() *cobra.Command {
return writeReportFile(reportFile, report)
}
}
pterm.Error.Println("wrong number of arguments, expecting two (2)")
pterm.Error.Println("Too many arguments provided, expecting two (2)")
pterm.Println()
PrintHowToUse("markdown-report")
return nil
},
}
Expand Down Expand Up @@ -315,7 +322,7 @@ func RunGitHistoryMarkdownReport(gitPath, filePath, baseCommit string, latest, u
return nil, nil, err
}

if latest {
if latest && len(commitHistory) > 0 {
commitHistory = commitHistory[:1]
}

Expand Down
13 changes: 10 additions & 3 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func GetReportCommand() *cobra.Command {
jsonBytes, _ := json.MarshalIndent(flat, "", " ")
fmt.Println(string(jsonBytes))
return nil
} else {
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.")
pterm.Println()
PrintHowToUse("report")
return nil
}

} else {
Expand Down Expand Up @@ -231,7 +236,9 @@ func GetReportCommand() *cobra.Command {
return nil
}
}
pterm.Error.Println("wrong number of arguments, expecting two (2)")
pterm.Error.Println("Too many arguments provided, expecting two (2)")
pterm.Println()
PrintHowToUse("report")
return nil
},
}
Expand Down Expand Up @@ -271,7 +278,7 @@ func runGitHistoryReport(gitPath, filePath, baseCommit string, latest bool,
return nil, err
}

if latest {
if latest && len(commitHistory) > 0 {
commitHistory = commitHistory[:1]
}

Expand Down Expand Up @@ -309,7 +316,7 @@ func runGithubHistoryReport(username, repo, filePath, baseCommit string, latest
return nil, errs
}

if latest {
if latest && len(commitHistory) > 1 {
commitHistory = commitHistory[:1]
}

Expand Down
22 changes: 17 additions & 5 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func GetSummaryCommand() *cobra.Command {
}
return nil
} else {
pterm.Error.Println("When using a single argument (URL), only github.com is supported at this time. Please provide a github url")
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.")
return nil
}

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

if latest {
if latest && len(commitHistory) > 1 {
commitHistory = commitHistory[:1]
}

Expand Down Expand Up @@ -441,9 +441,17 @@ func runGitHistorySummary(gitPath, filePath, baseCommit string, latest bool,
}

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

if latest {
if len(commitHistory) == 0 {
model.SendProgressUpdate("extraction",
"no comparable changes found in history", true, updateChan)
close(updateChan)
pterm.Warning.Println("The file has no prior version to compare against — nothing to report")
return nil
}

if latest && len(commitHistory) > 0 {
commitHistory = commitHistory[:1]
}

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

if len(commitHistory) == 0 {
pterm.Info.Println("Nothing to report")
return nil
}
if len(commitHistory) == 1 && commitHistory[0].Changes == nil {
pterm.Success.Println("No changes found between specifications")
return nil
Expand Down
5 changes: 4 additions & 1 deletion git/read_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
}
}
if len(oldBits) == 0 && len(newBits) > 0 {
model.SendProgressWarning("building models",
fmt.Sprintf("Commit %s is the first version of '%s' — no prior version to compare against, skipping",
commitHistory[c].Hash, commitHistory[c].FilePath), progressChan)
newDoc, err = libopenapi.NewDocumentWithConfiguration(newBits, docConfig)
if err != nil {
model.SendFatalError("building models", fmt.Sprintf("unable to create OpenAPI modified document: %s", err.Error()), errorChan)
Expand All @@ -300,7 +303,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
if oldDoc != nil {
commitHistory[c].OldDocument = oldDoc
}
if (c == len(commitHistory)-1) || commitHistory[c].Changes != nil {
if commitHistory[c].Changes != nil {
cleaned = append(cleaned, commitHistory[c])
}
}
Expand Down
50 changes: 14 additions & 36 deletions git/read_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package git

import (
"context"
"testing"
"time"

"github.com/pb33f/openapi-changes/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCheckLocalRepoAvailable(t *testing.T) {
Expand All @@ -18,40 +17,19 @@ func TestCheckLocalRepoAvailable(t *testing.T) {
}

func TestExtractHistoryFromFile(t *testing.T) {

c := make(chan *model.ProgressUpdate)
e := make(chan model.ProgressError)
d := make(chan bool)
go func() {
iterations := 0
for iterations < 26 {
select {
case <-c:

iterations++
case <-e:

iterations++
}
}
d <- true
}()

// this shit times out in the pipeline (damn you github runners)
ctx, cncl := context.WithTimeout(context.Background(), 5*time.Second)
history, _ := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1)
defer cncl()

select {

case <-d:
assert.NotNil(t, history)
assert.Equal(t, "A lot of clean up, after consuming the tool as a library.", history[len(history)-1].Message)
return
case <-ctx.Done():
return
}

c := make(chan *model.ProgressUpdate, 32)
e := make(chan model.ProgressError, 32)

history, errs := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1)
require.Empty(t, errs)
require.NotEmpty(t, history)

oldest := history[len(history)-1]
assert.Equal(t, "./", oldest.RepoDirectory)
assert.Equal(t, "read_local.go", oldest.FilePath)
assert.NotEmpty(t, oldest.Hash)
assert.NotEmpty(t, oldest.Message)
assert.False(t, oldest.CommitDate.IsZero())
}

func TestExtractHistoryFromFile_Fail(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/gdamore/tcell/v2 v2.13.4
github.com/google/uuid v1.6.0
github.com/pb33f/libopenapi v0.30.0
github.com/pb33f/libopenapi v0.34.2
github.com/pmezard/go-difflib v1.0.0
github.com/pterm/pterm v0.12.82
github.com/rivo/tview v0.42.0
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
go.yaml.in/yaml/v4 v4.0.0-rc.3
go.yaml.in/yaml/v4 v4.0.0-rc.4
golang.org/x/text v0.32.0
)

Expand All @@ -30,12 +30,13 @@ require (
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pb33f/jsonpath v0.7.0 // indirect
github.com/pb33f/jsonpath v0.8.1 // indirect
github.com/pb33f/ordered-map/v2 v2.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.37.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pb33f/jsonpath v0.7.0 h1:3oG6yu1RqNoMZpqnRjBMqi8fSIXWoDAKDrsB0QGTcoU=
github.com/pb33f/jsonpath v0.7.0/go.mod h1:/+JlSIjWA2ijMVYGJ3IQPF4Q1nLMYbUTYNdk0exCDPQ=
github.com/pb33f/libopenapi v0.30.0 h1:F5VmLZH/pJ7Cybe48Ya/5CA3TWE6XusR4KxrlrHA4R8=
github.com/pb33f/libopenapi v0.30.0/go.mod h1:4MP76dnaTMY+DM+bRhKBneAIhVISEEZM6G6sd7A9pus=
github.com/pb33f/jsonpath v0.8.1 h1:84C6QRyx6HcSm6PZnsMpcqYot3IsZ+m0n95+0NbBbvs=
github.com/pb33f/jsonpath v0.8.1/go.mod h1:zBV5LJW4OQOPatmQE2QdKpGQJvhDTlE5IEj6ASaRNTo=
github.com/pb33f/libopenapi v0.34.2 h1:ValgPCDIVSC1IzPY7rY6GPOslCzaAWEml40IuFGZXOc=
github.com/pb33f/libopenapi v0.34.2/go.mod h1:YOP20KzYe3mhE5301aQzJtzQ9MnvhABBGO7RMttA4V4=
github.com/pb33f/ordered-map/v2 v2.3.0 h1:k2OhVEQkhTCQMhAicQ3Z6iInzoZNQ7L9MVomwKBZ5WQ=
github.com/pb33f/ordered-map/v2 v2.3.0/go.mod h1:oe5ue+6ZNhy7QN9cPZvPA23Hx0vMHnNVeMg4fGdCANw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -106,8 +106,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 h1:1wqE9dj9NpSm04INVsJhhEUzhuDVjbcyKH91sVyPATw=
Expand All @@ -121,6 +121,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
Loading
Loading