Skip to content

Commit

Permalink
validate file if present
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Apr 9, 2024
1 parent 908c09c commit ec4fcd4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tools/check-changelog/check-changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ func main() {
log.Fatalf("PR_LABELS is not a stringified JSON array: %v", err)
}

filePath := fmt.Sprintf(".changelog/%s.txt", number)
content, errFile := os.ReadFile(filePath)
if errFile == nil { // if file exists then it's always validated, never skipped.
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 file is valid: %s\n", filePath)
return
}

if skipTitle(title) {
fmt.Println("Skipping changelog check because PR title")
return
Expand All @@ -39,19 +52,7 @@ func main() {
return
}

filePath := fmt.Sprintf(".changelog/%s.txt", number)
content, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Changelog file not found: %s, err: %v", filePath, err)
}

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 file is valid: %s\n", filePath)
log.Fatalf("Changelog file not found: %s, err: %v", filePath, errFile)
}

func skipTitle(title string) bool {
Expand Down

0 comments on commit ec4fcd4

Please sign in to comment.