From d6e72995b03f36c6dbf6c5efe0f0b252b77809f6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Starostin <32613074+vstarostin@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:39:46 +0600 Subject: [PATCH] githubPublishRelease: fix the link which points to changes between the last release and the new one (#4296) --- cmd/githubPublishRelease.go | 5 ++-- cmd/githubPublishRelease_test.go | 42 ++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/cmd/githubPublishRelease.go b/cmd/githubPublishRelease.go index 2ff51d338..3f8c235e7 100644 --- a/cmd/githubPublishRelease.go +++ b/cmd/githubPublishRelease.go @@ -145,17 +145,18 @@ func getClosedIssuesText(ctx context.Context, publishedAt github.Timestamp, conf func getReleaseDeltaText(config *githubPublishReleaseOptions, lastRelease *github.RepositoryRelease) string { releaseDeltaText := "" + tagName := config.TagPrefix + config.Version // add delta link to previous release releaseDeltaText += "\n**Changes**\n" releaseDeltaText += fmt.Sprintf( "[%v...%v](%v/%v/%v/compare/%v...%v)\n", lastRelease.GetTagName(), - config.Version, + tagName, config.ServerURL, config.Owner, config.Repository, - lastRelease.GetTagName(), config.Version, + lastRelease.GetTagName(), tagName, ) return releaseDeltaText diff --git a/cmd/githubPublishRelease_test.go b/cmd/githubPublishRelease_test.go index 717900a8d..6d3db742e 100644 --- a/cmd/githubPublishRelease_test.go +++ b/cmd/githubPublishRelease_test.go @@ -314,20 +314,36 @@ func TestGetClosedIssuesText(t *testing.T) { } func TestGetReleaseDeltaText(t *testing.T) { - myGithubPublishReleaseOptions := githubPublishReleaseOptions{ - Owner: "TEST", - Repository: "test", - ServerURL: "https://github.com", - Version: "1.1", - } - lastTag := "1.0" - lastRelease := github.RepositoryRelease{ - TagName: &lastTag, - } + t.Run("test case without TagPrefix for new release", func(t *testing.T) { + myGithubPublishReleaseOptions := githubPublishReleaseOptions{ + Owner: "TEST", + Repository: "test", + ServerURL: "https://github.com", + Version: "1.1", + } + lastTag := "1.0" + lastRelease := github.RepositoryRelease{ + TagName: &lastTag, + } + res := getReleaseDeltaText(&myGithubPublishReleaseOptions, &lastRelease) + assert.Equal(t, "\n**Changes**\n[1.0...1.1](https://github.com/TEST/test/compare/1.0...1.1)\n", res) + }) - res := getReleaseDeltaText(&myGithubPublishReleaseOptions, &lastRelease) - - assert.Equal(t, "\n**Changes**\n[1.0...1.1](https://github.com/TEST/test/compare/1.0...1.1)\n", res) + t.Run("test case with TagPrefix for new release", func(t *testing.T) { + myGithubPublishReleaseOptions := githubPublishReleaseOptions{ + Owner: "TEST", + Repository: "test", + ServerURL: "https://github.com", + Version: "1.1", + TagPrefix: "release/", + } + lastTag := "1.0" + lastRelease := github.RepositoryRelease{ + TagName: &lastTag, + } + res := getReleaseDeltaText(&myGithubPublishReleaseOptions, &lastRelease) + assert.Equal(t, "\n**Changes**\n[1.0...release/1.1](https://github.com/TEST/test/compare/1.0...release/1.1)\n", res) + }) } func TestUploadReleaseAsset(t *testing.T) {