Skip to content

Commit

Permalink
fix(gitlab): correctly prepend/append/keep releases notes (#3765)
Browse files Browse the repository at this point in the history
Hi, I found a bug in the GitLab client that leads to not correctly
prepend/append/keep releases notes.

This will use the original `Description` instead of the pre-rendered
`DescriptionHTML`. Furthermore, as `include_html_description` is not
enabled, the `DescriptionHTML` field is always empty.

[GitLab
documentation](https://docs.gitlab.com/ee/api/releases/index.html#get-a-release-by-a-tag-name)
  • Loading branch information
christophwitzko committed Feb 7, 2023
1 parent 9da9f78 commit 90d8324
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/client/gitlab.go
Expand Up @@ -319,7 +319,7 @@ func (c *gitlabClient) CreateRelease(ctx *context.Context, body string) (release
} else {
desc := body
if release != nil {
desc = getReleaseNotes(release.DescriptionHTML, body, ctx.Config.Release.ReleaseNotesMode)
desc = getReleaseNotes(release.Description, body, ctx.Config.Release.ReleaseNotesMode)
}

release, _, err = c.client.Releases.UpdateRelease(projectID, tagName, &gitlab.UpdateReleaseOptions{
Expand Down
54 changes: 54 additions & 0 deletions internal/client/gitlab_test.go
Expand Up @@ -326,6 +326,60 @@ func TestGitLabCreateReleaseReleaseNotExists(t *testing.T) {
}
}

func TestGitLabCreateReleaseReleaseExists(t *testing.T) {
totalRequests := 0
createdRelease := false
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
totalRequests++

if !strings.Contains(r.URL.Path, "releases") {
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "{}")
return
}

// Check if release exists
if r.Method == http.MethodGet {
w.WriteHeader(200)
require.NoError(t, json.NewEncoder(w).Encode(map[string]string{
"description": "original description",
}))
return
}

// Update release
if r.Method == http.MethodPut {
createdRelease = true
var resBody map[string]string
require.NoError(t, json.NewDecoder(r.Body).Decode(&resBody))
require.Equal(t, "original description", resBody["description"])
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "{}")
return
}

require.FailNow(t, "should not reach here")
}))
defer srv.Close()

ctx := context.New(config.Project{
GitLabURLs: config.GitLabURLs{
API: srv.URL,
},
Release: config.Release{
ReleaseNotesMode: config.ReleaseNotesModeKeepExisting,
},
})
client, err := NewGitLab(ctx, "test-token")
require.NoError(t, err)

_, err = client.CreateRelease(ctx, "body")
require.NoError(t, err)
require.True(t, createdRelease)
require.Equal(t, 3, totalRequests)
}

func TestGitLabCreateReleaseUnkownHTTPError(t *testing.T) {
totalRequests := 0
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 90d8324

Please sign in to comment.