Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

appview/pages: render last commit info in tree views

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 0c73203f 88e3b3b7

verified
+52 -17
+9 -7
appview/pages/pages.go
··· 764 764 } 765 765 766 766 type RepoTreeParams struct { 767 - LoggedInUser *oauth.MultiAccountUser 768 - RepoInfo repoinfo.RepoInfo 769 - Active string 770 - BreadCrumbs [][]string 771 - TreePath string 772 - Raw bool 773 - HTMLReadme template.HTML 767 + LoggedInUser *oauth.MultiAccountUser 768 + RepoInfo repoinfo.RepoInfo 769 + Active string 770 + BreadCrumbs [][]string 771 + TreePath string 772 + Raw bool 773 + HTMLReadme template.HTML 774 + EmailToDid map[string]string 775 + LastCommitInfo *types.LastCommitInfo 774 776 types.RepoTreeResponse 775 777 } 776 778
+4
appview/pages/templates/repo/tree.html
··· 52 52 </div> 53 53 </div> 54 54 55 + {{ if .LastCommitInfo }} 56 + {{ template "repo/fragments/lastCommitPanel" $ }} 57 + {{ end }} 58 + 55 59 {{ range .Files }} 56 60 <div class="grid grid-cols-12 gap-4 items-center py-1"> 57 61 <div class="col-span-8 md:col-span-4">
+5
appview/repo/blob.go
··· 101 101 Message: resp.LastCommit.Message, 102 102 When: when, 103 103 } 104 + if resp.LastCommit.Author != nil { 105 + lastCommitInfo.Author.Name = resp.LastCommit.Author.Name 106 + lastCommitInfo.Author.Email = resp.LastCommit.Author.Email 107 + lastCommitInfo.Author.When, _ = time.Parse(time.RFC3339, resp.LastCommit.Author.When) 108 + } 104 109 } 105 110 106 111 rp.pages.RepoBlob(w, pages.RepoBlobParams{
+29
appview/repo/tree.go
··· 8 8 "time" 9 9 10 10 "tangled.org/core/api/tangled" 11 + "tangled.org/core/appview/db" 11 12 "tangled.org/core/appview/pages" 12 13 "tangled.org/core/appview/reporesolver" 13 14 xrpcclient "tangled.org/core/appview/xrpcclient" ··· 99 98 } 100 99 sortFiles(result.Files) 101 100 101 + // Get email to DID mapping for commit author 102 + var emails []string 103 + if xrpcResp.LastCommit != nil && xrpcResp.LastCommit.Author != nil { 104 + emails = append(emails, xrpcResp.LastCommit.Author.Email) 105 + } 106 + emailToDidMap, err := db.GetEmailToDid(rp.db, emails, true) 107 + if err != nil { 108 + l.Error("failed to get email to did mapping", "err", err) 109 + emailToDidMap = make(map[string]string) 110 + } 111 + 112 + var lastCommitInfo *types.LastCommitInfo 113 + if xrpcResp.LastCommit != nil { 114 + when, _ := time.Parse(time.RFC3339, xrpcResp.LastCommit.When) 115 + lastCommitInfo = &types.LastCommitInfo{ 116 + Hash: plumbing.NewHash(xrpcResp.LastCommit.Hash), 117 + Message: xrpcResp.LastCommit.Message, 118 + When: when, 119 + } 120 + if xrpcResp.LastCommit.Author != nil { 121 + lastCommitInfo.Author.Name = xrpcResp.LastCommit.Author.Name 122 + lastCommitInfo.Author.Email = xrpcResp.LastCommit.Author.Email 123 + lastCommitInfo.Author.When, _ = time.Parse(time.RFC3339, xrpcResp.LastCommit.Author.When) 124 + } 125 + } 126 + 102 127 rp.pages.RepoTree(w, pages.RepoTreeParams{ 103 128 LoggedInUser: user, 104 129 BreadCrumbs: breadcrumbs, 105 130 TreePath: treePath, 106 131 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 132 + EmailToDid: emailToDidMap, 133 + LastCommitInfo: lastCommitInfo, 107 134 RepoTreeResponse: result, 108 135 }) 109 136 }
-10
types/repo.go
··· 106 106 Branch string `json:"branch,omitempty"` 107 107 } 108 108 109 - type RepoBlobResponse struct { 110 - Contents string `json:"contents,omitempty"` 111 - Ref string `json:"ref,omitempty"` 112 - Path string `json:"path,omitempty"` 113 - IsBinary bool `json:"is_binary,omitempty"` 114 - 115 - Lines int `json:"lines,omitempty"` 116 - SizeHint uint64 `json:"size_hint,omitempty"` 117 - } 118 - 119 109 type ForkStatus int 120 110 121 111 const (
+5
types/tree.go
··· 105 105 Hash plumbing.Hash 106 106 Message string 107 107 When time.Time 108 + Author struct { 109 + Email string 110 + Name string 111 + When time.Time 112 + } 108 113 }