From 88909de70c00244cb273aa23653fc6b3b9e82cc7 Mon Sep 17 00:00:00 2001 From: Alex Pavel Date: Wed, 10 Jul 2024 21:33:24 +0000 Subject: [PATCH] server: improve comment for backport This PR adds some extra info specifying what issues were created and for what branches during a backport. This makes it easier for users to track what is going on without having to follow many links in the Jira UI. --- cmd/jira-lifecycle-plugin/server.go | 7 ++++++- cmd/jira-lifecycle-plugin/server_test.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/jira-lifecycle-plugin/server.go b/cmd/jira-lifecycle-plugin/server.go index 06e9983..1e00e40 100644 --- a/cmd/jira-lifecycle-plugin/server.go +++ b/cmd/jira-lifecycle-plugin/server.go @@ -2029,6 +2029,7 @@ func handleBackport(e event, gc githubClient, jc jiraclient.Client, repoOptions if len(branchesMissingDependents) != 0 { return comment(fmt.Sprintf("Missing required branches for backport chain: %v", missingDependencies.UnsortedList())) } + createdIssuesMessageLines := []string{} for _, refIssue := range e.issues { if !refIssue.IsBug { continue @@ -2049,6 +2050,7 @@ func handleBackport(e event, gc githubClient, jc jiraclient.Client, repoOptions var newLabels []string for key, branch := range createdIssues { newLabels = append(newLabels, fmt.Sprintf("jlp-%s:%s", branch, key)) + createdIssuesMessageLines = append(createdIssuesMessageLines, insertLinksIntoLine(fmt.Sprintf("- %s for branch %s", key, branch), []string{key}, jc.JiraURL())) } // sorting the labels isn't necessary for production but helps with tests sort.Strings(newLabels) @@ -2058,7 +2060,10 @@ func handleBackport(e event, gc githubClient, jc jiraclient.Client, repoOptions return comment(fmt.Sprintf("Failed to add label to issue %s: %v", issue.Key, err)) } } - return comment(fmt.Sprintf("All backport jira issues created. Queuing cherrypicks to the requested branches to be created after this PR merges:\n%s", cherrypickBranches)) + // make message deterministic for tests + sort.Strings(createdIssuesMessageLines) + createdIssuesMessage := strings.Join(createdIssuesMessageLines, "\n") + return comment(fmt.Sprintf("The following backport issues have been created:\n%s\n\nQueuing cherrypicks to the requested branches to be created after this PR merges:%s", createdIssuesMessage, cherrypickBranches)) } // createLinkedJiras recursively creates all descendants of the provided parent issue based on the child branches map diff --git a/cmd/jira-lifecycle-plugin/server_test.go b/cmd/jira-lifecycle-plugin/server_test.go index b99e45a..2f4a7ac 100644 --- a/cmd/jira-lifecycle-plugin/server_test.go +++ b/cmd/jira-lifecycle-plugin/server_test.go @@ -2988,8 +2988,13 @@ Instructions for interacting with me using PR comments are available [here](http "v4": {TargetVersion: &v4Str, DependentBugTargetVersions: &[]string{v5Str}}, "v5": {TargetVersion: &v5Str, DependentBugTargetVersions: nil}, }, - expectedComment: `org/repo#1:@user: All backport jira issues created. Queuing cherrypicks to the requested branches to be created after this PR merges: + expectedComment: `org/repo#1:@user: The following backport issues have been created: +- [OCPBUGS-124](https://my-jira.com/browse/OCPBUGS-124) for branch v4 +- [OCPBUGS-125](https://my-jira.com/browse/OCPBUGS-125) for branch v3 +- [OCPBUGS-126](https://my-jira.com/browse/OCPBUGS-126) for branch v2 +- [OCPBUGS-127](https://my-jira.com/browse/OCPBUGS-127) for branch v1 +Queuing cherrypicks to the requested branches to be created after this PR merges: /cherrypick v1 /cherrypick v2 /cherrypick v3