Skip to content

Commit

Permalink
Merge pull request #85 from AlexNPavel/release-note-not-required-check
Browse files Browse the repository at this point in the history
server: add Release Note Type check
  • Loading branch information
openshift-merge-bot[bot] authored Apr 9, 2024
2 parents 2750030 + 98e2ede commit 3af1840
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
19 changes: 15 additions & 4 deletions cmd/jira-lifecycle-plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,16 +1390,27 @@ func validateBug(bug *jira.Issue, dependents []dependent, options JiraBranchOpti
}

if options.RequireReleaseNotes != nil && *options.RequireReleaseNotes {
releaseNotes, err := helpers.GetIssueReleaseNotesText(bug)
releaseNoteType, err := helpers.GetIssueReleaseNoteType(bug)
if err != nil {
errors = append(errors, err.Error())
}
releaseNotes, err := helpers.GetIssueReleaseNoteText(bug)
if err != nil {
errors = append(errors, err.Error())
valid = false
} else {
if releaseNotes == nil || *releaseNotes == "" || (options.ReleaseNotesDefaultText != nil && *options.ReleaseNotesDefaultText == *releaseNotes) {
if (releaseNotes == nil || *releaseNotes == "" || (options.ReleaseNotesDefaultText != nil && *options.ReleaseNotesDefaultText == *releaseNotes)) && (releaseNoteType == nil || releaseNoteType.Value != "Release Note Not Required") {
valid = false
errors = append(errors, "release note type must be set and release note text must not match the template")
errors = append(errors, "release note text must be set and not match the template OR release note type must be set to \"Release Note Not Required\"")
} else {
validations = append(validations, "release note type is set and release note text does not match the template")
if releaseNotes != nil && *releaseNotes != "" {
validations = append(validations, "release note text is set and does not match the template")
} else if releaseNoteType != nil && releaseNoteType.Value == "Release Note Not Required" {
validations = append(validations, "release note type set to \"Release Note Not Required\"")
} else {
// this else shouldn't be triggered, but it should still set the validation in case something was missed or changes above
validations = append(validations, "release notes fields are valid")
}
}
}
}
Expand Down
17 changes: 12 additions & 5 deletions cmd/jira-lifecycle-plugin/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4408,30 +4408,37 @@ func TestValidateBug(t *testing.T) {
name: "matching release notes requirement means a valid bug",
issue: &jira.Issue{Fields: &jira.IssueFields{
Unknowns: tcontainer.MarshalMap{
helpers.ReleaseNotesTextField: "These are release notes",
helpers.ReleaseNoteTextField: "These are release notes",
},
}},
options: JiraBranchOptions{RequireReleaseNotes: &yes, ReleaseNotesDefaultText: &oneStr},
valid: true,
validations: []string{"release note type is set and release note text does not match the template"},
validations: []string{"release note text is set and does not match the template"},
},
{
name: "no release notes with release notes requirement means an invalid bug",
issue: &jira.Issue{Fields: &jira.IssueFields{}},
options: JiraBranchOptions{RequireReleaseNotes: &yes, ReleaseNotesDefaultText: &oneStr},
valid: false,
why: []string{"release note type must be set and release note text must not match the template"},
why: []string{"release note text must be set and not match the template OR release note type must be set to \"Release Note Not Required\""},
},
{
name: "release notes matching default text means an invalid bug",
issue: &jira.Issue{Fields: &jira.IssueFields{
Unknowns: tcontainer.MarshalMap{
helpers.ReleaseNotesTextField: oneStr,
helpers.ReleaseNoteTextField: oneStr,
},
}},
options: JiraBranchOptions{RequireReleaseNotes: &yes, ReleaseNotesDefaultText: &oneStr},
valid: false,
why: []string{"release note type must be set and release note text must not match the template"},
why: []string{"release note text must be set and not match the template OR release note type must be set to \"Release Note Not Required\""},
},
{
name: "no release notes with release notes requirement but release type set to not required means an valid bug",
issue: &jira.Issue{Fields: &jira.IssueFields{Unknowns: tcontainer.MarshalMap{helpers.ReleaseNoteTypeField: helpers.CustomField{Value: "Release Note Not Required"}}}},
options: JiraBranchOptions{RequireReleaseNotes: &yes, ReleaseNotesDefaultText: &oneStr},
valid: true,
validations: []string{"release note type set to \"Release Note Not Required\""},
},
{
name: "matching target version requirement means a valid bug",
Expand Down
19 changes: 16 additions & 3 deletions pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const (
TargetVersionField = "customfield_12319940"
TargetVersionFieldOld = "customfield_12323140"
ReleaseBlockerField = "customfield_12319743"
ReleaseNotesTextField = "customfield_12317313"
ReleaseNoteTextField = "customfield_12317313"
SprintField = "customfield_12310940"
ReleaseNoteTypeField = "customfield_12320850"
)

// GetUnknownField will attempt to get the specified field from the Unknowns struct and unmarshal
Expand Down Expand Up @@ -130,9 +131,9 @@ type CustomField struct {
Disabled bool `json:"disabled"`
}

func GetIssueReleaseNotesText(issue *jira.Issue) (*string, error) {
func GetIssueReleaseNoteText(issue *jira.Issue) (*string, error) {
var obj *string
isSet, err := GetUnknownField(ReleaseNotesTextField, issue, func() interface{} {
isSet, err := GetUnknownField(ReleaseNoteTextField, issue, func() interface{} {
var field string
obj = &field
return obj
Expand All @@ -143,6 +144,18 @@ func GetIssueReleaseNotesText(issue *jira.Issue) (*string, error) {
return obj, err
}

func GetIssueReleaseNoteType(issue *jira.Issue) (*CustomField, error) {
var obj *CustomField
isSet, err := GetUnknownField(ReleaseNoteTypeField, issue, func() interface{} {
obj = &CustomField{}
return obj
})
if !isSet {
return nil, err
}
return obj, err
}

var activeSprintReg = regexp.MustCompile(",state=ACTIVE,")
var sprintIDReg = regexp.MustCompile("id=([0-9]+)")

Expand Down

0 comments on commit 3af1840

Please sign in to comment.