Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare original PR body on release notes mapping #3538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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