mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-10 10:44:06 +09:00
Fix various bugs (#35177)
* Fix #35144 * Fix #35117 * Fix https://github.com/go-gitea/gitea/issues/35054#issuecomment-3131793977 * Fix #35136
This commit is contained in:
@ -42,7 +42,7 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(sf.refURL, "../") {
|
||||
targetLink := path.Join(sf.repoLink, path.Dir(sf.fullPath), sf.refURL)
|
||||
targetLink := path.Join(sf.repoLink, sf.refURL)
|
||||
return &SubmoduleWebLink{RepoWebLink: targetLink, CommitWebLink: targetLink + moreLinkPath}
|
||||
}
|
||||
if !sf.parsed {
|
||||
|
@ -32,7 +32,7 @@ func TestCommitSubmoduleLink(t *testing.T) {
|
||||
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
|
||||
assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
|
||||
|
||||
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../../user/repo", "aaaa")
|
||||
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../user/repo", "aaaa")
|
||||
wl = sf.SubmoduleWebLinkCompare(t.Context(), "1111", "2222")
|
||||
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
|
||||
assert.Equal(t, "/subpath/user/repo/compare/1111...2222", wl.CommitWebLink)
|
||||
|
@ -11,6 +11,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// ObjectCache provides thread-safe cache operations.
|
||||
@ -106,3 +108,16 @@ func HashFilePathForWebUI(s string) string {
|
||||
_, _ = h.Write([]byte(s))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func SplitCommitTitleBody(commitMessage string, titleRuneLimit int) (title, body string) {
|
||||
title, body, _ = strings.Cut(commitMessage, "\n")
|
||||
title, title2 := util.EllipsisTruncateRunes(title, titleRuneLimit)
|
||||
if title2 != "" {
|
||||
if body == "" {
|
||||
body = title2
|
||||
} else {
|
||||
body = title2 + "\n" + body
|
||||
}
|
||||
}
|
||||
return title, body
|
||||
}
|
||||
|
@ -15,3 +15,17 @@ func TestHashFilePathForWebUI(t *testing.T) {
|
||||
HashFilePathForWebUI("foobar"),
|
||||
)
|
||||
}
|
||||
|
||||
func TestSplitCommitTitleBody(t *testing.T) {
|
||||
title, body := SplitCommitTitleBody("啊bcdefg", 4)
|
||||
assert.Equal(t, "啊…", title)
|
||||
assert.Equal(t, "…bcdefg", body)
|
||||
|
||||
title, body = SplitCommitTitleBody("abcdefg\n1234567", 4)
|
||||
assert.Equal(t, "a…", title)
|
||||
assert.Equal(t, "…bcdefg\n1234567", body)
|
||||
|
||||
title, body = SplitCommitTitleBody("abcdefg\n1234567", 100)
|
||||
assert.Equal(t, "abcdefg", title)
|
||||
assert.Equal(t, "1234567", body)
|
||||
}
|
||||
|
Reference in New Issue
Block a user