Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jacobm-splunk/openapi-changes into …
Browse files Browse the repository at this point in the history
…jacobm/OPENAPI-fixed-hashing-bug-around-pointers
  • Loading branch information
jacobm-splunk committed Jul 29, 2024
2 parents a841451 + 34bab3e commit 5ec2cd9
Show file tree
Hide file tree
Showing 22 changed files with 2,188 additions and 1,518 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

![logo](openapi-changes-logo.webp)

[![discord](https://img.shields.io/discord/923258363540815912)](https://discord.gg/x7VACVuEGP)
[![GitHub downloads](https://img.shields.io/github/downloads/pb33f/openapi-changes/total?label=github%20downloads&style=flat-square)](https://github.com/pb33f/wiretap/releases)
[![npm](https://img.shields.io/npm/dm/@pb33f/openapi-changes?style=flat-square&label=npm%20downloads)](https://www.npmjs.com/package/@pb33f/openapi-changes)
[![Docker Pulls](https://img.shields.io/docker/pulls/pb33f/openapi-changes?style=flat-square)](https://hub.docker.com/r/pb33f/openapi-changes)

# OpenAPI Changes

## The world's **_sexiest_** OpenAPI diff tool.
Expand Down
4 changes: 2 additions & 2 deletions builder/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package builder

import (
"fmt"
"github.com/google/uuid"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
wcModel "github.com/pb33f/libopenapi/what-changed/model"
"github.com/pb33f/openapi-changes/model"
"github.com/twinj/uuid"
"reflect"
"strings"
)
Expand Down Expand Up @@ -227,7 +227,7 @@ func exploreGraphObject(parent *model.NodeData[any], object any, nodes *[]*model
}

func buildId(label string) string {
return fmt.Sprintf("%s-%s", strings.ToLower(label), uuid.NewV4().String()[:6])
return fmt.Sprintf("%s-%s", strings.ToLower(label), uuid.New().String()[:6])
}

func calcWidth(label string) int {
Expand Down
10 changes: 5 additions & 5 deletions builder/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package builder

import (
"github.com/google/uuid"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
wcModel "github.com/pb33f/libopenapi/what-changed/model"
"github.com/pb33f/libopenapi/what-changed/reports"
"github.com/pb33f/openapi-changes/model"
"github.com/twinj/uuid"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"reflect"
Expand Down Expand Up @@ -86,7 +86,7 @@ func exploreTreeObject(parent *model.TreeNode, object any) {

parent.Children = append(parent.Children, &model.TreeNode{
TitleString: title,
Key: uuid.NewV4().String(),
Key: uuid.New().String(),
Change: topChanges[x],
IsLeaf: true,
Selectable: true,
Expand Down Expand Up @@ -290,7 +290,7 @@ func DigIntoTreeNode[T any](parent *model.TreeNode, field reflect.Value, label s
if !field.IsZero() {
e := &model.TreeNode{
TitleString: label,
Key: uuid.NewV4().String(),
Key: uuid.New().String(),
IsLeaf: false,
Selectable: false,
TotalChanges: tc,
Expand All @@ -309,7 +309,7 @@ func DigIntoTreeNodeSlice[T any](parent *model.TreeNode, field reflect.Value, la
f := field.Index(k)
e := &model.TreeNode{
TitleString: label,
Key: uuid.NewV4().String(),
Key: uuid.New().String(),
IsLeaf: false,
Selectable: false,
Disabled: false,
Expand All @@ -336,7 +336,7 @@ func BuildTreeMapNode(parent *model.TreeNode, field reflect.Value) {
default:
tn := &model.TreeNode{
TitleString: e.String(),
Key: uuid.NewV4().String(),
Key: uuid.New().String(),
IsLeaf: false,
Selectable: false,
Disabled: false,
Expand Down
22 changes: 12 additions & 10 deletions cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"path/filepath"
"time"

"github.com/google/uuid"
"github.com/pb33f/openapi-changes/git"
"github.com/pb33f/openapi-changes/model"
"github.com/pb33f/openapi-changes/tui"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/twinj/uuid"
)

func GetConsoleCommand() *cobra.Command {
Expand All @@ -38,6 +38,7 @@ func GetConsoleCommand() *cobra.Command {
failed := false
latestFlag, _ := cmd.Flags().GetBool("top")
limitFlag, _ := cmd.Flags().GetInt("limit")
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
baseFlag, _ := cmd.Flags().GetString("base")
remoteFlag, _ := cmd.Flags().GetBool("remote")

Expand Down Expand Up @@ -143,7 +144,7 @@ func GetConsoleCommand() *cobra.Command {
<-doneChan
return err
}
commits, e := runGithubHistoryConsole(user, repo, filePath, latestFlag, limitFlag, updateChan,
commits, e := runGithubHistoryConsole(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
errorChan, baseFlag, remoteFlag)

// wait for things to be completed.
Expand Down Expand Up @@ -204,7 +205,7 @@ func GetConsoleCommand() *cobra.Command {

go listenForUpdates(updateChan, errorChan)

commits, errs := runGitHistoryConsole(args[0], args[1], latestFlag, limitFlag,
commits, errs := runGitHistoryConsole(args[0], args[1], latestFlag, limitFlag, limitTimeFlag,
updateChan, errorChan, baseFlag, remoteFlag)

// wait.
Expand Down Expand Up @@ -265,10 +266,10 @@ func GetConsoleCommand() *cobra.Command {
return cmd
}

func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit int,
func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit int, limitTime int,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]*model.Commit, []error) {

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, base, remote)
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote)

if latest && len(commitHistory) > 1 {
commitHistory = commitHistory[:1]
Expand Down Expand Up @@ -300,7 +301,7 @@ func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit
return commitHistory, nil
}

func runGitHistoryConsole(gitPath, filePath string, latest bool, limit int,
func runGitHistoryConsole(gitPath, filePath string, latest bool, limit int, limitTime int,
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]*model.Commit, []error) {

if gitPath == "" || filePath == "" {
Expand All @@ -314,15 +315,16 @@ func runGitHistoryConsole(gitPath, filePath string, latest bool, limit int,
filePath, gitPath), false, updateChan)

// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan, limit)
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan, limit, limitTime)

if err != nil {
close(updateChan)
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(err)), errorChan)
return nil, err
}

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

if latest {
commitHistory = commitHistory[:1]
Expand Down Expand Up @@ -360,13 +362,13 @@ func runLeftRightCompare(left, right string, updateChan chan *model.ProgressUpda

commits := []*model.Commit{
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
CommitDate: time.Now(),
Data: rightBytes,
},
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("Original file: %s", left),
CommitDate: time.Now(),
Data: leftBytes,
Expand Down
12 changes: 9 additions & 3 deletions cmd/flatten_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
package cmd

import (
whatChanged "github.com/pb33f/libopenapi/what-changed/model"
"github.com/pb33f/openapi-changes/model"
)

func FlattenReport(report *model.Report) *model.FlatReport {

flatReport := &model.FlatReport{}
flatReport.Summary = report.Summary
var changes []*whatChanged.Change
var changes []*model.HashedChange
rpt := report.Commit.Changes
for _, change := range rpt.GetAllChanges() {
changes = append(changes, change)
hashedChange := model.HashedChange{
Change: change,
}

hashedChange.HashChange()

changes = append(changes, &hashedChange)
}
flatReport.Changes = changes

Expand All @@ -34,6 +39,7 @@ func FlattenHistoricalReport(report *model.HistoricalReport) *model.FlatHistoric
flatReport.GitFilePath = report.GitFilePath
flatReport.DateGenerated = report.DateGenerated
flatReport.Filename = report.Filename
flatReport.Reports = make([]*model.FlatReport, 0)
for _, r := range report.Reports {
flatReport.Reports = append(flatReport.Reports, FlattenReport(r))
}
Expand Down
25 changes: 13 additions & 12 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/openapi-changes/git"
htmlReport "github.com/pb33f/openapi-changes/html-report"
"github.com/pb33f/openapi-changes/model"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/twinj/uuid"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -42,6 +42,7 @@ func GetHTMLReportCommand() *cobra.Command {
cdnFlag, _ := cmd.Flags().GetBool("use-cdn")
latestFlag, _ := cmd.Flags().GetBool("top")
limitFlag, _ := cmd.Flags().GetInt("limit")
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
remoteFlag, _ := cmd.Flags().GetBool("remote")

if noColorFlag {
Expand Down Expand Up @@ -167,7 +168,7 @@ func GetHTMLReportCommand() *cobra.Command {
return err
}
report, _, er := RunGithubHistoryHTMLReport(user, repo, filePath, latestFlag, cdnFlag,
false, updateChan, errorChan, limitFlag, baseFlag, remoteFlag)
false, updateChan, errorChan, limitFlag, limitTimeFlag, baseFlag, remoteFlag)

// wait for things to be completed.
<-doneChan
Expand Down Expand Up @@ -225,7 +226,7 @@ func GetHTMLReportCommand() *cobra.Command {
go listenForUpdates(updateChan, errorChan)

report, _, er := RunGitHistoryHTMLReport(args[0], args[1], latestFlag, cdnFlag,
updateChan, errorChan, baseFlag, remoteFlag, limitFlag)
updateChan, errorChan, baseFlag, remoteFlag, limitFlag, limitTimeFlag)
<-doneChan
if er != nil {
for x := range er {
Expand Down Expand Up @@ -302,7 +303,7 @@ func ExtractGithubDetailsFromURL(url *url.URL) (string, string, string, error) {
}

func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool, limit int) ([]byte, []*model.Report, []error) {
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool, limit int, limitTime int) ([]byte, []*model.Report, []error) {
if gitPath == "" || filePath == "" {
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
model.SendProgressError("reading paths",
Expand All @@ -312,7 +313,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
}

// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, progressChan, errorChan, limit)
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, progressChan, errorChan, limit, limitTime)
if err != nil {
model.SendFatalError("extraction",
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
Expand All @@ -321,7 +322,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
}

// populate history with changes and data
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, progressChan, errorChan, base, remote)
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, progressChan, errorChan, base, remote)
if err != nil {
model.SendFatalError("extraction",
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
Expand Down Expand Up @@ -352,9 +353,9 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
}

func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN, embeddedMode bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, limit int, base string, remote bool) ([]byte, []*model.Report, []error) {
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, limit int, limitTime int, base string, remote bool) ([]byte, []*model.Report, []error) {

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, base, remote)
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote)
if latest && len(commitHistory) > 1 {
commitHistory = commitHistory[:1]
}
Expand Down Expand Up @@ -410,13 +411,13 @@ func RunLeftRightHTMLReport(left, right string, useCDN bool,

commits := []*model.Commit{
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("New: %s, Original: %s", right, left),
CommitDate: time.Now(),
Data: rightBytes,
},
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("Original file: %s", left),
CommitDate: time.Now(),
Data: leftBytes,
Expand All @@ -442,13 +443,13 @@ func RunLeftRightHTMLReportViaString(left, right string, useCDN, embedded bool,

commits := []*model.Commit{
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("Uploaded original (%d bytes)", len(left)),
CommitDate: time.Now(),
Data: []byte(left),
},
{
Hash: uuid.NewV4().String()[:6],
Hash: uuid.New().String()[:6],
Message: fmt.Sprintf("Uploaded modification (%d bytes)", len(right)),
CommitDate: time.Now(),
Data: []byte(right),
Expand Down
Loading

0 comments on commit 5ec2cd9

Please sign in to comment.