Skip to content

Commit 4ca9064

Browse files
authored
Merge branch 'main' into expandercss
2 parents bdb9ee7 + 2ecd73d commit 4ca9064

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+222
-154
lines changed

models/renderhelper/commit_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *commitChecker) IsCommitIDExisting(commitID string) bool {
4747
c.gitRepo, c.gitRepoCloser = r, closer
4848
}
4949

50-
exist = c.gitRepo.IsReferenceExist(commitID) // Don't use IsObjectExist since it doesn't support short hashs with gogit edition.
50+
exist = c.gitRepo.IsReferenceExist(commitID) // Don't use IsObjectExist since it doesn't support short hashes with gogit edition.
5151
c.commitCache[commitID] = exist
5252
return exist
5353
}

modules/templates/util_date_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
func TestDateTime(t *testing.T) {
1818
testTz, _ := time.LoadLocation("America/New_York")
1919
defer test.MockVariableValue(&setting.DefaultUILocation, testTz)()
20+
defer test.MockVariableValue(&setting.IsProd, true)()
2021
defer test.MockVariableValue(&setting.IsInTesting, false)()
2122

2223
du := NewDateUtils()
@@ -53,6 +54,7 @@ func TestDateTime(t *testing.T) {
5354
func TestTimeSince(t *testing.T) {
5455
testTz, _ := time.LoadLocation("America/New_York")
5556
defer test.MockVariableValue(&setting.DefaultUILocation, testTz)()
57+
defer test.MockVariableValue(&setting.IsProd, true)()
5658
defer test.MockVariableValue(&setting.IsInTesting, false)()
5759

5860
du := NewDateUtils()

modules/templates/util_render.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"unicode"
1515

1616
issues_model "code.gitea.io/gitea/models/issues"
17+
"code.gitea.io/gitea/models/renderhelper"
18+
"code.gitea.io/gitea/models/repo"
1719
"code.gitea.io/gitea/modules/emoji"
1820
"code.gitea.io/gitea/modules/htmlutil"
1921
"code.gitea.io/gitea/modules/log"
@@ -34,11 +36,11 @@ func NewRenderUtils(ctx reqctx.RequestContext) *RenderUtils {
3436
}
3537

3638
// RenderCommitMessage renders commit message with XSS-safe and special links.
37-
func (ut *RenderUtils) RenderCommitMessage(msg string, metas map[string]string) template.HTML {
39+
func (ut *RenderUtils) RenderCommitMessage(msg string, repo *repo.Repository) template.HTML {
3840
cleanMsg := template.HTMLEscapeString(msg)
3941
// we can safely assume that it will not return any error, since there
4042
// shouldn't be any special HTML.
41-
fullMessage, err := markup.PostProcessCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), cleanMsg)
43+
fullMessage, err := markup.PostProcessCommitMessage(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), cleanMsg)
4244
if err != nil {
4345
log.Error("PostProcessCommitMessage: %v", err)
4446
return ""
@@ -52,7 +54,7 @@ func (ut *RenderUtils) RenderCommitMessage(msg string, metas map[string]string)
5254

5355
// RenderCommitMessageLinkSubject renders commit message as a XSS-safe link to
5456
// the provided default url, handling for special links without email to links.
55-
func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, metas map[string]string) template.HTML {
57+
func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, repo *repo.Repository) template.HTML {
5658
msgLine := strings.TrimLeftFunc(msg, unicode.IsSpace)
5759
lineEnd := strings.IndexByte(msgLine, '\n')
5860
if lineEnd > 0 {
@@ -63,9 +65,8 @@ func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, me
6365
return ""
6466
}
6567

66-
// we can safely assume that it will not return any error, since there
67-
// shouldn't be any special HTML.
68-
renderedMessage, err := markup.PostProcessCommitMessageSubject(markup.NewRenderContext(ut.ctx).WithMetas(metas), urlDefault, template.HTMLEscapeString(msgLine))
68+
// we can safely assume that it will not return any error, since there shouldn't be any special HTML.
69+
renderedMessage, err := markup.PostProcessCommitMessageSubject(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), urlDefault, template.HTMLEscapeString(msgLine))
6970
if err != nil {
7071
log.Error("PostProcessCommitMessageSubject: %v", err)
7172
return ""
@@ -74,7 +75,7 @@ func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, me
7475
}
7576

7677
// RenderCommitBody extracts the body of a commit message without its title.
77-
func (ut *RenderUtils) RenderCommitBody(msg string, metas map[string]string) template.HTML {
78+
func (ut *RenderUtils) RenderCommitBody(msg string, repo *repo.Repository) template.HTML {
7879
msgLine := strings.TrimSpace(msg)
7980
lineEnd := strings.IndexByte(msgLine, '\n')
8081
if lineEnd > 0 {
@@ -87,7 +88,7 @@ func (ut *RenderUtils) RenderCommitBody(msg string, metas map[string]string) tem
8788
return ""
8889
}
8990

90-
renderedMessage, err := markup.PostProcessCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(msgLine))
91+
renderedMessage, err := markup.PostProcessCommitMessage(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), template.HTMLEscapeString(msgLine))
9192
if err != nil {
9293
log.Error("PostProcessCommitMessage: %v", err)
9394
return ""
@@ -105,8 +106,8 @@ func renderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
105106
}
106107

107108
// RenderIssueTitle renders issue/pull title with defined post processors
108-
func (ut *RenderUtils) RenderIssueTitle(text string, metas map[string]string) template.HTML {
109-
renderedText, err := markup.PostProcessIssueTitle(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(text))
109+
func (ut *RenderUtils) RenderIssueTitle(text string, repo *repo.Repository) template.HTML {
110+
renderedText, err := markup.PostProcessIssueTitle(renderhelper.NewRenderContextRepoComment(ut.ctx, repo), template.HTMLEscapeString(text))
110111
if err != nil {
111112
log.Error("PostProcessIssueTitle: %v", err)
112113
return ""

modules/templates/util_render_legacy.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ func renderMarkdownToHtmlLegacy(ctx context.Context, input string) template.HTML
3232
return NewRenderUtils(reqctx.FromContext(ctx)).MarkdownToHtml(input)
3333
}
3434

35-
func renderCommitMessageLegacy(ctx context.Context, msg string, metas map[string]string) template.HTML {
35+
func renderCommitMessageLegacy(ctx context.Context, msg string, _ map[string]string) template.HTML {
3636
panicIfDevOrTesting()
37-
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessage(msg, metas)
37+
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessage(msg, nil)
3838
}
3939

40-
func renderCommitMessageLinkSubjectLegacy(ctx context.Context, msg, urlDefault string, metas map[string]string) template.HTML {
40+
func renderCommitMessageLinkSubjectLegacy(ctx context.Context, msg, urlDefault string, _ map[string]string) template.HTML {
4141
panicIfDevOrTesting()
42-
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessageLinkSubject(msg, urlDefault, metas)
42+
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitMessageLinkSubject(msg, urlDefault, nil)
4343
}
4444

45-
func renderIssueTitleLegacy(ctx context.Context, text string, metas map[string]string) template.HTML {
45+
func renderIssueTitleLegacy(ctx context.Context, text string, _ map[string]string) template.HTML {
4646
panicIfDevOrTesting()
47-
return NewRenderUtils(reqctx.FromContext(ctx)).RenderIssueTitle(text, metas)
47+
return NewRenderUtils(reqctx.FromContext(ctx)).RenderIssueTitle(text, nil)
4848
}
4949

50-
func renderCommitBodyLegacy(ctx context.Context, msg string, metas map[string]string) template.HTML {
50+
func renderCommitBodyLegacy(ctx context.Context, msg string, _ map[string]string) template.HTML {
5151
panicIfDevOrTesting()
52-
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitBody(msg, metas)
52+
return NewRenderUtils(reqctx.FromContext(ctx)).RenderCommitBody(msg, nil)
5353
}

modules/templates/util_render_test.go

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
"testing"
1212

1313
"code.gitea.io/gitea/models/issues"
14-
"code.gitea.io/gitea/models/unittest"
15-
"code.gitea.io/gitea/modules/git"
16-
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/models/repo"
15+
user_model "code.gitea.io/gitea/models/user"
1716
"code.gitea.io/gitea/modules/markup"
1817
"code.gitea.io/gitea/modules/reqctx"
18+
"code.gitea.io/gitea/modules/setting"
1919
"code.gitea.io/gitea/modules/test"
2020
"code.gitea.io/gitea/modules/translation"
2121

@@ -47,19 +47,8 @@ [email protected]
4747
return strings.ReplaceAll(s, "<SPACE>", " ")
4848
}
4949

50-
var testMetas = map[string]string{
51-
"user": "user13",
52-
"repo": "repo11",
53-
"repoPath": "../../tests/gitea-repositories-meta/user13/repo11.git/",
54-
"markdownNewLineHardBreak": "true",
55-
"markupAllowShortIssuePattern": "true",
56-
}
57-
5850
func TestMain(m *testing.M) {
59-
unittest.InitSettingsForTesting()
60-
if err := git.InitSimple(context.Background()); err != nil {
61-
log.Fatal("git init failed, err: %v", err)
62-
}
51+
setting.Markdown.RenderOptionsComment.ShortIssuePattern = true
6352
markup.Init(&markup.RenderHelperFuncs{
6453
IsUsernameMentionable: func(ctx context.Context, username string) bool {
6554
return username == "mention-user"
@@ -74,46 +63,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
7463
return NewRenderUtils(ctx)
7564
}
7665

77-
func TestRenderCommitBody(t *testing.T) {
78-
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
79-
type args struct {
80-
msg string
66+
func TestRenderRepoComment(t *testing.T) {
67+
mockRepo := &repo.Repository{
68+
ID: 1, OwnerName: "user13", Name: "repo11",
69+
Owner: &user_model.User{ID: 13, Name: "user13"},
70+
Units: []*repo.RepoUnit{},
8171
}
82-
tests := []struct {
83-
name string
84-
args args
85-
want template.HTML
86-
}{
87-
{
88-
name: "multiple lines",
89-
args: args{
90-
msg: "first line\nsecond line",
72+
t.Run("RenderCommitBody", func(t *testing.T) {
73+
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
74+
type args struct {
75+
msg string
76+
}
77+
tests := []struct {
78+
name string
79+
args args
80+
want template.HTML
81+
}{
82+
{
83+
name: "multiple lines",
84+
args: args{
85+
msg: "first line\nsecond line",
86+
},
87+
want: "second line",
9188
},
92-
want: "second line",
93-
},
94-
{
95-
name: "multiple lines with leading newlines",
96-
args: args{
97-
msg: "\n\n\n\nfirst line\nsecond line",
89+
{
90+
name: "multiple lines with leading newlines",
91+
args: args{
92+
msg: "\n\n\n\nfirst line\nsecond line",
93+
},
94+
want: "second line",
9895
},
99-
want: "second line",
100-
},
101-
{
102-
name: "multiple lines with trailing newlines",
103-
args: args{
104-
msg: "first line\nsecond line\n\n\n",
96+
{
97+
name: "multiple lines with trailing newlines",
98+
args: args{
99+
msg: "first line\nsecond line\n\n\n",
100+
},
101+
want: "second line",
105102
},
106-
want: "second line",
107-
},
108-
}
109-
ut := newTestRenderUtils(t)
110-
for _, tt := range tests {
111-
t.Run(tt.name, func(t *testing.T) {
112-
assert.Equalf(t, tt.want, ut.RenderCommitBody(tt.args.msg, nil), "RenderCommitBody(%v, %v)", tt.args.msg, nil)
113-
})
114-
}
115-
116-
expected := `/just/a/path.bin
103+
}
104+
ut := newTestRenderUtils(t)
105+
for _, tt := range tests {
106+
t.Run(tt.name, func(t *testing.T) {
107+
assert.Equalf(t, tt.want, ut.RenderCommitBody(tt.args.msg, mockRepo), "RenderCommitBody(%v, %v)", tt.args.msg, nil)
108+
})
109+
}
110+
111+
expected := `/just/a/path.bin
117112
<a href="https://example.com/file.bin">https://example.com/file.bin</a>
118113
[local link](file.bin)
119114
[remote link](<a href="https://example.com">https://example.com</a>)
@@ -132,22 +127,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132127
<a href="/mention-user">@mention-user</a> test
133128
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
134129
space`
135-
assert.Equal(t, expected, string(newTestRenderUtils(t).RenderCommitBody(testInput(), testMetas)))
136-
}
130+
assert.Equal(t, expected, string(newTestRenderUtils(t).RenderCommitBody(testInput(), mockRepo)))
131+
})
137132

138-
func TestRenderCommitMessage(t *testing.T) {
139-
expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
140-
assert.EqualValues(t, expected, newTestRenderUtils(t).RenderCommitMessage(testInput(), testMetas))
141-
}
133+
t.Run("RenderCommitMessage", func(t *testing.T) {
134+
expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
135+
assert.EqualValues(t, expected, newTestRenderUtils(t).RenderCommitMessage(testInput(), mockRepo))
136+
})
142137

143-
func TestRenderCommitMessageLinkSubject(t *testing.T) {
144-
expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
145-
assert.EqualValues(t, expected, newTestRenderUtils(t).RenderCommitMessageLinkSubject(testInput(), "https://example.com/link", testMetas))
146-
}
138+
t.Run("RenderCommitMessageLinkSubject", func(t *testing.T) {
139+
expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
140+
assert.EqualValues(t, expected, newTestRenderUtils(t).RenderCommitMessageLinkSubject(testInput(), "https://example.com/link", mockRepo))
141+
})
147142

148-
func TestRenderIssueTitle(t *testing.T) {
149-
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
150-
expected := ` space @mention-user<SPACE><SPACE>
143+
t.Run("RenderIssueTitle", func(t *testing.T) {
144+
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
145+
expected := ` space @mention-user<SPACE><SPACE>
151146
/just/a/path.bin
152147
https://example.com/file.bin
153148
[local link](file.bin)
@@ -168,8 +163,9 @@ [email protected]
168163
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
169164
space<SPACE><SPACE>
170165
`
171-
expected = strings.ReplaceAll(expected, "<SPACE>", " ")
172-
assert.Equal(t, expected, string(newTestRenderUtils(t).RenderIssueTitle(testInput(), testMetas)))
166+
expected = strings.ReplaceAll(expected, "<SPACE>", " ")
167+
assert.Equal(t, expected, string(newTestRenderUtils(t).RenderIssueTitle(testInput(), mockRepo)))
168+
})
173169
}
174170

175171
func TestRenderMarkdownToHtml(t *testing.T) {

options/locale/locale_cs-CZ.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,12 +3667,13 @@ owner.settings.chef.keypair.description=Pro autentizaci do registru Chef je zapo
36673667
secrets=Tajné klíče
36683668
description=Tejné klíče budou předány určitým akcím a nelze je přečíst jinak.
36693669
none=Zatím zde nejsou žádné tajné klíče.
3670-
creation=Přidat tajný klíč
3670+
3671+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
36713672
creation.description=Popis
36723673
creation.name_placeholder=nerozlišovat velká a malá písmena, pouze alfanumerické znaky nebo podtržítka, nemohou začínat na GITEA_ nebo GITHUB_
36733674
creation.value_placeholder=Vložte jakýkoliv obsah. Mezery na začátku a konci budou vynechány.
3674-
creation.success=Tajný klíč „%s“ byl přidán.
3675-
creation.failed=Nepodařilo se přidat tajný klíč.
3675+
3676+
36763677
deletion=Odstranit tajný klíč
36773678
deletion.description=Odstranění tajného klíče je trvalé a nelze ho vrátit zpět. Pokračovat?
36783679
deletion.success=Tajný klíč byl odstraněn.

options/locale/locale_de-DE.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,12 +3659,13 @@ owner.settings.chef.keypair.description=Ein Schlüsselpaar ist notwendig, um mit
36593659
secrets=Secrets
36603660
description=Secrets werden an bestimmte Aktionen weitergegeben und können nicht anderweitig ausgelesen werden.
36613661
none=Noch keine Secrets vorhanden.
3662-
creation=Secret hinzufügen
3662+
3663+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
36633664
creation.description=Beschreibung
36643665
creation.name_placeholder=Groß-/Kleinschreibung wird ignoriert, nur alphanumerische Zeichen oder Unterstriche, darf nicht mit GITEA_ oder GITHUB_ beginnen
36653666
creation.value_placeholder=Beliebigen Inhalt eingeben. Leerzeichen am Anfang und Ende werden weggelassen.
3666-
creation.success=Das Secret "%s" wurde hinzugefügt.
3667-
creation.failed=Secret konnte nicht hinzugefügt werden.
3667+
3668+
36683669
deletion=Secret entfernen
36693670
deletion.description=Das Entfernen eines Secrets kann nicht rückgängig gemacht werden. Fortfahren?
36703671
deletion.success=Das Secret wurde entfernt.

options/locale/locale_el-GR.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,12 +3329,13 @@ owner.settings.chef.keypair.description=Ένα ζεύγος κλειδιών ε
33293329
secrets=Μυστικά
33303330
description=Τα μυστικά θα περάσουν σε ορισμένες δράσεις και δεν μπορούν να αναγνωστούν αλλού.
33313331
none=Δεν υπάρχουν ακόμα μυστικά.
3332-
creation=Προσθήκη Μυστικού
3332+
3333+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
33333334
creation.description=Περιγραφή
33343335
creation.name_placeholder=αλφαριθμητικοί χαρακτήρες ή κάτω παύλες μόνο, δεν μπορούν να ξεκινούν με GITEA_ ή GITHUB_
33353336
creation.value_placeholder=Εισάγετε οποιοδήποτε περιεχόμενο. Τα κενά στην αρχή παραλείπονται.
3336-
creation.success=Το μυστικό "%s" προστέθηκε.
3337-
creation.failed=Αποτυχία δημιουργίας μυστικού.
3337+
3338+
33383339
deletion=Αφαίρεση μυστικού
33393340
deletion.description=Η αφαίρεση ενός μυστικού είναι μόνιμη και δεν μπορεί να αναιρεθεί. Συνέχεια;
33403341
deletion.success=Το μυστικό έχει αφαιρεθεί.

options/locale/locale_es-ES.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,12 +3309,13 @@ owner.settings.chef.keypair.description=Un par de claves es necesario para auten
33093309
secrets=Secretos
33103310
description=Los secretos pasarán a ciertas acciones y no se podrán leer de otro modo.
33113311
none=Todavía no hay secretos.
3312-
creation=Añadir secreto
3312+
3313+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
33133314
creation.description=Descripción
33143315
creation.name_placeholder=sin distinción de mayúsculas, solo carácteres alfanuméricos o guiones bajos, no puede empezar por GITEA_ o GITHUB_
33153316
creation.value_placeholder=Introduce cualquier contenido. Se omitirá el espacio en blanco en el inicio y el final.
3316-
creation.success=El secreto "%s" ha sido añadido.
3317-
creation.failed=Error al añadir secreto.
3317+
3318+
33183319
deletion=Eliminar secreto
33193320
deletion.description=Eliminar un secreto es permanente y no se puede deshacer. ¿Continuar?
33203321
deletion.success=El secreto ha sido eliminado.

options/locale/locale_fa-IR.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,12 @@ conan.details.repository=مخزن
25062506
owner.settings.cleanuprules.enabled=فعال شده
25072507

25082508
[secrets]
2509+
2510+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
25092511
creation.description=شرح
25102512

2513+
2514+
25112515
[actions]
25122516

25132517

0 commit comments

Comments
 (0)