diff --git a/cmd/krel/cmd/release_notes.go b/cmd/krel/cmd/release_notes.go index c2eb2bdcca5..10030fff6ca 100644 --- a/cmd/krel/cmd/release_notes.go +++ b/cmd/krel/cmd/release_notes.go @@ -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 { @@ -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 { diff --git a/go.mod b/go.mod index 483d9494502..d99465343b9 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index 831b0c78d02..184fed74460 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -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" @@ -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 { @@ -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 } @@ -757,6 +762,7 @@ func (g *Gatherer) ReleaseNoteForPullRequest(prNr int) (*ReleaseNote, error) { ActionRequired: false, DoNotPublish: doNotPublish, DataFields: map[string]ReleaseNotesDataField{}, + PRBody: prBody, } if s != "" { @@ -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 @@ -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(¬eMap) if err != nil { diff --git a/pkg/notes/notes_map.go b/pkg/notes/notes_map.go index a08c4247901..066e5676750 100644 --- a/pkg/notes/notes_map.go +++ b/pkg/notes/notes_map.go @@ -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