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
27 changes: 21 additions & 6 deletions tools/cli/internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ type Change struct {
// The returned entries includes all the changes between the base and revision specs included the one
// marked as hidden.
func NewEntries(basePath, revisionPath, exceptionFilePath string) ([]*Entry, error) {
return NewEntriesWithRunDate(basePath, revisionPath, exceptionFilePath, time.Now().Format("2006-01-02"))
}

// NewEntriesWithRunDate generates the changelog entries with a specific run date.
func NewEntriesWithRunDate(basePath, revisionPath, exceptionFilePath, runDate string) ([]*Entry, error) {
baseMetadata, err := newMetadataFromFile(basePath)
if err != nil {
return nil, err
Expand All @@ -120,7 +125,7 @@ func NewEntries(basePath, revisionPath, exceptionFilePath string) ([]*Entry, err
}
log.Printf("Revision Metadata: %s", newStringFromStruct(revisionMetadata))

revisionMetadata.RunDate = time.Now().Format("2006-01-02")
revisionMetadata.RunDate = runDate

baseActiveVersionOnPreviousRunDate, err := latestVersionActiveOnDate(baseMetadata.RunDate, baseMetadata.Versions)
if err != nil {
Expand Down Expand Up @@ -208,7 +213,12 @@ func NewEntries(basePath, revisionPath, exceptionFilePath string) ([]*Entry, err
// The returned entries includes the changes between the base and revision specs that are not
// marked as hidden.
func NewEntriesWithoutHidden(basePath, revisionPath, exceptionFilePath string) ([]*Entry, error) {
entries, err := NewEntries(basePath, revisionPath, exceptionFilePath)
return NewEntriesWithoutHiddenWithRunDate(basePath, revisionPath, exceptionFilePath, time.Now().Format("2006-01-02"))
}

// NewEntriesWithoutHiddenWithRunDate generates the changelog entries with a specific run date.
func NewEntriesWithoutHiddenWithRunDate(basePath, revisionPath, exceptionFilePath, runDate string) ([]*Entry, error) {
entries, err := NewEntriesWithRunDate(basePath, revisionPath, exceptionFilePath, runDate)
if err != nil {
return nil, err
}
Expand All @@ -218,6 +228,11 @@ func NewEntriesWithoutHidden(basePath, revisionPath, exceptionFilePath string) (

// NewEntriesBetweenRevisionVersions generates the changelog entries between the revision versions.
func NewEntriesBetweenRevisionVersions(revisionPath, exceptionFilePath string) ([]*Entry, error) {
return NewEntriesBetweenRevisionVersionsWithRunDate(revisionPath, exceptionFilePath, time.Now().Format("2006-01-02"))
}

// NewEntriesBetweenRevisionVersionsWithRunDate generates the changelog entries between the revision versions with a specific run date.
func NewEntriesBetweenRevisionVersionsWithRunDate(revisionPath, exceptionFilePath, runDate string) ([]*Entry, error) {
revisionMetadata, err := newMetadataFromFile(revisionPath)
if err != nil {
return nil, err
Expand All @@ -231,7 +246,7 @@ func NewEntriesBetweenRevisionVersions(revisionPath, exceptionFilePath string) (
continue
}

entry, err := newEntriesBetweenVersion(revisionMetadata, fromVersion, toVersion, exceptionFilePath)
entry, err := newEntriesBetweenVersionWithRunDate(revisionMetadata, fromVersion, toVersion, exceptionFilePath, runDate)
if err != nil {
return nil, err
}
Expand All @@ -242,19 +257,19 @@ func NewEntriesBetweenRevisionVersions(revisionPath, exceptionFilePath string) (
return newVersionEntries(entries), nil
}

func newEntriesBetweenVersion(metadata *Metadata, fromVersion, toVersion, exceptionFilePath string) (*Entry, error) {
func newEntriesBetweenVersionWithRunDate(metadata *Metadata, fromVersion, toVersion, exceptionFilePath, runDate string) (*Entry, error) {
baseMetadata := &Metadata{
Path: metadata.Path,
ActiveVersion: fromVersion,
RunDate: time.Now().Format("2006-01-02"),
RunDate: runDate,
SpecRevision: metadata.SpecRevision,
Versions: metadata.Versions,
}

revisionMetadata := &Metadata{
Path: metadata.Path,
ActiveVersion: toVersion,
RunDate: time.Now().Format("2006-01-02"),
RunDate: runDate,
SpecRevision: metadata.SpecRevision,
Versions: metadata.Versions,
}
Expand Down
16 changes: 14 additions & 2 deletions tools/cli/internal/cli/changelog/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package changelog
import (
"fmt"
"log"
"time"

"github.com/mongodb/openapi/tools/cli/internal/changelog"
"github.com/mongodb/openapi/tools/cli/internal/cli/flag"
Expand All @@ -41,10 +42,20 @@ type Opts struct {
exceptionsPaths string
outputPath string
dryRun bool
runDate string
}

func (o *Opts) Run() error {
entries, err := changelog.NewEntries(o.basePath, o.revisionPath, o.exceptionsPaths)
runDate := time.Now().Format("2006-01-02")
if o.runDate != "" {
// Validate the provided run date format
if _, err := time.Parse("2006-01-02", o.runDate); err != nil {
return fmt.Errorf("invalid run date format: %w. Use YYYY-MM-DD format", err)
}
runDate = o.runDate
}

entries, err := changelog.NewEntriesWithRunDate(o.basePath, o.revisionPath, o.exceptionsPaths, runDate)
if err != nil {
return err
}
Expand All @@ -54,7 +65,7 @@ func (o *Opts) Run() error {
return err
}

versionedEntries, err := changelog.NewEntriesBetweenRevisionVersions(o.revisionPath, o.exceptionsPaths)
versionedEntries, err := changelog.NewEntriesBetweenRevisionVersionsWithRunDate(o.revisionPath, o.exceptionsPaths, runDate)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,6 +152,7 @@ func CreateBuilder() *cobra.Command {
cmd.Flags().StringVarP(&opts.exceptionsPaths, flag.ExemptionFilePath, flag.ExemptionFilePathShort, "", usage.ExemptionFilePath)
cmd.Flags().BoolVarP(&opts.dryRun, flag.DryRun, flag.DryRunShort, false, usage.DryRun)
cmd.Flags().StringVarP(&opts.outputPath, flag.Output, flag.OutputShort, "", usage.Output)
cmd.Flags().StringVar(&opts.runDate, "run-date", "", "Fixed run date for testing (YYYY-MM-DD format)")

_ = cmd.MarkFlagRequired(flag.Base)
_ = cmd.MarkFlagRequired(flag.Revision)
Expand Down
2 changes: 2 additions & 0 deletions tools/cli/test/e2e/cli/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func TestChangelog(t *testing.T) {
exemptions,
"-o",
commandOut,
"--run-date",
"2025-06-15", // Fixed date after base run date but before sunset date
)

var o, e bytes.Buffer
Expand Down
Loading