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
13 changes: 7 additions & 6 deletions cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func GetConsoleCommand() *cobra.Command {
limitFlag, _ := cmd.Flags().GetInt("limit")
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
baseFlag, _ := cmd.Flags().GetString("base")
baseCommitFlag, _ := cmd.Flags().GetString("base-commit")
remoteFlag, _ := cmd.Flags().GetBool("remote")
extRefs, _ := cmd.Flags().GetBool("ext-refs")

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

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

go listenForUpdates(updateChan, errorChan)

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

// wait.
Expand Down Expand Up @@ -273,10 +274,10 @@ func GetConsoleCommand() *cobra.Command {
}

// TODO: we have got to clean up these methods and replace with a message based design.
func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit int, limitTime int,
func runGithubHistoryConsole(username, repo, filePath, baseCommit string, latest bool, limit int, limitTime int,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) ([]*model.Commit, []error) {

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

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

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

if gitPath == "" || filePath == "" {
Expand All @@ -322,7 +323,7 @@ func runGitHistoryConsole(gitPath, filePath string, latest bool, globalRevisions
filePath, gitPath), false, updateChan)

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

if err != nil {
close(updateChan)
Expand Down
13 changes: 7 additions & 6 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func GetHTMLReportCommand() *cobra.Command {
doneChan := make(chan bool)
failed := false
baseFlag, _ := cmd.Flags().GetString("base")
baseCommitFlag, _ := cmd.Flags().GetString("base-commit")
noColorFlag, _ := cmd.Flags().GetBool("no-color")
cdnFlag, _ := cmd.Flags().GetBool("use-cdn")
latestFlag, _ := cmd.Flags().GetBool("top")
Expand Down Expand Up @@ -170,7 +171,7 @@ func GetHTMLReportCommand() *cobra.Command {
<-doneChan
return err
}
report, _, er := RunGithubHistoryHTMLReport(user, repo, filePath, latestFlag, cdnFlag,
report, _, er := RunGithubHistoryHTMLReport(user, repo, filePath, baseCommitFlag, latestFlag, cdnFlag,
false, updateChan, errorChan, limitFlag, limitTimeFlag, baseFlag, remoteFlag, extRefs)

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

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

func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
func RunGitHistoryHTMLReport(gitPath, filePath, baseCommit string, latest, useCDN bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool, globalRevisions 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")
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, globalRevisions, limit, limitTime)
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, baseCommit, progressChan, errorChan, globalRevisions, limit, limitTime)
if err != nil {
model.SendFatalError("extraction",
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
Expand Down Expand Up @@ -351,10 +352,10 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
return generator.GenerateReport(false, useCDN, false), reports, nil
}

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

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote, extRefs)
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, baseCommit, progressChan, errorChan, true, limit, limitTime, base, remote, extRefs)
if latest && len(commitHistory) > 1 {
commitHistory = commitHistory[:1]
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func GetReportCommand() *cobra.Command {
doneChan := make(chan bool)
failed := false
latestFlag, _ := cmd.Flags().GetBool("top")
baseCommitFlag, _ := cmd.Flags().GetString("base-commit")
globalRevisionsFlag, _ := cmd.Flags().GetBool("global-revisions")
limitFlag, _ := cmd.Flags().GetInt("limit")
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
Expand Down Expand Up @@ -93,7 +94,7 @@ func GetReportCommand() *cobra.Command {
<-doneChan
return err
}
report, er := runGithubHistoryReport(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
report, er := runGithubHistoryReport(user, repo, filePath, baseCommitFlag, latestFlag, limitFlag, limitTimeFlag, updateChan,
errorChan, baseFlag, remoteFlag, extRefs)

// wait for things to be completed.
Expand Down Expand Up @@ -158,7 +159,7 @@ func GetReportCommand() *cobra.Command {

go listenForUpdates(updateChan, errorChan)

report, er := runGitHistoryReport(repo, p, latestFlag, updateChan, errorChan, baseFlag,
report, er := runGitHistoryReport(repo, p, baseCommitFlag, latestFlag, updateChan, errorChan, baseFlag,
remoteFlag, extRefs, globalRevisionsFlag, limitFlag, limitTimeFlag)

<-doneChan
Expand Down Expand Up @@ -229,7 +230,7 @@ func GetReportCommand() *cobra.Command {
return cmd
}

func runGitHistoryReport(gitPath, filePath string, latest bool,
func runGitHistoryReport(gitPath, filePath, baseCommit string, latest bool,
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool, globalRevisions bool, limit int, limitTime int) (*model.HistoricalReport, []error) {

if gitPath == "" || filePath == "" {
Expand All @@ -244,7 +245,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
filePath, gitPath), false, updateChan)

// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan, globalRevisions, limit, limitTime)
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, baseCommit, updateChan, errorChan, globalRevisions, limit, limitTime)
if err != nil {
model.SendProgressError("git", fmt.Sprintf("%d errors found building history", len(err)), errorChan)
close(updateChan)
Expand Down Expand Up @@ -284,10 +285,10 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,

}

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

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan,
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, baseCommit, progressChan, errorChan,
false, limit, limitTime, base, remote, extRefs)
if errs != nil {
model.SendProgressError("git", errors.Join(errs...).Error(), errorChan)
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func init() {
rootCmd.PersistentFlags().IntP("limit-time", "d", -1, "Limit history to number of days. Supersedes limit argument if present.")
rootCmd.PersistentFlags().BoolP("no-logo", "b", false, "Don't print the big purple pb33f banner")
rootCmd.PersistentFlags().StringP("base", "p", "", "Base URL or path to use for resolving relative or remote references")
rootCmd.PersistentFlags().StringP("base-commit", "", "", "Base commit to compare against (will check until commit is found or limit is reached -- make sure to not shallow clone)")
rootCmd.PersistentFlags().BoolP("remote", "r", true, "Allow remote reference (URLs and files) to be auto resolved, without a base URL or path (default is on)")
rootCmd.PersistentFlags().BoolP("ext-refs", "", false, "Turn on $ref lookups and resolving for extensions (x-) objects")
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func GetSummaryCommand() *cobra.Command {
doneChan := make(chan bool)
failed := false
baseFlag, _ := cmd.Flags().GetString("base")
baseCommitFlag, _ := cmd.Flags().GetString("base-commit")
latestFlag, _ := cmd.Flags().GetBool("top")
noColorFlag, _ := cmd.Flags().GetBool("no-color")
globalRevisionsFlag, _ := cmd.Flags().GetBool("global-revisions")
Expand Down Expand Up @@ -182,7 +183,7 @@ func GetSummaryCommand() *cobra.Command {
return err
}

er := runGithubHistorySummary(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
er := runGithubHistorySummary(user, repo, filePath, baseCommitFlag, latestFlag, limitFlag, limitTimeFlag, updateChan,
errorChan, baseFlag, remoteFlag, markdownFlag, extRefs, errOnDiff)
// wait for things to be completed.
<-doneChan
Expand Down Expand Up @@ -237,7 +238,7 @@ func GetSummaryCommand() *cobra.Command {

go listenForUpdates(updateChan, errorChan)

err = runGitHistorySummary(args[0], args[1], latestFlag, updateChan, errorChan,
err = runGitHistorySummary(args[0], args[1], baseCommitFlag, latestFlag, updateChan, errorChan,
baseFlag, remoteFlag, markdownFlag, extRefs, errOnDiff, globalRevisionsFlag, limitFlag, limitTimeFlag)

<-doneChan
Expand Down Expand Up @@ -385,9 +386,9 @@ func runLeftRightSummary(left, right string, updateChan chan *model.ProgressUpda
return nil
}

func runGithubHistorySummary(username, repo, filePath string, latest bool, limit int, limitTime int,
func runGithubHistorySummary(username, repo, filePath, baseCommit string, latest bool, limit int, limitTime int,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown, extRefs, errOnDiff bool) error {
commitHistory, _ := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan,
commitHistory, _ := git.ProcessGithubRepo(username, repo, filePath, baseCommit, progressChan, errorChan,
false, limit, limitTime, base, remote, extRefs)

if latest {
Expand All @@ -402,7 +403,7 @@ func runGithubHistorySummary(username, repo, filePath string, latest bool, limit
return printSummaryDetails(commitHistory, markdown, errOnDiff)
}

func runGitHistorySummary(gitPath, filePath string, latest bool,
func runGitHistorySummary(gitPath, filePath, baseCommit string, latest bool,
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown, extRefs, errOnDiff bool,
globalRevisions bool, limit int, limitTime int) error {

Expand All @@ -417,7 +418,7 @@ func runGitHistorySummary(gitPath, filePath string, latest bool,
filePath, gitPath), false, updateChan)

// build commit history.
commitHistory, errs := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan, globalRevisions, limit, limitTime)
commitHistory, errs := git.ExtractHistoryFromFile(gitPath, filePath, baseCommit, updateChan, errorChan, globalRevisions, limit, limitTime)
if errs != nil {
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(errs)), errorChan)
close(updateChan)
Expand Down
19 changes: 12 additions & 7 deletions git/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/araddon/dateparse"
"github.com/pb33f/openapi-changes/model"
"io"
"net"
"net/http"
Expand All @@ -17,6 +15,9 @@ import (
"path/filepath"
"strings"
"time"

"github.com/araddon/dateparse"
"github.com/pb33f/openapi-changes/model"
)

const GithubRepoAPI = "https://api.github.com/repos/"
Expand Down Expand Up @@ -49,7 +50,7 @@ type APIFile struct {
Bytes []byte `json:"-"`
}

func GetCommitsForGithubFile(user, repo, path string,
func GetCommitsForGithubFile(user, repo, path string, baseCommit string,
progressChan chan *model.ProgressUpdate, progressErrorChan chan model.ProgressError,
forceCutoff bool, limit int, limitTime int) ([]*APICommit, error) {

Expand Down Expand Up @@ -121,7 +122,7 @@ func GetCommitsForGithubFile(user, repo, path string,
errString := fmt.Sprintf("HTTP error %d, cannot proceed: %s", res.StatusCode, string(b))
model.SendProgressError(fmt.Sprintf("fetching commit %s via API", commit.Hash),
err.Error(), progressErrorChan)
e <- fmt.Errorf(errString)
e <- errors.New(errString)
return
}
b, er := io.ReadAll(res.Body)
Expand Down Expand Up @@ -169,7 +170,7 @@ func GetCommitsForGithubFile(user, repo, path string,
errMsg := fmt.Sprintf("HTTP error %d, cannot proceed: %s", res.StatusCode, string(k))
model.SendProgressError(fmt.Sprintf("reading commit %s file at %s via API",
commit.Hash, commit.Files[x].RawURL), errMsg, progressErrorChan)
e <- fmt.Errorf(errMsg)
e <- errors.New(errMsg)
return
}
b, er = io.ReadAll(res.Body)
Expand Down Expand Up @@ -222,6 +223,10 @@ func GetCommitsForGithubFile(user, repo, path string,
fmt.Sprintf("commit %s being fetched from %s", commits[x].Hash[0:6], u), false, progressChan)
go extractFilesFromCommit(user, repo, path, commits[x], sigChan, errChan)
b++
if baseCommit != "" && (commits[x].Hash == baseCommit || strings.HasPrefix(commits[x].Hash, baseCommit)) {
totalCommits = b
break
}
if limit > 0 && b > limit {
break
}
Expand Down Expand Up @@ -292,7 +297,7 @@ func ConvertGithubCommitsIntoModel(ghCommits []*APICommit,
return normalized, errs
}

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

Expand All @@ -302,7 +307,7 @@ func ProcessGithubRepo(username string, repo string, filePath string,
return nil, []error{err}
}

githubCommits, err := GetCommitsForGithubFile(username, repo, filePath, progressChan, errorChan, forceCutoff, limit, limitTime)
githubCommits, err := GetCommitsForGithubFile(username, repo, filePath, baseCommit, progressChan, errorChan, forceCutoff, limit, limitTime)

if err != nil {
return nil, []error{err}
Expand Down
Loading
Loading