Skip to content

Commit ac760c9

Browse files
committed
fix
1 parent b4d8691 commit ac760c9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

modules/templates/util_render.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,16 @@ func RenderMarkdownToHtml(ctx context.Context, input string) template.HTML { //n
216216
return output
217217
}
218218

219-
func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string) template.HTML {
219+
func RenderLabels(ctx context.Context, locale translation.Locale, labels []*issues_model.Label, repoLink string, issue *issues_model.Issue) template.HTML {
220+
isPullRequest := issue != nil && issue.IsPull
221+
baseLink := fmt.Sprintf("%s/%s", repoLink, util.Iif(isPullRequest, "pulls", "issues"))
220222
htmlCode := `<span class="labels-list">`
221223
for _, label := range labels {
222224
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
223225
if label == nil {
224226
continue
225227
}
226-
htmlCode += fmt.Sprintf("<a href='%s/issues?labels=%d'>%s</a> ",
227-
repoLink, label.ID, RenderLabel(ctx, locale, label))
228+
htmlCode += fmt.Sprintf(`<a href="%s?labels=%d">%s</a>`, baseLink, label.ID, RenderLabel(ctx, locale, label))
228229
}
229230
htmlCode += "</span>"
230231
return template.HTML(htmlCode)

modules/templates/util_render_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import (
99
"os"
1010
"testing"
1111

12+
"code.gitea.io/gitea/models/issues"
1213
"code.gitea.io/gitea/models/unittest"
1314
"code.gitea.io/gitea/modules/git"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/markup"
17+
"code.gitea.io/gitea/modules/translation"
1618

1719
"github.com/stretchr/testify/assert"
1820
)
1921

20-
const testInput = ` space @mention-user
22+
const testInput = ` space @mention-user
2123
/just/a/path.bin
2224
https://example.com/file.bin
2325
[local link](file.bin)
@@ -36,7 +38,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
3638
mail@domain.com
3739
@mention-user test
3840
#123
39-
space
41+
space
4042
`
4143

4244
var testMetas = map[string]string{
@@ -137,7 +139,7 @@ func TestRenderCommitMessageLinkSubject(t *testing.T) {
137139
}
138140

139141
func TestRenderIssueTitle(t *testing.T) {
140-
expected := ` space @mention-user
142+
expected := ` space @mention-user
141143
/just/a/path.bin
142144
https://example.com/file.bin
143145
[local link](file.bin)
@@ -156,7 +158,7 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
156158
mail@domain.com
157159
@mention-user test
158160
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
159-
space
161+
space
160162
`
161163
assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput, testMetas))
162164
}
@@ -185,3 +187,18 @@ space</p>
185187
`
186188
assert.EqualValues(t, expected, RenderMarkdownToHtml(context.Background(), testInput))
187189
}
190+
191+
func TestRenderLabels(t *testing.T) {
192+
ctx := context.Background()
193+
locale := &translation.MockLocale{}
194+
195+
label := &issues.Label{ID: 123, Name: "label-name", Color: "label-color"}
196+
issue := &issues.Issue{}
197+
expected := `/owner/repo/issues?labels=123`
198+
assert.Contains(t, RenderLabels(ctx, locale, []*issues.Label{label}, "/owner/repo", issue), expected)
199+
200+
label = &issues.Label{ID: 123, Name: "label-name", Color: "label-color"}
201+
issue = &issues.Issue{IsPull: true}
202+
expected = `/owner/repo/pulls?labels=123`
203+
assert.Contains(t, RenderLabels(ctx, locale, []*issues.Label{label}, "/owner/repo", issue), expected)
204+
}

templates/repo/issue/view_content/comments.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@
173173
<span class="text grey muted-links">
174174
{{template "shared/user/authorlink" .Poster}}
175175
{{if and .AddedLabels (not .RemovedLabels)}}
176-
{{ctx.Locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels $.Context ctx.Locale .AddedLabels $.RepoLink) $createdStr}}
176+
{{ctx.Locale.TrN (len .AddedLabels) "repo.issues.add_label" "repo.issues.add_labels" (RenderLabels ctx ctx.Locale .AddedLabels $.RepoLink .Issue) $createdStr}}
177177
{{else if and (not .AddedLabels) .RemovedLabels}}
178-
{{ctx.Locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels $.Context ctx.Locale .RemovedLabels $.RepoLink) $createdStr}}
178+
{{ctx.Locale.TrN (len .RemovedLabels) "repo.issues.remove_label" "repo.issues.remove_labels" (RenderLabels ctx ctx.Locale .RemovedLabels $.RepoLink .Issue) $createdStr}}
179179
{{else}}
180-
{{ctx.Locale.Tr "repo.issues.add_remove_labels" (RenderLabels $.Context ctx.Locale .AddedLabels $.RepoLink) (RenderLabels $.Context ctx.Locale .RemovedLabels $.RepoLink) $createdStr}}
180+
{{ctx.Locale.Tr "repo.issues.add_remove_labels" (RenderLabels ctx ctx.Locale .AddedLabels $.RepoLink .Issue) (RenderLabels ctx ctx.Locale .RemovedLabels $.RepoLink .Issue) $createdStr}}
181181
{{end}}
182182
</span>
183183
</div>

0 commit comments

Comments
 (0)