Skip to content

Commit

Permalink
Merge pull request #151 from h0tw1r3/panic/148
Browse files Browse the repository at this point in the history
  • Loading branch information
chelnak authored May 3, 2024
2 parents 74c5093 + 6667c92 commit dad43c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions internal/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions internal/get/single_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- markdownlint-disable MD024 -->
# 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)

0 comments on commit dad43c2

Please sign in to comment.