diff --git a/internal/get/get.go b/internal/get/get.go index bb23ee0..3ce1334 100644 --- a/internal/get/get.go +++ b/internal/get/get.go @@ -28,8 +28,10 @@ func parseChangelog(fileName string) (changelog.Changelog, error) { func changelogWithSingleEntry(entry entry.Entry, repoName, repoOwner string) changelog.Changelog { // Isolate the entry entry.Next = nil - entry.PrevTag = entry.Previous.Tag - entry.Previous = nil + if entry.Previous != nil { + entry.PrevTag = entry.Previous.Tag + entry.Previous = nil + } cl := changelog.NewChangelog(repoOwner, repoName) cl.Insert(entry) diff --git a/internal/get/get_test.go b/internal/get/get_test.go index aaa0377..7ba02f6 100644 --- a/internal/get/get_test.go +++ b/internal/get/get_test.go @@ -8,6 +8,7 @@ import ( ) var fileName string = "CHANGELOG.md" +var singleEntryFileName string = "single_CHANGELOG.md" func TestGetAll(t *testing.T) { cl, err := get.GetAll(fileName) @@ -32,6 +33,18 @@ func TestGetLatest(t *testing.T) { assert.Equal(t, "v0.13.0", cl.GetEntries()[0].PrevTag) } +func TestGetLatestWithNoPrevious(t *testing.T) { + cl, err := get.GetLatest(singleEntryFileName) + + // Should not error + assert.Nil(t, err) + + // Should have 1 entry + count := len(cl.GetEntries()) + assert.Equal(t, 1, count) + assert.Equal(t, "", cl.GetEntries()[0].PrevTag) +} + func TestGetVersionWithAValidVersion(t *testing.T) { // Should not error when version is found cl, err := get.GetVersion(fileName, "v0.9.0") diff --git a/internal/get/single_CHANGELOG.md b/internal/get/single_CHANGELOG.md new file mode 100644 index 0000000..ec856a9 --- /dev/null +++ b/internal/get/single_CHANGELOG.md @@ -0,0 +1,10 @@ + +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). + +## [v0.1.0](https://github.com/chelnak/gh-changelog/tree/v0.1.0) - 2022-04-15 + +[Full Changelog](https://github.com/chelnak/gh-changelog/compare/42d4c93b23eaf307c5f9712f4c62014fe38332bd...v0.1.0)