[BUG] Render correct label link

- Render the correct label for pull requests, it should link to the pull
requests list and not the issue list.
- Add unit test.
- Resolves https://codeberg.org/forgejo/forgejo/issues/3183
This commit is contained in:
Gusted 2024-04-12 14:31:44 +02:00
parent c3aed7cb69
commit 7a97c05206
No known key found for this signature in database
GPG key ID: FD821B732837125F
4 changed files with 50 additions and 23 deletions

View file

@ -239,15 +239,20 @@ func RenderMarkdownToHtml(ctx context.Context, input string) template.HTML { //n
return output
}
func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string) template.HTML {
func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string, isPull bool) template.HTML {
htmlCode := `<span class="labels-list">`
for _, label := range labels {
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
if label == nil {
continue
}
htmlCode += fmt.Sprintf("<a href='%s/issues?labels=%d'>%s</a> ",
repoLink, label.ID, RenderLabel(ctx, locale, label))
issuesOrPull := "issues"
if isPull {
issuesOrPull = "pulls"
}
htmlCode += fmt.Sprintf("<a href='%s/%s?labels=%d'>%s</a> ",
repoLink, issuesOrPull, label.ID, RenderLabel(ctx, locale, label))
}
htmlCode += "</span>"
return template.HTML(htmlCode)