Skip to content

Commit

Permalink
fixed bounds for releases
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasvanEyk committed Jun 20, 2023
1 parent 07ad321 commit 9d2b7be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var showCmd = &cobra.Command{
}

changelog := clog.Parse(source)
// TODO: These bounds are always off by two (too much) at the Stop
bounds, err := findReleaseBounds(args[0], &changelog)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/changelog/inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func determineInsertionPoint(changeType ChangeType, changelog *Changelog) (int,
}

latestRelease := changelog.Releases.Past[len(changelog.Releases.Past)-1]
return latestRelease.Begin, Padding{Before: 0, After: 2}
return latestRelease.Bounds.Start, Padding{Before: 0, After: 2}
}

// Now with all other edge cases handled we can shift our focus to adding a
Expand Down
10 changes: 4 additions & 6 deletions internal/changelog/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ type Release struct {
Version string

HeadlineBounds Bounds

// Position of the first character of the release block (the heading)
Begin int
Bounds Bounds
Bounds Bounds
}

func NewRelease(version string, date string) Release {
Expand Down Expand Up @@ -189,17 +186,18 @@ func Parse(source []byte) Changelog {
if heading.Level == 2 {
headingBounds := ComputeBounds(heading)
if currentRelease != nil {
stop := headingBounds.Start - 3
if currentReleaseIsNextRelease {
nextRelease = &NextRelease{
Bounds: Bounds{
Start: currentRelease.HeadlineBounds.Start - 3,
Stop: headingBounds.Start - 1,
Stop: stop,
},
HeadlineBounds: currentRelease.HeadlineBounds,
Sections: currentRelease.Sections,
}
} else {
currentRelease.Bounds.Stop = headingBounds.Start - 1
currentRelease.Bounds.Stop = stop
releases = append(releases, *currentRelease)
}
}
Expand Down

0 comments on commit 9d2b7be

Please sign in to comment.