Skip to content

Commit 11cdba1

Browse files
authored
Merge branch 'main' into feature/webhook-payload-optimization
2 parents 6e07c6f + 8125633 commit 11cdba1

Some content is hidden

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

49 files changed

+1460
-1113
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ module.exports = {
484484
'max-nested-callbacks': [0],
485485
'max-params': [0],
486486
'max-statements': [0],
487-
'multiline-comment-style': [2, 'separate-lines'],
487+
'multiline-comment-style': [0],
488488
'new-cap': [0],
489489
'no-alert': [0],
490490
'no-array-constructor': [0], // handled by @typescript-eslint/no-array-constructor

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.19.1
40-
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.19.1
39+
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.20.0
40+
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.20.0
4141

4242
DOCKER_IMAGE ?= gitea/gitea
4343
DOCKER_TAG ?= latest

modules/git/commit_info.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33

44
package git
55

6-
import "path"
7-
86
// CommitInfo describes the first commit with the provided entry
97
type CommitInfo struct {
108
Entry *TreeEntry
119
Commit *Commit
1210
SubmoduleFile *CommitSubmoduleFile
1311
}
1412

15-
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
16-
fullPath := path.Join(treePathDir, entry.Name())
13+
func GetCommitInfoSubmoduleFile(repoLink, fullPath string, commit *Commit, refCommitID ObjectID) (*CommitSubmoduleFile, error) {
1714
submodule, err := commit.GetSubModule(fullPath)
1815
if err != nil {
1916
return nil, err
2017
}
2118
if submodule == nil {
2219
// unable to find submodule from ".gitmodules" file
23-
return NewCommitSubmoduleFile(repoLink, fullPath, "", entry.ID.String()), nil
20+
return NewCommitSubmoduleFile(repoLink, fullPath, "", refCommitID.String()), nil
2421
}
25-
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
22+
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, refCommitID.String()), nil
2623
}

modules/git/commit_info_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
7373

7474
// If the entry is a submodule, add a submodule file for this
7575
if entry.IsSubModule() {
76-
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
76+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
7777
if err != nil {
7878
return nil, nil, err
7979
}

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
6464

6565
// If the entry is a submodule, add a submodule file for this
6666
if entry.IsSubModule() {
67-
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
67+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
6868
if err != nil {
6969
return nil, nil, err
7070
}

modules/git/commit_info_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
125125
t.Run("NonExistingSubmoduleAsNil", func(t *testing.T) {
126126
commit, err := bareRepo1.GetCommit("HEAD")
127127
require.NoError(t, err)
128-
tree, err := commit.GetTreeEntryByPath("file1.txt")
128+
treeEntry, err := commit.GetTreeEntryByPath("file1.txt")
129129
require.NoError(t, err)
130-
cisf, err := getCommitInfoSubmoduleFile("/any/repo-link", tree, commit, "")
130+
cisf, err := GetCommitInfoSubmoduleFile("/any/repo-link", "file1.txt", commit, treeEntry.ID)
131131
require.NoError(t, err)
132132
assert.Equal(t, &CommitSubmoduleFile{
133133
repoLink: "/any/repo-link",

modules/git/commit_submodule_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
4242
return nil
4343
}
4444
if strings.HasPrefix(sf.refURL, "../") {
45-
targetLink := path.Join(sf.repoLink, path.Dir(sf.fullPath), sf.refURL)
45+
targetLink := path.Join(sf.repoLink, sf.refURL)
4646
return &SubmoduleWebLink{RepoWebLink: targetLink, CommitWebLink: targetLink + moreLinkPath}
4747
}
4848
if !sf.parsed {

modules/git/commit_submodule_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestCommitSubmoduleLink(t *testing.T) {
3232
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
3333
assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
3434

35-
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../../user/repo", "aaaa")
35+
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../user/repo", "aaaa")
3636
wl = sf.SubmoduleWebLinkCompare(t.Context(), "1111", "2222")
3737
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
3838
assert.Equal(t, "/subpath/user/repo/compare/1111...2222", wl.CommitWebLink)

modules/git/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14+
15+
"code.gitea.io/gitea/modules/util"
1416
)
1517

1618
// ObjectCache provides thread-safe cache operations.
@@ -106,3 +108,16 @@ func HashFilePathForWebUI(s string) string {
106108
_, _ = h.Write([]byte(s))
107109
return hex.EncodeToString(h.Sum(nil))
108110
}
111+
112+
func SplitCommitTitleBody(commitMessage string, titleRuneLimit int) (title, body string) {
113+
title, body, _ = strings.Cut(commitMessage, "\n")
114+
title, title2 := util.EllipsisTruncateRunes(title, titleRuneLimit)
115+
if title2 != "" {
116+
if body == "" {
117+
body = title2
118+
} else {
119+
body = title2 + "\n" + body
120+
}
121+
}
122+
return title, body
123+
}

modules/git/utils_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ func TestHashFilePathForWebUI(t *testing.T) {
1515
HashFilePathForWebUI("foobar"),
1616
)
1717
}
18+
19+
func TestSplitCommitTitleBody(t *testing.T) {
20+
title, body := SplitCommitTitleBody("啊bcdefg", 4)
21+
assert.Equal(t, "啊…", title)
22+
assert.Equal(t, "…bcdefg", body)
23+
24+
title, body = SplitCommitTitleBody("abcdefg\n1234567", 4)
25+
assert.Equal(t, "a…", title)
26+
assert.Equal(t, "…bcdefg\n1234567", body)
27+
28+
title, body = SplitCommitTitleBody("abcdefg\n1234567", 100)
29+
assert.Equal(t, "abcdefg", title)
30+
assert.Equal(t, "1234567", body)
31+
}

0 commit comments

Comments
 (0)