This commit is contained in:
yystopf 2022-08-08 14:13:45 +08:00
parent db945157cd
commit 6eefa22e78
1 changed files with 2 additions and 10 deletions

View File

@ -761,20 +761,16 @@ func GetReadmeContents(ctx *context.APIContext) {
// treePath := ctx.Params("*")
ref := ctx.QueryTrim("ref")
var readmePath string
readmePath := "README.md"
filesListInterface, _ := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref)
filesList, ok := filesListInterface.([]*api.ContentsResponse)
if ok {
for _, file := range filesList {
if strings.ToLower(file.Name) == "readme.md" {
readmePath = file.Name
}
if readmePath != "" {
break
}
}
} else {
readmePath = "README.md"
}
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, readmePath, ref); err != nil {
@ -831,20 +827,16 @@ func GetReadmeContentsByPath(ctx *context.APIContext) {
treePath := ctx.Params("*")
ref := ctx.QueryTrim("ref")
var readmePath string
readmePath := "README.md"
filesListInterface, _ := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref)
filesList, ok := filesListInterface.([]*api.ContentsResponse)
if ok {
for _, file := range filesList {
if strings.ToLower(file.Name) == "readme.md" {
readmePath = file.Name
}
if readmePath != "" {
break
}
}
} else {
readmePath = "README.md"
}
newTreePath := treePath + "/" + readmePath
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, newTreePath, ref); err != nil {