Skip to content

Commit 28a38d7

Browse files
author
Aly Sewelam
committed
Resolve linting issues
Modernise string suffix check with CutSuffix Added nilcheck for entry after the org version check attempt
1 parent 83353a8 commit 28a38d7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

routers/web/repo/wiki.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func wikiEntryByName(ctx *context.Context, commit *git.Commit, wikiName wiki_ser
154154
}
155155
if entry == nil {
156156
// If .md file not found, try .org file
157-
if strings.HasSuffix(gitFilename, ".md") {
158-
orgFilename := strings.TrimSuffix(gitFilename, ".md") + ".org"
157+
if base, ok := strings.CutSuffix(gitFilename, ".md"); ok {
158+
orgFilename := base + ".org"
159159
entry, err = findEntryForFile(commit, orgFilename)
160160
if err != nil && !git.IsErrNotExist(err) {
161161
ctx.ServerError("findEntryForFile", err)
@@ -168,10 +168,10 @@ func wikiEntryByName(ctx *context.Context, commit *git.Commit, wikiName wiki_ser
168168
// If still not found, check if the file without extension exists (for raw files)
169169
if entry == nil {
170170
baseFilename := gitFilename
171-
if strings.HasSuffix(baseFilename, ".md") {
172-
baseFilename = strings.TrimSuffix(baseFilename, ".md")
173-
} else if strings.HasSuffix(baseFilename, ".org") {
174-
baseFilename = strings.TrimSuffix(baseFilename, ".org")
171+
if base, ok := strings.CutSuffix(baseFilename, ".md"); ok {
172+
baseFilename = base
173+
} else if base, ok := strings.CutSuffix(baseFilename, ".org"); ok {
174+
baseFilename = base
175175
}
176176
entry, err = findEntryForFile(commit, baseFilename)
177177
if err != nil && !git.IsErrNotExist(err) {
@@ -678,10 +678,12 @@ func WikiRaw(ctx *context.Context) {
678678
ctx.ServerError("findFile", err)
679679
return
680680
}
681-
entry, err = findEntryForFile(commit, providedGitPath)
682-
if err != nil && !git.IsErrNotExist(err) {
683-
ctx.ServerError("findFile", err)
684-
return
681+
if entry == nil {
682+
entry, err = findEntryForFile(commit, providedGitPath)
683+
if err != nil && !git.IsErrNotExist(err) {
684+
ctx.ServerError("findFile", err)
685+
return
686+
}
685687
}
686688
}
687689
}

0 commit comments

Comments
 (0)