Skip to content

Commit 0623915

Browse files
committed
Compare original PR body on release notes mapping
When creating a mapping we now preserve the original PR body in the YAML map. This allows us to track modifications to the PR if their values already got mapped during the release cycle and warn the end user in that case. Fixes #3510 Signed-off-by: Sascha Grunert <[email protected]>
1 parent 0c522db commit 0623915

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

cmd/krel/cmd/release_notes.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func createDraftPR(repoPath, tag string) (err error) {
400400
}
401401

402402
// Run the release notes fix flow
403-
err := fixReleaseNotes(filepath.Join(releaseDir, releaseNotesWorkDir), releaseNotes)
403+
err := FixReleaseNotes(filepath.Join(releaseDir, releaseNotesWorkDir), releaseNotes)
404404
if err != nil {
405405
return fmt.Errorf("while running release notes fix flow: %w", err)
406406
}
@@ -1154,6 +1154,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error {
11541154
ActionRequired: note.ActionRequired,
11551155
Documentation: note.Documentation,
11561156
DoNotPublish: note.DoNotPublish,
1157+
PRBody: note.PRBody,
11571158
}
11581159

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

1414+
testMap.PRBody = &originalNote.PRBody
1415+
14131416
// Remarshall the newyaml to save only the new values
14141417
newYAML, err := yaml.Marshal(testMap)
14151418
if err != nil {

pkg/notes/notes.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737

3838
gogithub "github.com/google/go-github/v58/github"
3939
"github.com/nozzle/throttler"
40+
"github.com/sergi/go-diff/diffmatchpatch"
4041
"github.com/sirupsen/logrus"
4142
"golang.org/x/text/cases"
4243
"golang.org/x/text/language"
@@ -139,6 +140,9 @@ type ReleaseNote struct {
139140

140141
// IsMapped is set if the note got modified from a map
141142
IsMapped bool `json:"is_mapped,omitempty"`
143+
144+
// PRBody is the full PR body of the release note
145+
PRBody string `json:"pr_body,omitempty"`
142146
}
143147

144148
type Documentation struct {
@@ -518,6 +522,7 @@ func (g *Gatherer) ReleaseNoteFromCommit(result *Result) (*ReleaseNote, error) {
518522
DuplicateKind: isDuplicateKind,
519523
ActionRequired: labelExactMatch(pr, "release-note-action-required"),
520524
DoNotPublish: labelExactMatch(pr, "release-note-none"),
525+
PRBody: prBody,
521526
}, nil
522527
}
523528

@@ -757,6 +762,7 @@ func (g *Gatherer) ReleaseNoteForPullRequest(prNr int) (*ReleaseNote, error) {
757762
ActionRequired: false,
758763
DoNotPublish: doNotPublish,
759764
DataFields: map[string]ReleaseNotesDataField{},
765+
PRBody: prBody,
760766
}
761767

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

1160+
if noteMap.PRBody != nil && rn.PRBody != "" && rn.PRBody != *noteMap.PRBody {
1161+
logrus.Warnf("Original PR body of release note mapping changed for PR: #%d", rn.PrNumber)
1162+
1163+
dmp := diffmatchpatch.New()
1164+
diffs := dmp.DiffMain(rn.PRBody, *noteMap.PRBody, false)
1165+
logrus.Warnf("The diff between actual release note body and mapped one is:\n%s", dmp.DiffPrettyText(diffs))
1166+
}
1167+
11541168
reRenderMarkdown := false
11551169
if noteMap.ReleaseNote.Author != nil {
11561170
rn.Author = *noteMap.ReleaseNote.Author
@@ -1231,6 +1245,7 @@ func (rn *ReleaseNote) ToNoteMap() (string, error) {
12311245
noteMap.ReleaseNote.Feature = &rn.Feature
12321246
noteMap.ReleaseNote.ActionRequired = &rn.ActionRequired
12331247
noteMap.ReleaseNote.DoNotPublish = &rn.DoNotPublish
1248+
noteMap.PRBody = &rn.PRBody
12341249

12351250
yamlCode, err := yaml.Marshal(&noteMap)
12361251
if err != nil {

pkg/notes/notes_map.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ type ReleaseNotesMap struct {
117117
} `json:"releasenote"`
118118

119119
DataFields map[string]ReleaseNotesDataField `json:"datafields,omitempty" yaml:"datafields,omitempty"`
120+
121+
// PRBody is the full original PR body.
122+
PRBody *string `json:"pr_body,omitempty" yaml:"pr_body,omitempty"`
120123
}
121124

122125
// ReleaseNotesDataField extra data added to a release note

0 commit comments

Comments
 (0)