1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

githubPublishRelease: fix the link which points to changes between the last release and the new one (#4296)

This commit is contained in:
Vyacheslav Starostin 2023-03-27 21:39:46 +06:00 committed by GitHub
parent f5c33d51bb
commit d6e72995b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View File

@ -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

View File

@ -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) {