Skip to content

Commit

Permalink
Merge pull request #104 from AlexNPavel/fix-assignee-wait
Browse files Browse the repository at this point in the history
server: fix assignee race condition
  • Loading branch information
openshift-merge-bot[bot] committed Jul 10, 2024
2 parents b07073a + 3f1e8fe commit 85df48a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
24 changes: 15 additions & 9 deletions cmd/jira-lifecycle-plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,22 +1894,28 @@ func createCherryPickBug(jc jiraclient.Client, bug *jira.Issue, branch string, o
return clone.Key, fmt.Sprintf("Detected clone of %s with correct target version. Will retitle the PR to link to the clone.", oldLink), nil
}
}
// clone the bug in order to not lose fields during backports, which reuse *bug
bugCopy := *bug
copyFields := *bug.Fields
bugCopy.Fields = &copyFields
// TODO: these fields can cause the clone to fail if not manually removed. It may be better to
// perform some recursion when cloning issues, as these only error when everything else is correct...
delete(bug.Fields.Unknowns, "environment")
delete(bug.Fields.Unknowns, "customfield_12318341")
delete(bugCopy.Fields.Unknowns, "environment")
delete(bugCopy.Fields.Unknowns, "customfield_12318341")
// This is the sprint field; sprints are handled by a custom plugin, and the data given to us via
// GetIssue is invalid for setting the field ourselves
sprintField := bug.Fields.Unknowns[helpers.SprintField]
delete(bug.Fields.Unknowns, helpers.SprintField)
releaseNoteType := bug.Fields.Unknowns[helpers.ReleaseNoteTypeField]
releaseNoteText := bug.Fields.Unknowns[helpers.ReleaseNoteTextField]
sprintField := bugCopy.Fields.Unknowns[helpers.SprintField]
delete(bugCopy.Fields.Unknowns, helpers.SprintField)
releaseNoteType := bugCopy.Fields.Unknowns[helpers.ReleaseNoteTypeField]
releaseNoteText := bugCopy.Fields.Unknowns[helpers.ReleaseNoteTextField]
if len(options.IgnoreCloneLabels) != 0 {
labelsSet := sets.New[string](bug.Fields.Labels...)
labelsSet := sets.New[string](bugCopy.Fields.Labels...)
labelsSet.Delete(options.IgnoreCloneLabels...)
bug.Fields.Labels = labelsSet.UnsortedList()
bugCopy.Fields.Labels = labelsSet.UnsortedList()
}
clone, err := jc.CloneIssue(bug)
// unset assignee so we can more easily check when jira's internal auto-assign completes
bugCopy.Fields.Assignee = nil
clone, err := jc.CloneIssue(&bugCopy)
if err != nil {
log.WithError(err).Debugf("Failed to clone bug %+v", bug)
return "", "", errors.New(formatError("cloning bug for cherrypick", jc.JiraURL(), bug.Key, err))
Expand Down
10 changes: 8 additions & 2 deletions cmd/jira-lifecycle-plugin/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ func (f *fakeJiraClient) CloneIssue(issue *jira.Issue) (*jira.Issue, error) {
newFields := *issue.Fields
newIssue.Fields = &newFields
newIssue.Fields.IssueLinks = nil
return jiraclient.CloneIssue(f, &newIssue)
clonedIssue, err := jiraclient.CloneIssue(f, &newIssue)
if err != nil {
return clonedIssue, err
}
// simulate auto-assignee plugin for jira
clonedIssue.Fields.Assignee = &jira.User{Name: "defaultAssignee"}
return clonedIssue, err
}

func TestHandle(t *testing.T) {
Expand Down Expand Up @@ -2213,7 +2219,7 @@ In response to [this](https://github.com/org/repo/pull/1):
Instructions for interacting with me using PR comments are available [here](https://prow.ci.openshift.org/command-help?repo=org%2Frepo). If you have questions or suggestions related to my behavior, please file an issue against the [openshift-eng/jira-lifecycle-plugin](https://github.com/openshift-eng/jira-lifecycle-plugin/issues/new) repository.
</details>`,
expectedIssues: []*jira.Issue{{ID: "3", Key: "OCPBUGS-125", Fields: &jira.IssueFields{
Assignee: &jira.User{Name: "testUser"},
Assignee: &jira.User{Name: "defaultAssignee"},
Description: "This is a clone of issue OCPBUGS-123. The following is the description of the original issue: \n---\n",
Status: &jira.Status{Name: "CLOSED"},
Comments: &jira.Comments{Comments: []*jira.Comment{{
Expand Down

0 comments on commit 85df48a

Please sign in to comment.