Skip to content

Commit d14ed18

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Fix session gob (go-gitea#35128) Replace `setup-python` with `setup-uv` (go-gitea#35116) Don't use full-file highlight when there is a git diff textconv (go-gitea#35114) Fix submodule parsing when the gitmodules is missing (go-gitea#35109) Align `issue-title-buttons` with `list-header` (go-gitea#35018)
2 parents 3ddb542 + f201dde commit d14ed18

File tree

23 files changed

+190
-101
lines changed

23 files changed

+190
-101
lines changed

.github/workflows/pull-compliance.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ jobs:
3232
runs-on: ubuntu-latest
3333
steps:
3434
- uses: actions/checkout@v4
35-
- uses: actions/setup-python@v5
36-
with:
37-
python-version: "3.12"
35+
- uses: astral-sh/setup-uv@v6
36+
- run: uv python install 3.12
3837
- uses: actions/setup-node@v4
3938
with:
4039
node-version: 24
4140
cache: npm
4241
cache-dependency-path: package-lock.json
43-
- run: pip install uv
4442
- run: make deps-py
4543
- run: make deps-frontend
4644
- run: make lint-templates
@@ -51,10 +49,8 @@ jobs:
5149
runs-on: ubuntu-latest
5250
steps:
5351
- uses: actions/checkout@v4
54-
- uses: actions/setup-python@v5
55-
with:
56-
python-version: "3.12"
57-
- run: pip install uv
52+
- uses: astral-sh/setup-uv@v6
53+
- run: uv python install 3.12
5854
- run: make deps-py
5955
- run: make lint-yaml
6056

modules/git/attribute/attribute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
GitlabLanguage = "gitlab-language"
2121
Lockable = "lockable"
2222
Filter = "filter"
23+
Diff = "diff"
2324
)
2425

2526
var LinguistAttributes = []string{

modules/git/commit_info.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ type CommitInfo struct {
1515
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
1616
fullPath := path.Join(treePathDir, entry.Name())
1717
submodule, err := commit.GetSubModule(fullPath)
18-
if submodule == nil || err != nil {
18+
if err != nil {
1919
return nil, err
2020
}
21+
if submodule == nil {
22+
// unable to find submodule from ".gitmodules" file
23+
return NewCommitSubmoduleFile(repoLink, fullPath, "", entry.ID.String()), nil
24+
}
2125
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
2226
}

modules/git/commit_info_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
129129
require.NoError(t, err)
130130
cisf, err := getCommitInfoSubmoduleFile("/any/repo-link", tree, commit, "")
131131
require.NoError(t, err)
132-
assert.Nil(t, cisf)
132+
assert.Equal(t, &CommitSubmoduleFile{
133+
repoLink: "/any/repo-link",
134+
fullPath: "file1.txt",
135+
refURL: "",
136+
refID: "e2129701f1a4d54dc44f03c93bca0a2aec7c5449",
137+
}, cisf)
138+
// since there is no refURL, it means that the submodule info doesn't exist, so it won't have a web link
139+
assert.Nil(t, cisf.SubmoduleWebLinkTree(t.Context()))
133140
})
134141
}
135142

modules/git/commit_submodule_file.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSub
2929
return &CommitSubmoduleFile{repoLink: repoLink, fullPath: fullPath, refURL: refURL, refID: refID}
3030
}
3131

32+
// RefID returns the commit ID of the submodule, it returns empty string for nil receiver
3233
func (sf *CommitSubmoduleFile) RefID() string {
34+
if sf == nil {
35+
return ""
36+
}
3337
return sf.refID
3438
}
3539

3640
func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreLinkPath string) *SubmoduleWebLink {
37-
if sf == nil {
41+
if sf == nil || sf.refURL == "" {
3842
return nil
3943
}
4044
if strings.HasPrefix(sf.refURL, "../") {
@@ -53,14 +57,13 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
5357
}
5458

5559
// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
60+
// It returns nil if the submodule does not have a valid URL or is nil
5661
func (sf *CommitSubmoduleFile) SubmoduleWebLinkTree(ctx context.Context, optCommitID ...string) *SubmoduleWebLink {
57-
if sf == nil {
58-
return nil
59-
}
60-
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+util.OptionalArg(optCommitID, sf.refID))
62+
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+util.OptionalArg(optCommitID, sf.RefID()))
6163
}
6264

6365
// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
66+
// It returns nil if the submodule does not have a valid URL or is nil
6467
func (sf *CommitSubmoduleFile) SubmoduleWebLinkCompare(ctx context.Context, commitID1, commitID2 string) *SubmoduleWebLink {
6568
return sf.getWebLinkInTargetRepo(ctx, "/compare/"+commitID1+"..."+commitID2)
6669
}

modules/git/commit_submodule_file_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
func TestCommitSubmoduleLink(t *testing.T) {
1313
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkTree(t.Context()))
1414
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkCompare(t.Context(), "", ""))
15+
assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkTree(t.Context()))
16+
assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkCompare(t.Context(), "", ""))
1517

1618
t.Run("GitHubRepo", func(t *testing.T) {
1719
sf := NewCommitSubmoduleFile("/any/repo-link", "full-path", "[email protected]:user/repo.git", "aaaa")

modules/session/mem.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package session
5+
6+
import (
7+
"bytes"
8+
"encoding/gob"
9+
"net/http"
10+
11+
"gitea.com/go-chi/session"
12+
)
13+
14+
type mockMemRawStore struct {
15+
s *session.MemStore
16+
}
17+
18+
var _ session.RawStore = (*mockMemRawStore)(nil)
19+
20+
func (m *mockMemRawStore) Set(k, v any) error {
21+
// We need to use gob to encode the value, to make it have the same behavior as other stores and catch abuses.
22+
// Because gob needs to "Register" the type before it can encode it, and it's unable to decode a struct to "any" so use a map to help to decode the value.
23+
var buf bytes.Buffer
24+
if err := gob.NewEncoder(&buf).Encode(map[string]any{"v": v}); err != nil {
25+
return err
26+
}
27+
return m.s.Set(k, buf.Bytes())
28+
}
29+
30+
func (m *mockMemRawStore) Get(k any) (ret any) {
31+
v, ok := m.s.Get(k).([]byte)
32+
if !ok {
33+
return nil
34+
}
35+
var w map[string]any
36+
_ = gob.NewDecoder(bytes.NewBuffer(v)).Decode(&w)
37+
return w["v"]
38+
}
39+
40+
func (m *mockMemRawStore) Delete(k any) error {
41+
return m.s.Delete(k)
42+
}
43+
44+
func (m *mockMemRawStore) ID() string {
45+
return m.s.ID()
46+
}
47+
48+
func (m *mockMemRawStore) Release() error {
49+
return m.s.Release()
50+
}
51+
52+
func (m *mockMemRawStore) Flush() error {
53+
return m.s.Flush()
54+
}
55+
56+
type mockMemStore struct {
57+
*mockMemRawStore
58+
}
59+
60+
var _ Store = (*mockMemStore)(nil)
61+
62+
func (m mockMemStore) Destroy(writer http.ResponseWriter, request *http.Request) error {
63+
return nil
64+
}
65+
66+
func NewMockMemStore(sid string) Store {
67+
return &mockMemStore{&mockMemRawStore{session.NewMemStore(sid)}}
68+
}

modules/session/mock.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

modules/session/store.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ import (
1111
"gitea.com/go-chi/session"
1212
)
1313

14-
// Store represents a session store
14+
type RawStore = session.RawStore
15+
1516
type Store interface {
16-
Get(any) any
17-
Set(any, any) error
18-
Delete(any) error
19-
ID() string
20-
Release() error
21-
Flush() error
17+
RawStore
2218
Destroy(http.ResponseWriter, *http.Request) error
2319
}
2420

21+
type mockStoreContextKeyStruct struct{}
22+
23+
var MockStoreContextKey = mockStoreContextKeyStruct{}
24+
2525
// RegenerateSession regenerates the underlying session and returns the new store
2626
func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error) {
2727
for _, f := range BeforeRegenerateSession {
2828
f(resp, req)
2929
}
3030
if setting.IsInTesting {
31-
if store, ok := req.Context().Value(MockStoreContextKey).(*MockStore); ok {
32-
return store, nil
31+
if store := req.Context().Value(MockStoreContextKey); store != nil {
32+
return store.(Store), nil
3333
}
3434
}
3535
return session.RegenerateSession(resp, req)
3636
}
3737

3838
func GetContextSession(req *http.Request) Store {
3939
if setting.IsInTesting {
40-
if store, ok := req.Context().Value(MockStoreContextKey).(*MockStore); ok {
41-
return store
40+
if store := req.Context().Value(MockStoreContextKey); store != nil {
41+
return store.(Store)
4242
}
4343
}
4444
return session.GetSession(req)

modules/session/virtual.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type VirtualSessionProvider struct {
2222
provider session.Provider
2323
}
2424

25-
// Init initializes the cookie session provider with given root path.
26-
func (o *VirtualSessionProvider) Init(gclifetime int64, config string) error {
25+
// Init initializes the cookie session provider with the given config.
26+
func (o *VirtualSessionProvider) Init(gcLifetime int64, config string) error {
2727
var opts session.Options
2828
if err := json.Unmarshal([]byte(config), &opts); err != nil {
2929
return err
@@ -52,7 +52,7 @@ func (o *VirtualSessionProvider) Init(gclifetime int64, config string) error {
5252
default:
5353
return fmt.Errorf("VirtualSessionProvider: Unknown Provider: %s", opts.Provider)
5454
}
55-
return o.provider.Init(gclifetime, opts.ProviderConfig)
55+
return o.provider.Init(gcLifetime, opts.ProviderConfig)
5656
}
5757

5858
// Read returns raw session store by session ID.

0 commit comments

Comments
 (0)