Skip to content

Commit

Permalink
Merge pull request #3538 from saschagrunert/release-notes-original-pr
Browse files Browse the repository at this point in the history
Compare original PR body on release notes mapping
  • Loading branch information
k8s-ci-robot authored Apr 2, 2024
2 parents 0c522db + 2ae0d38 commit 3ada8c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/krel/cmd/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
ActionRequired: note.ActionRequired,
Documentation: note.Documentation,
DoNotPublish: note.DoNotPublish,
PRBody: note.PRBody,
}

if noteMaps != nil {
Expand Down Expand Up @@ -1410,6 +1411,8 @@ func editReleaseNote(pr int, workDir string, originalNote, modifiedNote *notes.R
return true, errors.New("invalid map: the YAML code did not have a PR number")
}

testMap.PRBody = &originalNote.PRBody

// Remarshall the newyaml to save only the new values
newYAML, err := yaml.Marshal(testMap)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/saschagrunert/go-modiff v1.3.5
github.com/sendgrid/rest v2.6.9+incompatible
github.com/sendgrid/sendgrid-go v3.14.0+incompatible
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3
github.com/shirou/gopsutil/v3 v3.24.3
github.com/shurcooL/githubv4 v0.0.0-20220115235240-a14260e6f8a2
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -226,7 +227,6 @@ require (
github.com/sassoftware/relic v7.2.1+incompatible // indirect
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/sigstore/cosign/v2 v2.2.2 // indirect
Expand Down
15 changes: 15 additions & 0 deletions pkg/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

gogithub "github.com/google/go-github/v58/github"
"github.com/nozzle/throttler"
"github.com/sergi/go-diff/diffmatchpatch"
"github.com/sirupsen/logrus"
"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down Expand Up @@ -139,6 +140,9 @@ type ReleaseNote struct {

// IsMapped is set if the note got modified from a map
IsMapped bool `json:"is_mapped,omitempty"`

// PRBody is the full PR body of the release note
PRBody string `json:"pr_body,omitempty"`
}

type Documentation struct {
Expand Down Expand Up @@ -518,6 +522,7 @@ func (g *Gatherer) ReleaseNoteFromCommit(result *Result) (*ReleaseNote, error) {
DuplicateKind: isDuplicateKind,
ActionRequired: labelExactMatch(pr, "release-note-action-required"),
DoNotPublish: labelExactMatch(pr, "release-note-none"),
PRBody: prBody,
}, nil
}

Expand Down Expand Up @@ -757,6 +762,7 @@ func (g *Gatherer) ReleaseNoteForPullRequest(prNr int) (*ReleaseNote, error) {
ActionRequired: false,
DoNotPublish: doNotPublish,
DataFields: map[string]ReleaseNotesDataField{},
PRBody: prBody,
}

if s != "" {
Expand Down Expand Up @@ -1151,6 +1157,14 @@ func (rn *ReleaseNote) ApplyMap(noteMap *ReleaseNotesMap, markdownLinks bool) er
}).Debugf("Applying map to note")
rn.IsMapped = true

if noteMap.PRBody != nil && rn.PRBody != "" && rn.PRBody != *noteMap.PRBody {
logrus.Warnf("Original PR body of release note mapping changed for PR: #%d", rn.PrNumber)

dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(rn.PRBody, *noteMap.PRBody, false)
logrus.Warnf("The diff between actual release note body and mapped one is:\n%s", dmp.DiffPrettyText(diffs))
}

reRenderMarkdown := false
if noteMap.ReleaseNote.Author != nil {
rn.Author = *noteMap.ReleaseNote.Author
Expand Down Expand Up @@ -1231,6 +1245,7 @@ func (rn *ReleaseNote) ToNoteMap() (string, error) {
noteMap.ReleaseNote.Feature = &rn.Feature
noteMap.ReleaseNote.ActionRequired = &rn.ActionRequired
noteMap.ReleaseNote.DoNotPublish = &rn.DoNotPublish
noteMap.PRBody = &rn.PRBody

yamlCode, err := yaml.Marshal(&noteMap)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/notes/notes_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type ReleaseNotesMap struct {
} `json:"releasenote"`

DataFields map[string]ReleaseNotesDataField `json:"datafields,omitempty" yaml:"datafields,omitempty"`

// PRBody is the full original PR body.
PRBody *string `json:"pr_body,omitempty" yaml:"pr_body,omitempty"`
}

// ReleaseNotesDataField extra data added to a release note
Expand Down

0 comments on commit 3ada8c5

Please sign in to comment.