knotserver: return README files from tree pages #581

We have README files displayed on the main page of a repository, but we don't do that on subfolders. The first step in making those available is returning README files when they exist

Signed-off-by: Skyler Grey minion@freshlybakedca.ke

Changed files
+25 -10
knotserver
types
+18 -5
knotserver/handler.go
···
return
}
+
var readmeContent string
+
var readmeFile string
+
for _, readme := range h.c.Repo.Readme {
+
maybeReadmeFile, _ := securejoin.SecureJoin(treePath, readme)
+
content, _ := gr.FileContent(maybeReadmeFile)
+
if len(content) > 0 {
+
readmeContent = string(content)
+
readmeFile = maybeReadmeFile
+
}
+
}
+
resp := types.RepoTreeResponse{
-
Ref: ref,
-
Parent: treePath,
-
Description: getDescription(path),
-
DotDot: filepath.Dir(treePath),
-
Files: files,
+
Ref: ref,
+
Parent: treePath,
+
Description: getDescription(path),
+
DotDot: filepath.Dir(treePath),
+
Files: files,
+
Readme: readmeContent,
+
ReadmeFileName: readmeFile,
}
writeJSON(w, resp)
+7 -5
types/repo.go
···
}
type RepoTreeResponse struct {
-
Ref string `json:"ref,omitempty"`
-
Parent string `json:"parent,omitempty"`
-
Description string `json:"description,omitempty"`
-
DotDot string `json:"dotdot,omitempty"`
-
Files []NiceTree `json:"files,omitempty"`
+
Ref string `json:"ref,omitempty"`
+
Parent string `json:"parent,omitempty"`
+
Description string `json:"description,omitempty"`
+
DotDot string `json:"dotdot,omitempty"`
+
Files []NiceTree `json:"files,omitempty"`
+
Readme string `json:"readme,omitempty"`
+
ReadmeFileName string `json:"readme_file_name,omitempty"`
}
type TagReference struct {