diff --git a/types/repo.go b/types/repo.go --- a/types/repo.go +++ b/types/repo.go @@ -38,16 +38,6 @@ CombinedPatchRaw string `json:"combined_patch_raw,omitempty"` } -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"` - ReadmeFileName string `json:"readme_filename,omitempty"` - Readme string `json:"readme_contents,omitempty"` -} - type TagReference struct { Reference Tag *object.Tag `json:"tag,omitempty"` diff --git a/appview/pages/pages.go b/appview/pages/pages.go --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -987,7 +987,12 @@ HTMLReadme template.HTML EmailToDid map[string]string LastCommitInfo *types.LastCommitInfo - types.RepoTreeResponse + Ref string + Parent string + DotDot string + Files []types.NiceTree + ReadmeFileName string + Readme string } type RepoTreeStats struct { @@ -1092,7 +1097,8 @@ BlobView models.BlobView EmailToDid map[string]string LastCommitInfo *types.LastCommitInfo - *tangled.RepoBlob_Output + Ref string + Path string } func (p *Pages) RepoBlob(w io.Writer, params RepoBlobParams) error { diff --git a/appview/repo/blob.go b/appview/repo/blob.go --- a/appview/repo/blob.go +++ b/appview/repo/blob.go @@ -99,13 +99,14 @@ } rp.pages.RepoBlob(w, pages.RepoBlobParams{ - LoggedInUser: user, - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), - BreadCrumbs: breadcrumbs, - BlobView: blobView, - EmailToDid: emailToDidMap, - LastCommitInfo: lastCommitInfo, - RepoBlob_Output: resp, + LoggedInUser: user, + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), + BreadCrumbs: breadcrumbs, + BlobView: blobView, + EmailToDid: emailToDidMap, + LastCommitInfo: lastCommitInfo, + Ref: resp.Ref, + Path: resp.Path, }) } diff --git a/appview/repo/tree.go b/appview/repo/tree.go --- a/appview/repo/tree.go +++ b/appview/repo/tree.go @@ -43,6 +43,16 @@ rp.pages.Error503(w) return } + + ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) + // redirects tree paths trying to access a blob; in this case the result.Files is unpopulated, + // so we can safely redirect to the "parent" (which is the same file). + if len(xrpcResp.Files) == 0 && xrpcResp.Parent != nil && *xrpcResp.Parent == treePath { + redirectTo := fmt.Sprintf("/%s/blob/%s/%s", ownerSlashRepo, url.PathEscape(ref), *xrpcResp.Parent) + http.Redirect(w, r, redirectTo, http.StatusFound) + return + } + var readmeFile *tangled.GitTempGetTree_TreeEntry // Convert XRPC response to internal types.RepoTreeResponse files := make([]types.NiceTree, len(xrpcResp.Files)) @@ -66,16 +76,12 @@ readmeFile = xrpcFile } } - result := types.RepoTreeResponse{ - Ref: xrpcResp.Ref, - Files: files, - } - if xrpcResp.Parent != nil { - result.Parent = *xrpcResp.Parent - } - if xrpcResp.Dotdot != nil { - result.DotDot = *xrpcResp.Dotdot - } + sortFiles(files) + + var ( + readmeFileName string + readmeFileContent string + ) if readmeFile != nil { bytes, err := tangled.GitTempGetBlob(r.Context(), xrpcc, path.Join(treePath, readmeFile.Name), ref, f.RepoDid) if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil { @@ -83,18 +89,9 @@ rp.pages.Error503(w) return } - result.ReadmeFileName = readmeFile.Name - result.Readme = string(bytes) + readmeFileName = readmeFile.Name + readmeFileContent = string(bytes) } - ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) - // redirects tree paths trying to access a blob; in this case the result.Files is unpopulated, - // so we can safely redirect to the "parent" (which is the same file). - if len(result.Files) == 0 && result.Parent == treePath { - redirectTo := fmt.Sprintf("/%s/blob/%s/%s", ownerSlashRepo, url.PathEscape(ref), result.Parent) - http.Redirect(w, r, redirectTo, http.StatusFound) - return - } - user := rp.oauth.GetMultiAccountUser(r) var breadcrumbs [][]string breadcrumbs = append(breadcrumbs, []string{f.Name, fmt.Sprintf("/%s/tree/%s", ownerSlashRepo, url.PathEscape(ref))}) if treePath != "" { @@ -102,7 +99,6 @@ breadcrumbs = append(breadcrumbs, []string{elem, fmt.Sprintf("%s/%s", breadcrumbs[idx][1], url.PathEscape(elem))}) } } - sortFiles(result.Files) // Get email to DID mapping for commit author var emails []string @@ -130,13 +126,26 @@ } } + user := rp.oauth.GetMultiAccountUser(r) rp.pages.RepoTree(w, pages.RepoTreeParams{ - LoggedInUser: user, - BreadCrumbs: breadcrumbs, - Path: treePath, - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), - EmailToDid: emailToDidMap, - LastCommitInfo: lastCommitInfo, - RepoTreeResponse: result, + LoggedInUser: user, + BreadCrumbs: breadcrumbs, + Path: treePath, + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), + EmailToDid: emailToDidMap, + LastCommitInfo: lastCommitInfo, + Ref: xrpcResp.Ref, + Parent: derefString(xrpcResp.Parent), + DotDot: derefString(xrpcResp.Dotdot), + Files: files, + ReadmeFileName: readmeFileName, + Readme: readmeFileContent, }) +} + +func derefString(s *string) string { + if s == nil { + return "" + } + return *s }