Skip to content

Commit

Permalink
fix integration test for empty release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
npolshakova committed Sep 18, 2024
1 parent 29cadce commit d948c1a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
13 changes: 10 additions & 3 deletions pkg/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) {
// may contain the commit message, the PR description, etc.
// This is generally the content inside the ```release-note ``` stanza.
func noteTextFromString(s string) (string, error) {
// check release note is not empty
// Matches "release-notes" block with no meaningful content (ex. only whitespace, empty, just newlines)
emptyExps := []*regexp.Regexp{
regexp.MustCompile("(?i)```release-notes?\\s*```\\s*"),
}

if matchesFilter(s, emptyExps) {
return "", errors.New("empty release note")
}

exps := []*regexp.Regexp{
// (?s) is needed for '.' to be matching on newlines, by default that's disabled
// we need to match ungreedy 'U', because after the notes a `docs` block can occur
Expand Down Expand Up @@ -634,9 +644,6 @@ var noteExclusionFilters = []*regexp.Regexp{

// simple '/release-note-none' tag
regexp.MustCompile("/release-note-none"),

// Matches "release-notes" block with no meaningful content (ex. only whitespace, empty, just newlines)
regexp.MustCompile("(?i)```release-notes?\\s*```\\s*"),
}

// MatchesExcludeFilter returns true if the string matches an excluded release note.
Expand Down
8 changes: 4 additions & 4 deletions pkg/notes/notes_gatherer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ func TestGatherNotes(t *testing.T) {
{pullRequest(9, "release-note /release-note-none", "closed")}, // excluded, the exclusion filters take precedence
{pullRequest(10, "```release-note\nNAAAAAAAAAA\n```", "closed")}, // included, does not match the N/A filter, but the 'release-note' check
{pullRequest(11, "```release-note\nnone something\n```", "closed")}, // included, does not match the N/A filter, but the 'release-note' check
// empty release note block should be excluded
// empty release note block should skipped because noteTextFromString returns an error
{pullRequest(12, "```release-note\n\n```", "closed")},
{pullRequest(13, "```release-note```", "closed")},
{pullRequest(13, "```release-note ```", "closed")},
{pullRequest(14, "```release-note\n\n```", "open")},
{pullRequest(14, "```release-note ```", "closed")},
{pullRequest(15, "```release-note\n\n```", "open")},
}
var callCount int64 = -1

Expand All @@ -371,7 +371,7 @@ func TestGatherNotes(t *testing.T) {
resultsChecker: func(t *testing.T, results []*Result) {
// there is not much we can check on the Result, as all the fields are
// unexported
expectedResultSize := 12
expectedResultSize := 9
if e, a := expectedResultSize, len(results); e != a {
t.Errorf("Expected the result to be of size %d, got %d", e, a)
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/notes/notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ func TestNoteTextFromString(t *testing.T) {
require.Equal(t, "item\nitem\n- item\n item", res)
},
},
{
noteBlock(
"",
),
func(res string, err error) {
require.NotNil(t, err)
require.Contains(t, err.Error(), "empty release note")
require.Equal(t, "", res)
},
},
} {
tc.expect(noteTextFromString(tc.input))
}
Expand Down Expand Up @@ -384,7 +394,7 @@ Please use the following format for linking documentation:
` + mdSep + `
`,
shouldExclude: true,
shouldExclude: false, // noteTextFromString will catch empty release notes
},
} {
res := MatchesExcludeFilter(tc.input)
Expand Down

0 comments on commit d948c1a

Please sign in to comment.