Skip to content

Commit

Permalink
Include PRs in notes when no release note is defined
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Apr 14, 2021
1 parent b74561a commit 49092d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
10 changes: 5 additions & 5 deletions pkg/notes/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ func New(
for _, pr := range releaseNotes.History() {
note := releaseNotes.Get(pr)

if note.DoNotPublish {
logrus.Debugf("skipping PR %d as (marked to not be published)", pr)
continue
}

if _, hasCVE := note.DataFields["cve"]; hasCVE {
logrus.Infof("Release note for PR #%d has CVE vulnerability info", note.PrNumber)

Expand All @@ -240,6 +235,11 @@ func New(
doc.CVEList = append(doc.CVEList, newcve)
}

if note.DoNotPublish {
logrus.Debugf("skipping PR %d as (marked to not be published)", pr)
continue
}

// TODO: Refactor the logic here and add testing.
if note.DuplicateKind {
kind := mapKind(highestPriorityKind(note.Kinds))
Expand Down
45 changes: 35 additions & 10 deletions pkg/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,45 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) {
return nil, errors.Wrap(err, "listing commits")
}

results, err := g.gatherNotes(commits)
// Get the PRs into a temporary results set
resultsTemp, err := g.gatherNotes(commits)
if err != nil {
return nil, errors.Wrap(err, "gathering notes")
}

// Cycle the results and add the complete notes, as well as those that
// have a map associated with it
results := []*Result{}
logrus.Info("Checking PRs for mapped data")
for _, res := range resultsTemp {
// If the PR has no release note, check if we have to add it
if MatchesExcludeFilter(*res.pullRequest.Body) {
for _, provider := range mapProviders {
noteMaps, err := provider.GetMapsForPR(res.pullRequest.GetNumber())
if err != nil {
return nil, errors.Wrapf(
err, "checking if a map exists for PR %d", res.pullRequest.GetNumber(),
)
}
if len(noteMaps) != 0 {
logrus.Infof(
"Artificially adding pr #%d because a map for it was found",
res.pullRequest.GetNumber(),
)
results = append(results, res)
}
}
logrus.Debugf(
"Skipping PR #%d because it contains no release note",
res.pullRequest.GetNumber(),
)
continue
} else {
// Append the note as it is
results = append(results, res)
}
}

dedupeCache := map[string]struct{}{}
notes := NewReleaseNotes()
for _, result := range results {
Expand Down Expand Up @@ -311,7 +345,6 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) {
dedupeCache[note.Text] = struct{}{}
}
}

return notes, nil
}

Expand Down Expand Up @@ -676,14 +709,6 @@ func (g *Gatherer) notesForCommit(commit *gogithub.RepositoryCommit) (*Result, e
"Got PR #%d for commit: %s", pr.GetNumber(), commit.GetSHA(),
)

if MatchesExcludeFilter(prBody) {
logrus.Debugf(
"Skipping PR #%d because it contains no release note",
pr.GetNumber(),
)
continue
}

if MatchesIncludeFilter(prBody) {
res := &Result{commit: commit, pullRequest: pr}
logrus.Infof("PR #%d seems to contain a release note", pr.GetNumber())
Expand Down

0 comments on commit 49092d8

Please sign in to comment.