0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-21 15:20:35 +02:00

Include defaultWikiFormat in WebPathToGitPath

Updated all calls of function to include the new signature
The new signature calls for the repo setting for wiki formats
This commit is contained in:
Aly Sewelam 2025-11-27 18:16:41 +02:00
parent 914926f6d7
commit 4778511570
6 changed files with 21 additions and 14 deletions

View File

@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
@ -509,7 +510,8 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) string {
// wikiContentsByName returns the contents of a wiki page, along with a boolean
// indicating whether the page exists. Writes to ctx if an error occurs.
func wikiContentsByName(ctx *context.APIContext, commit *git.Commit, wikiName wiki_service.WebPath, isSidebarOrFooter bool) (string, string) {
gitFilename := wiki_service.WebPathToGitPath(wikiName)
repoDefaultWikiFormat := ctx.Repo.Repository.DefaultWikiFormat
gitFilename := wiki_service.WebPathToGitPath(wikiName, repoDefaultWikiFormat)
entry, err := findEntryForFile(commit, gitFilename)
if err != nil {
if git.IsErrNotExist(err) {

View File

@ -146,7 +146,8 @@ func wikiContentsByEntry(ctx *context.Context, entry *git.TreeEntry) []byte {
// The last return value indicates whether the file should be returned as a raw file
func wikiEntryByName(ctx *context.Context, commit *git.Commit, wikiName wiki_service.WebPath) (*git.TreeEntry, string, bool, bool) {
isRaw := false
gitFilename := wiki_service.WebPathToGitPath(wikiName)
repoDefaultWikiFormat := ctx.Repo.Repository.DefaultWikiFormat
gitFilename := wiki_service.WebPathToGitPath(wikiName, repoDefaultWikiFormat)
entry, err := findEntryForFile(commit, gitFilename)
if err != nil && !git.IsErrNotExist(err) {
ctx.ServerError("findEntryForFile", err)
@ -719,7 +720,8 @@ func WikiRaw(ctx *context.Context) {
}
providedWebPath := wiki_service.WebPathFromRequest(ctx.PathParamRaw("*"))
providedGitPath := wiki_service.WebPathToGitPath(providedWebPath)
repoDefaultWikiFormat := ctx.Repo.Repository.DefaultWikiFormat
providedGitPath := wiki_service.WebPathToGitPath(providedWebPath, repoDefaultWikiFormat)
var entry *git.TreeEntry
if commit != nil {
// Try to find a file with that name

View File

@ -37,7 +37,7 @@ func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName wiki_service.
entries, err := commit.ListEntries()
assert.NoError(t, err)
for _, entry := range entries {
if entry.Name() == wiki_service.WebPathToGitPath(wikiName) {
if entry.Name() == wiki_service.WebPathToGitPath(wikiName, repo.DefaultWikiFormat) {
return entry
}
}

View File

@ -58,7 +58,7 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath, defaultWikiFormat string) (bool, string, error) {
unescapedMd := string(wikiPath) + ".md"
unescapedOrg := string(wikiPath) + ".org"
gitPath := WebPathToGitPath(wikiPath)
gitPath := WebPathToGitPath(wikiPath, defaultWikiFormat)
// Build list of files to look for based on defaultWikiFormat
var filesToCheck []string

View File

@ -94,7 +94,7 @@ func WebPathSegments(s WebPath) []string {
return a
}
func WebPathToGitPath(s WebPath) string {
func WebPathToGitPath(s WebPath, repoDefaultWikiFormat string) string {
str := string(s)
// Accept only .md or .org directly
if strings.HasSuffix(str, ".md") || strings.HasSuffix(str, ".org") {
@ -102,8 +102,11 @@ func WebPathToGitPath(s WebPath) string {
return util.PathJoinRelX(ret)
}
// Get default wiki format from global setting
defaultWikiFormat := setting.Repository.DefaultWikiFormat
// Prioritize repository's DefaultWikiFormat, fallback to global setting if empty
defaultWikiFormat := repoDefaultWikiFormat
if defaultWikiFormat == "" {
defaultWikiFormat = setting.Repository.DefaultWikiFormat
}
a := strings.Split(string(s), "/")
for i := range a {

View File

@ -81,7 +81,7 @@ func TestWebPathToGitPath(t *testing.T) {
{"2000-01-02-meeting.md", "2000-01-02+meeting"},
{"2000-01-02 meeting.-.md", "2000-01-02%20meeting.-"},
} {
assert.Equal(t, test.Expected, WebPathToGitPath(test.WikiName))
assert.Equal(t, test.Expected, WebPathToGitPath(test.WikiName, "markdown"))
}
}
@ -129,11 +129,11 @@ func TestUserWebGitPathConsistency(t *testing.T) {
continue
}
webPath := UserTitleToWebPath("", userTitle)
gitPath := WebPathToGitPath(webPath)
gitPath := WebPathToGitPath(webPath, "markdown")
webPath1, _ := GitPathToWebPath(gitPath)
_, userTitle1 := WebPathToUserTitle(webPath1)
gitPath1 := WebPathToGitPath(webPath1)
gitPath1 := WebPathToGitPath(webPath1, "markdown")
assert.Equal(t, userTitle, userTitle1, "UserTitle for userTitle: %q", userTitle)
assert.Equal(t, webPath, webPath1, "WebPath for userTitle: %q", userTitle)
@ -173,7 +173,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
assert.NoError(t, err)
gitPath := WebPathToGitPath(webPath)
gitPath := WebPathToGitPath(webPath, repo.DefaultWikiFormat)
entry, err := masterTree.GetTreeEntryByPath(gitPath)
assert.NoError(t, err)
assert.Equal(t, gitPath, entry.Name(), "%s not added correctly", userTitle)
@ -218,7 +218,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
assert.NoError(t, err)
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
assert.NoError(t, err)
gitPath := WebPathToGitPath(webPath)
gitPath := WebPathToGitPath(webPath, repo.DefaultWikiFormat)
entry, err := masterTree.GetTreeEntryByPath(gitPath)
assert.NoError(t, err)
assert.Equal(t, gitPath, entry.Name(), "%s not edited correctly", newWikiName)
@ -244,7 +244,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
defer gitRepo.Close()
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
assert.NoError(t, err)
gitPath := WebPathToGitPath("Home")
gitPath := WebPathToGitPath("Home", repo.DefaultWikiFormat)
_, err = masterTree.GetTreeEntryByPath(gitPath)
assert.Error(t, err)
}