Skip to content

Commit b842d2a

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: [skip ci] Updated translations via Crowdin fix artifact merging chunks path with correct slash on Windows (go-gitea#26400) Use flex classes in package settings (go-gitea#26314) Improve multiple strings in en-US locale (go-gitea#26213) Refactor "editorconfig" (go-gitea#26391) fix generated source URL on rendered files (go-gitea#26364) Remove unnecessary template helper DisableGravatar (go-gitea#26386)
2 parents 7a94ddf + 906e253 commit b842d2a

File tree

18 files changed

+294
-242
lines changed

18 files changed

+294
-242
lines changed

models/fixtures/repo_unit.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,15 @@
637637
repo_id: 58
638638
type: 5
639639
created_unix: 946684810
640+
641+
-
642+
id: 96
643+
repo_id: 49
644+
type: 1
645+
created_unix: 946684810
646+
647+
-
648+
id: 97
649+
repo_id: 49
650+
type: 2
651+
created_unix: 946684810

modules/templates/helper.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
package templates
66

77
import (
8-
"context"
98
"fmt"
109
"html"
1110
"html/template"
1211
"net/url"
1312
"strings"
1413
"time"
1514

16-
system_model "code.gitea.io/gitea/models/system"
1715
"code.gitea.io/gitea/modules/base"
1816
"code.gitea.io/gitea/modules/emoji"
1917
"code.gitea.io/gitea/modules/markup"
@@ -104,9 +102,6 @@ func NewFuncMap() template.FuncMap {
104102
"AssetVersion": func() string {
105103
return setting.AssetVersion
106104
},
107-
"DisableGravatar": func(ctx context.Context) bool {
108-
return system_model.GetSettingWithCacheBool(ctx, system_model.KeyPictureDisableGravatar)
109-
},
110105
"DefaultShowFullName": func() bool {
111106
return setting.UI.DefaultShowFullName
112107
},

modules/templates/util_misc.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package templates
55

66
import (
77
"context"
8-
"fmt"
98
"html/template"
109
"mime"
1110
"path/filepath"
11+
"strconv"
1212
"strings"
1313
"time"
1414

@@ -174,23 +174,12 @@ func FilenameIsImage(filename string) bool {
174174
return strings.HasPrefix(mimeType, "image/")
175175
}
176176

177-
func TabSizeClass(ec any, filename string) string {
178-
var (
179-
value *editorconfig.Editorconfig
180-
ok bool
181-
)
177+
func TabSizeClass(ec *editorconfig.Editorconfig, filename string) string {
182178
if ec != nil {
183-
if value, ok = ec.(*editorconfig.Editorconfig); !ok || value == nil {
184-
return "tab-size-8"
185-
}
186-
def, err := value.GetDefinitionForFilename(filename)
187-
if err != nil {
188-
log.Error("tab size class: getting definition for filename: %v", err)
189-
return "tab-size-8"
190-
}
191-
if def.TabWidth > 0 {
192-
return fmt.Sprintf("tab-size-%d", def.TabWidth)
179+
def, err := ec.GetDefinitionForFilename(filename)
180+
if err == nil && def.TabWidth >= 1 && def.TabWidth <= 16 {
181+
return "tab-size-" + strconv.Itoa(def.TabWidth)
193182
}
194183
}
195-
return "tab-size-8"
184+
return "tab-size-4"
196185
}

options/locale/locale_de-DE.ini

Lines changed: 101 additions & 101 deletions
Large diffs are not rendered by default.

options/locale/locale_en-US.ini

Lines changed: 80 additions & 78 deletions
Large diffs are not rendered by default.

routers/api/actions/artifacts_chunks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/base64"
99
"fmt"
1010
"io"
11+
"path/filepath"
1112
"sort"
1213
"time"
1314

@@ -67,7 +68,7 @@ func listChunksByRunID(st storage.ObjectStorage, runID int64) (map[int64][]*chun
6768
var chunks []*chunkFileItem
6869
if err := st.IterateObjects(storageDir, func(path string, obj storage.Object) error {
6970
item := chunkFileItem{Path: path}
70-
if _, err := fmt.Sscanf(path, storageDir+"/%d-%d-%d.chunk", &item.ArtifactID, &item.Start, &item.End); err != nil {
71+
if _, err := fmt.Sscanf(path, filepath.Join(storageDir, "%d-%d-%d.chunk"), &item.ArtifactID, &item.Start, &item.End); err != nil {
7172
return fmt.Errorf("parse content range error: %v", err)
7273
}
7374
chunks = append(chunks, &item)

routers/web/admin/users.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models"
1414
"code.gitea.io/gitea/models/auth"
1515
"code.gitea.io/gitea/models/db"
16+
system_model "code.gitea.io/gitea/models/system"
1617
user_model "code.gitea.io/gitea/models/user"
1718
"code.gitea.io/gitea/modules/auth/password"
1819
"code.gitea.io/gitea/modules/base"
@@ -255,6 +256,7 @@ func EditUser(ctx *context.Context) {
255256
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
256257
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
257258
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
259+
ctx.Data["DisableGravatar"] = system_model.GetSettingWithCacheBool(ctx, system_model.KeyPictureDisableGravatar)
258260

259261
prepareUserInfo(ctx)
260262
if ctx.Written() {
@@ -271,6 +273,7 @@ func EditUserPost(ctx *context.Context) {
271273
ctx.Data["PageIsAdminUsers"] = true
272274
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
273275
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
276+
ctx.Data["DisableGravatar"] = system_model.GetSettingWithCacheBool(ctx, system_model.KeyPictureDisableGravatar)
274277

275278
u := prepareUserInfo(ctx)
276279
if ctx.Written() {

routers/web/repo/editor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
191191
ctx.Data["last_commit"] = ctx.Repo.CommitID
192192
ctx.Data["PreviewableExtensions"] = strings.Join(markup.PreviewableExtensions(), ",")
193193
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
194-
ctx.Data["Editorconfig"] = GetEditorConfig(ctx, treePath)
194+
ctx.Data["EditorconfigJson"] = GetEditorConfig(ctx, treePath)
195195

196196
ctx.HTML(http.StatusOK, tplEditFile)
197197
}
@@ -242,7 +242,7 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
242242
ctx.Data["last_commit"] = ctx.Repo.CommitID
243243
ctx.Data["PreviewableExtensions"] = strings.Join(markup.PreviewableExtensions(), ",")
244244
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
245-
ctx.Data["Editorconfig"] = GetEditorConfig(ctx, form.TreePath)
245+
ctx.Data["EditorconfigJson"] = GetEditorConfig(ctx, form.TreePath)
246246

247247
if ctx.HasError() {
248248
ctx.HTML(http.StatusOK, tplEditFile)

routers/web/user/setting/profile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"code.gitea.io/gitea/models/db"
1818
"code.gitea.io/gitea/models/organization"
1919
repo_model "code.gitea.io/gitea/models/repo"
20+
system_model "code.gitea.io/gitea/models/system"
2021
user_model "code.gitea.io/gitea/models/user"
2122
"code.gitea.io/gitea/modules/base"
2223
"code.gitea.io/gitea/modules/context"
@@ -43,6 +44,7 @@ func Profile(ctx *context.Context) {
4344
ctx.Data["Title"] = ctx.Tr("settings.profile")
4445
ctx.Data["PageIsSettingsProfile"] = true
4546
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
47+
ctx.Data["DisableGravatar"] = system_model.GetSettingWithCacheBool(ctx, system_model.KeyPictureDisableGravatar)
4648

4749
ctx.HTML(http.StatusOK, tplSettingsProfile)
4850
}
@@ -83,6 +85,8 @@ func ProfilePost(ctx *context.Context) {
8385
form := web.GetForm(ctx).(*forms.UpdateProfileForm)
8486
ctx.Data["Title"] = ctx.Tr("settings")
8587
ctx.Data["PageIsSettingsProfile"] = true
88+
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
89+
ctx.Data["DisableGravatar"] = system_model.GetSettingWithCacheBool(ctx, system_model.KeyPictureDisableGravatar)
8690

8791
if ctx.HasError() {
8892
ctx.HTML(http.StatusOK, tplSettingsProfile)

templates/admin/user/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<div class="ui attached segment">
160160
<form class="ui form" action="{{.Link}}/avatar" method="post" enctype="multipart/form-data">
161161
{{.CsrfTokenHtml}}
162-
{{if not (DisableGravatar $.Context)}}
162+
{{if not .DisableGravatar}}
163163
<div class="inline field">
164164
<div class="ui radio checkbox">
165165
<input name="source" value="lookup" type="radio" {{if not .User.UseCustomAvatar}}checked{{end}}>

templates/org/team/members.tmpl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,23 @@
5353
</div>
5454
{{if and .Invites $.IsOrganizationOwner}}
5555
<h4 class="ui top attached header">{{$.locale.Tr "org.teams.invite_team_member.list"}}</h4>
56-
<div class="ui bottom attached table segment members">
57-
{{range .Invites}}
58-
<div class="item gt-df gt-ac gt-fw">
59-
<span class="gt-f1">{{.Email}}</span>
60-
<form action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/remove_invite" method="post">
61-
{{$.CsrfTokenHtml}}
62-
<input type="hidden" name="iid" value="{{.ID}}">
63-
<button class="ui red button">{{$.locale.Tr "org.members.remove"}}</button>
64-
</form>
65-
</div>
66-
{{end}}
56+
<div class="ui attached segment">
57+
<div class="flex-list">
58+
{{range .Invites}}
59+
<div class="flex-item flex-item-center">
60+
<div class="flex-item-main">
61+
{{.Email}}
62+
</div>
63+
<div class="flex-item-trailing">
64+
<form action="{{$.OrgLink}}/teams/{{$.Team.LowerName | PathEscape}}/action/remove_invite" method="post">
65+
{{$.CsrfTokenHtml}}
66+
<input type="hidden" name="iid" value="{{.ID}}">
67+
<button class="ui red button">{{$.locale.Tr "org.members.remove"}}</button>
68+
</form>
69+
</div>
70+
</div>
71+
{{end}}
72+
</div>
6773
</div>
6874
{{end}}
6975
</div>

templates/package/settings.tmpl

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,30 @@
3838
<h4 class="ui top attached error header">
3939
{{.locale.Tr "repo.settings.danger_zone"}}
4040
</h4>
41-
<div class="ui attached error table danger segment">
42-
<div class="item">
43-
<div class="ui right">
44-
<button class="ui basic red show-modal button" data-modal="#delete-package-modal">{{.locale.Tr "packages.settings.delete"}}</button>
45-
</div>
46-
<div>
47-
<h5>{{.locale.Tr "packages.settings.delete"}}</h5>
48-
<p>{{.locale.Tr "packages.settings.delete.description"}}</p>
49-
</div>
50-
<div class="ui tiny modal" id="delete-package-modal">
51-
<div class="header">
52-
{{.locale.Tr "packages.settings.delete"}}
41+
<div class="ui attached error danger segment">
42+
<div class="flex-list">
43+
<div class="flex-item">
44+
<div class="flex-item-main">
45+
<div class="flex-item-title">{{.locale.Tr "packages.settings.delete"}}</div>
46+
<div class="flex-item-body">{{.locale.Tr "packages.settings.delete.description"}}</div>
5347
</div>
54-
<div class="content">
55-
<div class="ui warning message gt-word-break">
56-
{{.locale.Tr "packages.settings.delete.notice" .PackageDescriptor.Package.Name .PackageDescriptor.Version.Version}}
48+
<div class="flex-item-trailing">
49+
<button class="ui basic red show-modal button" data-modal="#delete-package-modal">{{.locale.Tr "packages.settings.delete"}}</button>
50+
</div>
51+
<div class="ui tiny modal" id="delete-package-modal">
52+
<div class="header">
53+
{{.locale.Tr "packages.settings.delete"}}
54+
</div>
55+
<div class="content">
56+
<div class="ui warning message gt-word-break">
57+
{{.locale.Tr "packages.settings.delete.notice" .PackageDescriptor.Package.Name .PackageDescriptor.Version.Version}}
58+
</div>
59+
<form class="ui form" action="{{.Link}}" method="post">
60+
{{.CsrfTokenHtml}}
61+
<input type="hidden" name="action" value="delete">
62+
{{template "base/modal_actions_confirm" .}}
63+
</form>
5764
</div>
58-
<form class="ui form" action="{{.Link}}" method="post">
59-
{{.CsrfTokenHtml}}
60-
<input type="hidden" name="action" value="delete">
61-
{{template "base/modal_actions_confirm" .}}
62-
</form>
6365
</div>
6466
</div>
6567
</div>

templates/repo/editor/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{range $i, $v := .TreeNames}}
1616
<div class="divider"> / </div>
1717
{{if eq $i $l}}
18-
<input id="file-name" value="{{$v}}" placeholder="{{$.locale.Tr "repo.editor.name_your_file"}}" data-editorconfig="{{$.Editorconfig}}" required autofocus>
18+
<input id="file-name" value="{{$v}}" placeholder="{{$.locale.Tr "repo.editor.name_your_file"}}" data-editorconfig="{{$.EditorconfigJson}}" required autofocus>
1919
<span data-tooltip-content="{{$.locale.Tr "repo.editor.filename_help"}}">{{svg "octicon-info"}}</span>
2020
{{else}}
2121
<span class="section"><a href="{{$.BranchLink}}/{{index $.TreePaths $i | PathEscapeSegments}}">{{$v}}</a></span>

templates/repo/settings/options.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@
8383
{{$.locale.Tr "repo.settings.mirror_settings.docs"}}
8484
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pushing-to<ing-to-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
8585
{{$.locale.Tr "repo.settings.mirror_settings.docs.pull_mirror_instructions"}}
86-
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br>
86+
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_pull_section"}}</a><br>
8787
{{else if $onlyNewPushMirrorsEnabled}}
8888
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_pull_mirror.instructions"}}
89+
{{$.locale.Tr "repo.settings.mirror_settings.docs.more_information_if_disabled"}}
8990
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br>
9091
{{else if $onlyNewPullMirrorsEnabled}}
9192
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.instructions"}}
9293
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.pull_mirror_warning"}}
94+
{{$.locale.Tr "repo.settings.mirror_settings.docs.more_information_if_disabled"}}
9395
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
9496
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.info"}}
9597
{{if $existingPushMirror}}

templates/repo/view_file.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@
116116
</table>
117117
<div class="code-line-menu ui vertical pointing menu tippy-target">
118118
{{if $.Permission.CanRead $.UnitTypeIssues}}
119-
<a class="item ref-in-new-issue" data-url-issue-new="{{.RepoLink}}/issues/new" data-url-param-body-link="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}" rel="nofollow noindex">{{.locale.Tr "repo.issues.context.reference_issue"}}</a>
119+
<a class="item ref-in-new-issue" data-url-issue-new="{{.RepoLink}}/issues/new" data-url-param-body-link="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}" rel="nofollow noindex">{{.locale.Tr "repo.issues.context.reference_issue"}}</a>
120120
{{end}}
121121
<a class="item view_git_blame" href="{{.Repository.Link}}/blame/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}">{{.locale.Tr "repo.view_git_blame"}}</a>
122-
<a class="item copy-line-permalink" data-url="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}">{{.locale.Tr "repo.file_copy_permalink"}}</a>
122+
<a class="item copy-line-permalink" data-url="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}">{{.locale.Tr "repo.file_copy_permalink"}}</a>
123123
</div>
124124
{{end}}
125125
{{end}}

templates/user/settings/profile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<div class="ui attached segment">
100100
<form class="ui form" action="{{.Link}}/avatar" method="post" enctype="multipart/form-data">
101101
{{.CsrfTokenHtml}}
102-
{{if not (DisableGravatar $.Context)}}
102+
{{if not .DisableGravatar}}
103103
<div class="inline field">
104104
<div class="ui radio checkbox">
105105
<input name="source" value="lookup" type="radio" {{if not .SignedUser.UseCustomAvatar}}checked{{end}}>

tests/e2e/example.test.e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('Test Register Form', async ({page}, workerInfo) => {
2424
// Make sure we routed to the home page. Else login failed.
2525
await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
2626
await expect(page.locator('.dashboard-navbar span>img.ui.avatar')).toBeVisible();
27-
await expect(page.locator('.ui.positive.message.flash-success')).toHaveText('Account was successfully created.');
27+
await expect(page.locator('.ui.positive.message.flash-success')).toHaveText('Account was successfully created. Welcome!');
2828

2929
save_visual(page);
3030
});

tests/integration/repo_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,39 @@ func TestMarkDownReadmeImageSubfolder(t *testing.T) {
408408
assert.True(t, exists, "Image not found in markdown file")
409409
assert.Equal(t, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg", src)
410410
}
411+
412+
func TestGeneratedSourceLink(t *testing.T) {
413+
defer tests.PrepareTestEnv(t)()
414+
415+
t.Run("Rendered file", func(t *testing.T) {
416+
defer tests.PrintCurrentTest(t)()
417+
req := NewRequest(t, "GET", "/user2/repo1/src/branch/master/README.md?display=source")
418+
resp := MakeRequest(t, req, http.StatusOK)
419+
doc := NewHTMLParser(t, resp.Body)
420+
421+
dataURL, exists := doc.doc.Find(".copy-line-permalink").Attr("data-url")
422+
assert.True(t, exists)
423+
assert.Equal(t, "/user2/repo1/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d/README.md?display=source", dataURL)
424+
425+
dataURL, exists = doc.doc.Find(".ref-in-new-issue").Attr("data-url-param-body-link")
426+
assert.True(t, exists)
427+
assert.Equal(t, "/user2/repo1/src/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d/README.md?display=source", dataURL)
428+
})
429+
430+
t.Run("Non-Rendered file", func(t *testing.T) {
431+
defer tests.PrintCurrentTest(t)()
432+
433+
session := loginUser(t, "user27")
434+
req := NewRequest(t, "GET", "/user27/repo49/src/branch/master/test/test.txt")
435+
resp := session.MakeRequest(t, req, http.StatusOK)
436+
doc := NewHTMLParser(t, resp.Body)
437+
438+
dataURL, exists := doc.doc.Find(".copy-line-permalink").Attr("data-url")
439+
assert.True(t, exists)
440+
assert.Equal(t, "/user27/repo49/src/commit/aacbdfe9e1c4b47f60abe81849045fa4e96f1d75/test/test.txt", dataURL)
441+
442+
dataURL, exists = doc.doc.Find(".ref-in-new-issue").Attr("data-url-param-body-link")
443+
assert.True(t, exists)
444+
assert.Equal(t, "/user27/repo49/src/commit/aacbdfe9e1c4b47f60abe81849045fa4e96f1d75/test/test.txt", dataURL)
445+
})
446+
}

0 commit comments

Comments
 (0)