Skip to content

Commit

Permalink
extract function validateChangelog
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Apr 9, 2024
1 parent fc6bbf4 commit b9b2f7c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tools/check-changelog-entry-file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ func main() {
filePath := fmt.Sprintf(".changelog/%s.txt", number)
content, errFile := os.ReadFile(filePath)
if errFile == nil { // Always validate changelog file if present, skip logic is not considered in this case
entry := changelog.Entry{
Body: string(content),
}
if err := entry.Validate(); err != nil {
log.Fatalf("Error validating changelog file: %s, err: %v", filePath, err)
}
fmt.Printf("Changelog entry file is valid: %s\n", filePath)
validateChangelog(filePath, string(content))
return
}

Expand All @@ -55,6 +49,16 @@ func main() {
log.Fatalf("Consider using label %s if this PR doesn't need a changelog entry file. Read contributing guides for more info.\nChangelog file not found: %s, err: %v", skipLabelName, filePath, errFile)
}

func validateChangelog(filePath, body string) {
entry := changelog.Entry{
Body: body,
}
if err := entry.Validate(); err != nil {
log.Fatalf("Error validating changelog file: %s, err: %v", filePath, err)
}
fmt.Printf("Changelog entry file is valid: %s\n", filePath)
}

func skipTitle(title string) bool {
for _, item := range skipTitles {
if strings.HasPrefix(title, item+":") {
Expand Down

0 comments on commit b9b2f7c

Please sign in to comment.