Skip to content

Commit a3d1f26

Browse files
committed
fix RefURL
1 parent 8d63859 commit a3d1f26

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

modules/git/commit_submodule_file.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ func NewCommitSubModuleFile(refURL, refID string) *CommitSubModuleFile {
3131
}
3232
}
3333

34-
func getRefURL(refURL, urlPrefix, repoFullName, sshDomain string) string {
34+
func getRefURL(refURL, repoFullName string) string {
3535
if refURL == "" {
3636
return ""
3737
}
3838

39+
// FIXME: use a more generic way to handle the domain and subpath
40+
urlPrefix := setting.AppURL
41+
sshDomain := setting.SSH.Domain
42+
3943
refURI := strings.TrimSuffix(refURL, ".git")
4044

4145
prefixURL, _ := url.Parse(urlPrefix)
@@ -102,9 +106,8 @@ func getRefURL(refURL, urlPrefix, repoFullName, sshDomain string) string {
102106
}
103107

104108
// RefURL guesses and returns reference URL.
105-
// FIXME: template passes AppURL as urlPrefix, it needs to figure out the correct approach (no hard-coded AppURL anymore)
106109
func (sf *CommitSubModuleFile) RefURL(repoFullName string) string {
107-
return getRefURL(sf.refURL, setting.AppURL, repoFullName, setting.SSH.Domain)
110+
return getRefURL(sf.refURL, repoFullName)
108111
}
109112

110113
// RefID returns reference ID.

modules/git/commit_submodule_file_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package git
66
import (
77
"testing"
88

9+
"code.gitea.io/gitea/modules/setting"
10+
"code.gitea.io/gitea/modules/test"
11+
912
"github.com/stretchr/testify/assert"
1013
)
1114

@@ -37,6 +40,10 @@ func TestCommitSubModuleFileGetRefURL(t *testing.T) {
3740
}
3841

3942
for _, kase := range kases {
40-
assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath, kase.SSHDomain))
43+
t.Run(kase.refURL, func(t *testing.T) {
44+
defer test.MockVariableValue(&setting.AppURL, kase.prefixURL)()
45+
defer test.MockVariableValue(&setting.SSH.Domain, kase.SSHDomain)()
46+
assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.parentPath))
47+
})
4148
}
4249
}

0 commit comments

Comments
 (0)