Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.71 #184

Merged
merged 10 commits into from
Feb 14, 2025
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
15 changes: 14 additions & 1 deletion builder/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,25 @@ func DigIntoTreeNode[T any](parent *model.TreeNode, field reflect.Value, label s
}
}

func transformLabel(in string) string {
switch in {
case "ONEOF":
return "OneOf"
case "ALLOF":
return "AllOf"
case "ANYOF":
return "AnyOf"
default:
return in
}
}

func DigIntoTreeNodeSlice[T any](parent *model.TreeNode, field reflect.Value, label string) {
if !field.IsZero() {
for k := 0; k < field.Len(); k++ {
f := field.Index(k)
e := &model.TreeNode{
TitleString: label,
TitleString: transformLabel(label),
Key: uuid.New().String(),
IsLeaf: false,
Selectable: false,
Expand Down
2 changes: 1 addition & 1 deletion cmd/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func PrintHowToUse(command string) {
cmd.Print(command)
title.Println(" . sample-specs/petstorev3.json")
fmt.Println()
title.Println(">> diff old / new files")
title.Println(">> diff old / modified files")
desc.Println("supply paths to the left (original) and right (modified) OpenAPI specs")
fmt.Println()
fmt.Print("openapi-changes ")
Expand Down
7 changes: 6 additions & 1 deletion cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func runLeftRightCompare(left, right string, updateChan chan *model.ProgressUpda
commits := []*model.Commit{
{
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
Message: fmt.Sprintf("Original: %s, Modified: %s", left, right),
CommitDate: time.Now(),
Data: rightBytes,
},
Expand All @@ -382,6 +382,11 @@ func runLeftRightCompare(left, right string, updateChan chan *model.ProgressUpda
}
close(updateChan)
close(errorChan)

if len(commits) == 1 && commits[0].Changes == nil {
pterm.Success.Println("No changes found between specifications")
return nil
}
app := tui.BuildApplication(commits, Version)
if err := app.Run(); err != nil {
return []error{err}
Expand Down
21 changes: 12 additions & 9 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func GetHTMLReportCommand() *cobra.Command {
limitFlag, _ := cmd.Flags().GetInt("limit")
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
remoteFlag, _ := cmd.Flags().GetBool("remote")
reportFile, _ := cmd.Flags().GetString("report-file")

if noColorFlag {
pterm.DisableStyling()
Expand Down Expand Up @@ -179,12 +180,12 @@ func GetHTMLReportCommand() *cobra.Command {
return er[0]
}
if len(report) > 0 {
err = os.WriteFile("report.html", report, 0664)
err = os.WriteFile(reportFile, report, 0664)
if err != nil {
pterm.Error.Println(err.Error())
return err
}
pterm.Success.Printf("%s report written to file 'report.html' (%s)", specUrl.String(),
pterm.Success.Printf("%s report written to file '%s' (%s)", reportFile, specUrl.String(),
index.HumanFileSize(float64(len(report))))
pterm.Println()
pterm.Println()
Expand Down Expand Up @@ -237,12 +238,12 @@ func GetHTMLReportCommand() *cobra.Command {
return er[0]
}

err = os.WriteFile("report.html", report, 0744)
err = os.WriteFile(reportFile, report, 0744)
if err != nil {
pterm.Error.Println(err.Error())
return err
}
pterm.Success.Printf("report written to file 'report.html' (%dkb)", len(report)/1024)
pterm.Success.Printf("report written to file '%s' (%dkb)", reportFile, len(report)/1024)
pterm.Println()
pterm.Println()
return nil
Expand Down Expand Up @@ -273,8 +274,8 @@ func GetHTMLReportCommand() *cobra.Command {
return errors.New("unable to process specifications")
}

err = os.WriteFile("report.html", report, 0744)
pterm.Success.Printf("report written to file 'report.html' (%dkb)", len(report)/1024)
err = os.WriteFile(reportFile, report, 0744)
pterm.Success.Printf("report written to file '%s' (%dkb)", reportFile, len(report)/1024)
pterm.Println()
pterm.Println()
return nil
Expand All @@ -286,6 +287,7 @@ func GetHTMLReportCommand() *cobra.Command {
}
cmd.Flags().BoolP("no-color", "n", false, "Disable color and style output (very useful for CI/CD)")
cmd.Flags().BoolP("use-cdn", "c", false, "Use CDN for CSS and JS delivery instead of bundling inline")
cmd.Flags().StringP("report-file", "", "report.html", "The name of the HTML report file (defaults to 'report.html')")

return cmd
}
Expand Down Expand Up @@ -414,15 +416,16 @@ func RunLeftRightHTMLReport(left, right string, useCDN bool,
commits := []*model.Commit{
{
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
Message: fmt.Sprintf("Original: %s. Modified: %s", left, right),
CommitDate: time.Now(),
Data: rightBytes,
},
{
FilePath: right,
}, {
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("Original file: %s", left),
CommitDate: time.Now(),
Data: leftBytes,
FilePath: left,
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func runLeftRightReport(left, right string,
commits := []*model.Commit{
{
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
Message: fmt.Sprintf("Original: %s, Modified: %s, ", left, right),
CommitDate: time.Now(),
Data: rightBytes,
},
Expand Down
16 changes: 13 additions & 3 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ func GetSummaryCommand() *cobra.Command {
case err := <-errorChan:
if err.Fatal {
if !noColorFlag {
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
spinner.Stop()
if spinner != nil {
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
spinner.Stop()
} else {
pterm.Error.Printf("Stopped: %s", err.Message)
}

}
} else {
warnings = append(warnings, err.Message)
Expand Down Expand Up @@ -337,7 +342,7 @@ func runLeftRightSummary(left, right string, updateChan chan *model.ProgressUpda
commits := []*model.Commit{
{
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
Message: fmt.Sprintf("Original: %s, Modified: %s, ", left, right),
CommitDate: time.Now(),
Data: rightBytes,
},
Expand Down Expand Up @@ -432,6 +437,11 @@ func printSummaryDetails(commitHistory []*model.Commit, markdown bool) error {
pterm.Println()
errorStyle := pterm.NewStyle(pterm.FgLightRed, pterm.Italic)

if len(commitHistory) == 1 && commitHistory[0].Changes == nil {
pterm.Success.Println("No changes found between specifications")
return nil
}

for c := range commitHistory {
tableData := [][]string{{"Document Element", "Total Changes", "Breaking Changes"}}

Expand Down
7 changes: 5 additions & 2 deletions git/read_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
docConfig.AllowFileReferences = true
}

// TODO: make this configurable for power users.
docConfig.ExcludeExtensionRefs = true

ptermLog := &pterm.Logger{
Formatter: pterm.LogFormatterColorful,
Writer: os.Stdout,
Expand Down Expand Up @@ -233,7 +236,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
oldDoc, err = libopenapi.NewDocumentWithConfiguration(oldBits, docConfig)

if err != nil {
model.SendFatalError("building models", fmt.Sprintf("unable to parse original document: %s", err.Error()), errorChan)
model.SendFatalError("building models", fmt.Sprintf("unable to parse original document '%s': %s", commitHistory[c].FilePath, err.Error()), errorChan)
changeErrors = append(changeErrors, err)
return nil, changeErrors
} else {
Expand All @@ -244,7 +247,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
}
newDoc, err = libopenapi.NewDocumentWithConfiguration(newBits, docConfig)
if err != nil {
model.SendProgressError("building models", fmt.Sprintf("unable to parse modified document: %s", err.Error()), errorChan)
model.SendProgressError("building models", fmt.Sprintf("unable to parse modified document '%s': %s", commitHistory[c].FilePath, err.Error()), errorChan)
changeErrors = append(changeErrors, err)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/gdamore/tcell/v2 v2.8.1
github.com/google/uuid v1.6.0
github.com/pb33f/libopenapi v0.21.2
github.com/pb33f/libopenapi v0.21.3
github.com/pterm/pterm v0.12.80
github.com/rivo/tview v0.0.0-20241227133733-17b7edb88c57
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ 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/libopenapi v0.21.2 h1:L99NhyXtcRIawo8aVmWPIfA6k8v+8t6zJrTZkv7ggMI=
github.com/pb33f/libopenapi v0.21.2/go.mod h1:Gc8oQkjr2InxwumK0zOBtKN9gIlv9L2VmSVIUk2YxcU=
github.com/pb33f/libopenapi v0.21.3 h1:3pAuQjWuAb/+jcxWYTIAtVL52d1lAZXU5FNtDDjE3HQ=
github.com/pb33f/libopenapi v0.21.3/go.mod h1:Gc8oQkjr2InxwumK0zOBtKN9gIlv9L2VmSVIUk2YxcU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function ReportSummary(props: ReportSummaryProps) {
breakingStat = <Statistic title="Breaking" className="width-100 m-bottom-20"
value={props.changeStats.totalBreaking}
valueStyle={{fontWeight: 'bolder', color: 'var(--error-font-color)'}}/>
} else {
breakingStat = <Statistic title="Breaking" className="width-100 m-bottom-20"
value='0'
valueStyle={{fontWeight: 'bolder', color: 'var(--terminal-green)'}}/>
}
return (
<section className='report-summary'>
Expand Down
2 changes: 1 addition & 1 deletion tui/build_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func buildTreeNode(root *tview.TreeNode, object any) *tview.TreeNode {

case reflect.TypeOf(&whatChangedModel.ResponseChanges{}):
node := CreateNode("Response", object)
DigIntoObject[whatChangedModel.ExtensionChanges](root, node, field)
DigIntoObject[whatChangedModel.ResponseChanges](root, node, field)

case reflect.TypeOf(&whatChangedModel.SchemaChanges{}):
node := CreateNode("Schema", object)
Expand Down
Loading