Monorepo for Tangled tangled.org

appview/{repo,pages}: show most recent commit in blob view

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

+83 -5
+7 -5
appview/pages/pages.go
··· 855 855 } 856 856 857 857 type RepoBlobParams struct { 858 - LoggedInUser *oauth.MultiAccountUser 859 - RepoInfo repoinfo.RepoInfo 860 - Active string 861 - BreadCrumbs [][]string 862 - BlobView models.BlobView 858 + LoggedInUser *oauth.MultiAccountUser 859 + RepoInfo repoinfo.RepoInfo 860 + Active string 861 + BreadCrumbs [][]string 862 + BlobView models.BlobView 863 + EmailToDid map[string]string 864 + LastCommitInfo *types.LastCommitInfo 863 865 *tangled.RepoBlob_Output 864 866 } 865 867
+49
appview/pages/templates/repo/blob.html
··· 12 12 13 13 {{ define "repoContent" }} 14 14 {{ $linkstyle := "no-underline hover:underline" }} 15 + 16 + {{ if .LastCommitInfo }} 17 + <div class="pb-3 mb-3 border-b border-gray-200 dark:border-gray-700"> 18 + <div id="commit-message"> 19 + {{ $messageParts := splitN .LastCommitInfo.Message "\n\n" 2 }} 20 + <div class="text-base"> 21 + <a href="/{{ .RepoInfo.FullName }}/commit/{{ .LastCommitInfo.Hash }}" 22 + class="inline no-underline hover:underline dark:text-white"> 23 + {{ index $messageParts 0 }} 24 + </a> 25 + {{ if gt (len $messageParts) 1 }} 26 + <button 27 + class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600" 28 + hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')"> 29 + {{ i "ellipsis" "w-3 h-3" }} 30 + </button> 31 + {{ end }} 32 + </div> 33 + {{ if gt (len $messageParts) 1 }} 34 + <p class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300"> 35 + {{ nl2br (index $messageParts 1) }} 36 + </p> 37 + {{ end }} 38 + </div> 39 + <div class="text-xs mt-2 text-gray-500 dark:text-gray-400 flex items-center flex-wrap"> 40 + {{ if .LastCommit.Author }} 41 + {{ $authorDid := index .EmailToDid .LastCommit.Author.Email }} 42 + <span class="flex items-center gap-1"> 43 + {{ if $authorDid }} 44 + {{ template "user/fragments/picHandleLink" $authorDid }} 45 + {{ else }} 46 + {{ placeholderAvatar "tiny" }} 47 + <a href="mailto:{{ .LastCommit.Author.Email }}" class="no-underline hover:underline">{{ .LastCommit.Author.Name }}</a> 48 + {{ end }} 49 + </span> 50 + <span class="px-1 select-none before:content-['\00B7']"></span> 51 + {{ end }} 52 + {{ template "repo/fragments/time" .LastCommitInfo.When }} 53 + <span class="px-1 select-none before:content-['\00B7']"></span> 54 + <span class="font-mono"> 55 + <a href="/{{ .RepoInfo.FullName }}/commit/{{ .LastCommitInfo.Hash.String }}" 56 + class="no-underline hover:underline text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-900 px-2 py-1 rounded"> 57 + {{ slice .LastCommitInfo.Hash.String 0 8 }} 58 + </a> 59 + </span> 60 + </div> 61 + </div> 62 + {{ end }} 63 + 15 64 <div class="pb-2 mb-3 text-base border-b border-gray-200 dark:border-gray-700"> 16 65 <div class="flex flex-col md:flex-row md:justify-between gap-2"> 17 66 <div id="breadcrumbs" class="overflow-x-auto whitespace-nowrap text-gray-400 dark:text-gray-500">
+27
appview/repo/blob.go
··· 9 9 "path/filepath" 10 10 "slices" 11 11 "strings" 12 + "time" 12 13 13 14 "tangled.org/core/api/tangled" 14 15 "tangled.org/core/appview/config" 16 + "tangled.org/core/appview/db" 15 17 "tangled.org/core/appview/models" 16 18 "tangled.org/core/appview/pages" 17 19 "tangled.org/core/appview/pages/markup" 18 20 "tangled.org/core/appview/reporesolver" 19 21 xrpcclient "tangled.org/core/appview/xrpcclient" 22 + "tangled.org/core/types" 20 23 21 24 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 22 25 "github.com/go-chi/chi/v5" 26 + "github.com/go-git/go-git/v5/plumbing" 23 27 ) 24 28 25 29 // the content can be one of the following: ··· 78 82 79 83 user := rp.oauth.GetMultiAccountUser(r) 80 84 85 + // Get email to DID mapping for commit author 86 + var emails []string 87 + if resp.LastCommit != nil && resp.LastCommit.Author != nil { 88 + emails = append(emails, resp.LastCommit.Author.Email) 89 + } 90 + emailToDidMap, err := db.GetEmailToDid(rp.db, emails, true) 91 + if err != nil { 92 + l.Error("failed to get email to did mapping", "err", err) 93 + emailToDidMap = make(map[string]string) 94 + } 95 + 96 + var lastCommitInfo *types.LastCommitInfo 97 + if resp.LastCommit != nil { 98 + when, _ := time.Parse(time.RFC3339, resp.LastCommit.When) 99 + lastCommitInfo = &types.LastCommitInfo{ 100 + Hash: plumbing.NewHash(resp.LastCommit.Hash), 101 + Message: resp.LastCommit.Message, 102 + When: when, 103 + } 104 + } 105 + 81 106 rp.pages.RepoBlob(w, pages.RepoBlobParams{ 82 107 LoggedInUser: user, 83 108 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 84 109 BreadCrumbs: breadcrumbs, 85 110 BlobView: blobView, 111 + EmailToDid: emailToDidMap, 112 + LastCommitInfo: lastCommitInfo, 86 113 RepoBlob_Output: resp, 87 114 }) 88 115 }