Skip to content

Commit

Permalink
validator: check entry type through substring matching (#202)
Browse files Browse the repository at this point in the history
* validator: check entry type through substring matching

* validator: add test for both singular and plural form

* add changelog

---------

Co-authored-by: Juan Manuel Perez <[email protected]>
  • Loading branch information
Nadia Santalla and kilokang authored Aug 9, 2024
1 parent aaee8b2 commit 555a2d2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Unreleased section should follow [Release Toolkit](https://github.com/newrelic/release-toolkit#render-markdown-and-update-markdown)
## Unreleased

### Enhancement
- Fix markdown validator to match entry-type

## v1.1.0 - 2024-04-09

### ⛓️ Dependencies
Expand Down
18 changes: 13 additions & 5 deletions src/changelog/sources/markdown/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@ func (v *Validator) validateL2Children(l2doc *headingdoc.Doc) []error {

// isEntryType detects if a L3 header is one of the defined changelog EntryTypes.
func (v *Validator) isEntryType(header *headingdoc.Doc) bool {
return strings.ToLower(header.Name) == string(changelog.TypeEnhancement) ||
strings.ToLower(header.Name) == string(changelog.TypeBugfix) ||
strings.ToLower(header.Name) == string(changelog.TypeSecurity) ||
strings.ToLower(header.Name) == string(changelog.TypeBreaking) ||
strings.ToLower(header.Name) == string(changelog.TypeDependency)
for _, entryType := range []changelog.EntryType{
changelog.TypeBreaking,
changelog.TypeSecurity,
changelog.TypeEnhancement,
changelog.TypeBugfix,
changelog.TypeDependency,
} {
if strings.Contains(strings.ToLower(header.Name), strings.ToLower(string(entryType))) {
return true
}
}

return false
}

// ensureItemizedList ensures the body of a L3 header
Expand Down
33 changes: 33 additions & 0 deletions src/changelog/sources/markdown/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,39 @@ This is a release note
## v1.2.3 - 2022-11-11
### Enhancements
- This is in the past and should not be included
`),
expected: []error{},
},
{
name: "Only enhancements plural",
markdown: strings.TrimSpace(`
# Changelog
This is based on blah blah blah
### Enhancements
- Added this
- Improved that
## v1.2.3 - 2022-11-11
### Enhancements
- This is in the past and should not be included
`),
expected: []error{},
},
{
name: "Only enhancement singular",
markdown: strings.TrimSpace(`
# Changelog
This is based on blah blah blah
### Enhancement
- Added this
## v1.2.3 - 2022-11-11
### Enhancements
- This is in the past and should not be included
`),
Expand Down

0 comments on commit 555a2d2

Please sign in to comment.