From 6eb94bd17c86654eece7b3551a46e811b99ee0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Garc=C3=ADa=20Veytia=20=28Puerco=29?= Date: Wed, 14 Apr 2021 12:24:16 -0500 Subject: [PATCH] Include PRs in notes when no release note is defined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adolfo GarcĂ­a Veytia (Puerco) --- pkg/notes/document/document.go | 10 ++++---- pkg/notes/notes.go | 45 ++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/pkg/notes/document/document.go b/pkg/notes/document/document.go index cfa4318360a..fc3bf6d460a 100644 --- a/pkg/notes/document/document.go +++ b/pkg/notes/document/document.go @@ -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) @@ -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)) diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index 438edcd2ecf..ca8572ad802 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -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 { @@ -311,7 +345,6 @@ func (g *Gatherer) ListReleaseNotes() (*ReleaseNotes, error) { dedupeCache[note.Text] = struct{}{} } } - return notes, nil } @@ -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())