mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-19 10:41:01 +02:00
simplify
This commit is contained in:
parent
7e4db07081
commit
38fa21b366
@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
giturl "code.gitea.io/gitea/modules/git/url"
|
giturl "code.gitea.io/gitea/modules/git/url"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommitSubmoduleFile represents a file with submodule type.
|
// CommitSubmoduleFile represents a file with submodule type.
|
||||||
@ -28,6 +29,10 @@ func NewCommitSubmoduleFile(repoLink, fullPath, refURL, refID string) *CommitSub
|
|||||||
return &CommitSubmoduleFile{repoLink: repoLink, fullPath: fullPath, refURL: refURL, refID: refID}
|
return &CommitSubmoduleFile{repoLink: repoLink, fullPath: fullPath, refURL: refURL, refID: refID}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sf *CommitSubmoduleFile) RefID() string {
|
||||||
|
return sf.refID
|
||||||
|
}
|
||||||
|
|
||||||
func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreLinkPath string) *SubmoduleWebLink {
|
func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreLinkPath string) *SubmoduleWebLink {
|
||||||
if sf == nil {
|
if sf == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -47,17 +52,12 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
|
|||||||
return &SubmoduleWebLink{RepoWebLink: sf.parsedTargetLink, CommitWebLink: sf.parsedTargetLink + moreLinkPath}
|
return &SubmoduleWebLink{RepoWebLink: sf.parsedTargetLink, CommitWebLink: sf.parsedTargetLink + moreLinkPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefID returns the commit ref id of the submodule file, it also works on "nil" receiver
|
|
||||||
func (sf *CommitSubmoduleFile) RefID() string {
|
|
||||||
if sf == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return sf.refID
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
|
// SubmoduleWebLinkTree tries to make the submodule's tree link in its own repo, it also works on "nil" receiver
|
||||||
func (sf *CommitSubmoduleFile) SubmoduleWebLinkTree(ctx context.Context, refCommitID string) *SubmoduleWebLink {
|
func (sf *CommitSubmoduleFile) SubmoduleWebLinkTree(ctx context.Context, optCommitID ...string) *SubmoduleWebLink {
|
||||||
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+refCommitID)
|
if sf == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return sf.getWebLinkInTargetRepo(ctx, "/tree/"+util.OptionalArg(optCommitID, sf.refID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
|
// SubmoduleWebLinkCompare tries to make the submodule's compare link in its own repo, it also works on "nil" receiver
|
||||||
|
@ -10,12 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCommitSubmoduleLink(t *testing.T) {
|
func TestCommitSubmoduleLink(t *testing.T) {
|
||||||
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkTree(t.Context(), ""))
|
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkTree(t.Context()))
|
||||||
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkCompare(t.Context(), "", ""))
|
assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkCompare(t.Context(), "", ""))
|
||||||
|
|
||||||
t.Run("GitHubRepo", func(t *testing.T) {
|
t.Run("GitHubRepo", func(t *testing.T) {
|
||||||
sf := NewCommitSubmoduleFile("/any/repo-link", "full-path", "git@github.com:user/repo.git", "aaaa")
|
sf := NewCommitSubmoduleFile("/any/repo-link", "full-path", "git@github.com:user/repo.git", "aaaa")
|
||||||
wl := sf.SubmoduleWebLinkTree(t.Context(), sf.RefID())
|
wl := sf.SubmoduleWebLinkTree(t.Context())
|
||||||
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
|
assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ func TestCommitSubmoduleLink(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("RelativePath", func(t *testing.T) {
|
t.Run("RelativePath", func(t *testing.T) {
|
||||||
sf := NewCommitSubmoduleFile("/subpath/any/repo-home-link", "full-path", "../../user/repo", "aaaa")
|
sf := NewCommitSubmoduleFile("/subpath/any/repo-home-link", "full-path", "../../user/repo", "aaaa")
|
||||||
wl := sf.SubmoduleWebLinkTree(t.Context(), sf.RefID())
|
wl := sf.SubmoduleWebLinkTree(t.Context())
|
||||||
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
|
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
|
||||||
assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
|
assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func (si *SubmoduleDiffInfo) CompareRefIDLinkHTML(ctx context.Context) template.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (si *SubmoduleDiffInfo) SubmoduleRepoLinkHTML(ctx context.Context) template.HTML {
|
func (si *SubmoduleDiffInfo) SubmoduleRepoLinkHTML(ctx context.Context) template.HTML {
|
||||||
webLink := si.SubmoduleFile.SubmoduleWebLinkTree(ctx, si.SubmoduleFile.RefID())
|
webLink := si.SubmoduleFile.SubmoduleWebLinkTree(ctx)
|
||||||
if webLink == nil {
|
if webLink == nil {
|
||||||
return htmlutil.HTMLFormat("%s", si.SubmoduleName)
|
return htmlutil.HTMLFormat("%s", si.SubmoduleName)
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ func newTreeViewNodeFromEntry(ctx context.Context, repoLink string, renderedIcon
|
|||||||
log.Error("GetSubModule: %v", err)
|
log.Error("GetSubModule: %v", err)
|
||||||
} else if subModule != nil {
|
} else if subModule != nil {
|
||||||
submoduleFile := git.NewCommitSubmoduleFile(repoLink, node.FullPath, subModule.URL, entry.ID.String())
|
submoduleFile := git.NewCommitSubmoduleFile(repoLink, node.FullPath, subModule.URL, entry.ID.String())
|
||||||
webLink := submoduleFile.SubmoduleWebLinkTree(ctx, submoduleFile.RefID())
|
webLink := submoduleFile.SubmoduleWebLinkTree(ctx)
|
||||||
node.SubmoduleURL = webLink.CommitWebLink
|
node.SubmoduleURL = webLink.CommitWebLink
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<div class="repo-file-cell name muted-links {{if not $commit}}notready{{end}}">
|
<div class="repo-file-cell name muted-links {{if not $commit}}notready{{end}}">
|
||||||
{{index $.FileIcons $entry.Name}}
|
{{index $.FileIcons $entry.Name}}
|
||||||
{{if $entry.IsSubModule}}
|
{{if $entry.IsSubModule}}
|
||||||
{{$submoduleLink := $submoduleFile.SubmoduleWebLinkTree ctx $submoduleFile.RefID}}
|
{{$submoduleLink := $submoduleFile.SubmoduleWebLinkTree ctx}}
|
||||||
{{if $submoduleLink}}
|
{{if $submoduleLink}}
|
||||||
<a class="entry-name" href="{{$submoduleLink.RepoWebLink}}" title="{{$entry.Name}}">{{$entry.Name}}</a>
|
<a class="entry-name" href="{{$submoduleLink.RepoWebLink}}" title="{{$entry.Name}}">{{$entry.Name}}</a>
|
||||||
@ <a class="text primary" href="{{$submoduleLink.CommitWebLink}}">{{ShortSha $submoduleFile.RefID}}</a>
|
@ <a class="text primary" href="{{$submoduleLink.CommitWebLink}}">{{ShortSha $submoduleFile.RefID}}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user