Monorepo for Tangled tangled.org
856
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/repo: show number of forks on repo and link to page of forks #356

open opened by willdot.net targeting master from willdot.net/tangled-fork-2: repo-fork-counts

Signed-off-by: Will did:plc:dadhhalkfcq3gucaq25hjqon

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:dadhhalkfcq3gucaq25hjqon/sh.tangled.repo.pull/3mlgnel3ppx22
+111 -9
Diff #4
+10
appview/db/repos.go
··· 808 808 809 809 return labels, nil 810 810 } 811 + 812 + func GetForkCount(e Execer, sourceDID string) (int, error) { 813 + forks := 0 814 + err := e.QueryRow( 815 + `select count(source) from repos where source = ?`, sourceDID).Scan(&forks) 816 + if err != nil { 817 + return 0, err 818 + } 819 + return forks, nil 820 + }
+14
appview/pages/pages.go
··· 1557 1557 return p.executeRepo("repo/stars", w, params) 1558 1558 } 1559 1559 1560 + type RepoForksParams struct { 1561 + LoggedInUser *oauth.MultiAccountUser 1562 + RepoInfo repoinfo.RepoInfo 1563 + Active string 1564 + Forks []models.Repo 1565 + Page pagination.Page 1566 + TotalCount int 1567 + } 1568 + 1569 + func (p *Pages) RepoForks(w io.Writer, params RepoForksParams) error { 1570 + params.Active = "overview" 1571 + return p.executeRepo("repo/forks", w, params) 1572 + } 1573 + 1560 1574 type PipelinesParams struct { 1561 1575 LoggedInUser *oauth.MultiAccountUser 1562 1576 RepoInfo repoinfo.RepoInfo
+18 -9
appview/pages/templates/layouts/repobase.html
··· 117 117 "IsStarred" .RepoInfo.IsStarred 118 118 "StarCount" .RepoInfo.Stats.StarCount 119 119 "RepoName" .RepoInfo.Name) }} 120 - <a 121 - class="btn text-sm no-underline hover:no-underline flex items-center gap-2 group" 122 - hx-boost="true" 123 - href="/{{ .RepoInfo.FullName }}/fork" 124 - > 125 - {{ i "git-fork" "w-4 h-4" }} 126 - fork 127 - {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 128 - </a> 120 + <div class="flex w-full min-h-[30px] items-stretch overflow-hidden rounded border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm"> 121 + <a 122 + class="btn text-sm no-underline hover:no-underline flex items-center gap-2 group" 123 + hx-boost="true" 124 + href="/{{ .RepoInfo.FullName }}/fork" 125 + > 126 + {{ i "git-fork" "w-4 h-4" }} 127 + fork 128 + {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 129 + </a> 130 + <a 131 + href="/{{ .RepoInfo.FullName }}/forks" 132 + class="flex items-center px-2 text-sm no-underline hover:no-underline border-l border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700" 133 + title="Forked by" 134 + > 135 + {{ .RepoInfo.Stats.ForkCount }} 136 + </a> 137 + </div> 129 138 {{ template "repo/fragments/feedDropdown" . }} 130 139 </div> 131 140 {{ end }}
+35
appview/pages/templates/repo/forks.html
··· 1 + {{ define "title" }}forks ยท {{ .RepoInfo.FullName }}{{ end }} 2 + {{ define "repoContent" }} 3 + <div class="flex flex-col gap-4"> 4 + <h2 class="text-sm uppercase font-bold">Forked by</h2> 5 + <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> 6 + {{ range .Forks }} 7 + {{ $handle := resolve .Did }} 8 + {{ $name := .Name}} 9 + <div class="border border-gray-200 dark:border-gray-700 rounded p-4"> 10 + <div class="flex items-center gap-3"> 11 + {{ template "user/fragments/picLink" (list .Did "size-10") }} 12 + <div class="flex-1 min-w-0"> 13 + <a href="/{{ $handle }}" class="block truncate">{{ $handle }}</a> 14 + <a href="/{{ $handle }}/{{ $name }}" class="block truncate">{{ $name }}</a> 15 + <p class="text-sm text-gray-500 dark:text-gray-400"> 16 + forked {{ .Created | relTimeFmt }} 17 + </p> 18 + </div> 19 + </div> 20 + </div> 21 + {{ end }} 22 + {{ if eq .TotalCount 0 }} 23 + <p class="text-gray-500 dark:text-gray-400 col-span-3">No forks yet.</p> 24 + {{ end }} 25 + </div> 26 + {{ if gt .TotalCount .Page.Limit }} 27 + {{ template "fragments/pagination" (dict 28 + "Page" .Page 29 + "TotalCount" .TotalCount 30 + "BasePath" (printf "/%s/forks" .RepoInfo.FullName) 31 + "QueryParams" (queryParams) 32 + ) }} 33 + {{ end }} 34 + </div> 35 + {{ end }}
+33
appview/repo/repo.go
··· 1297 1297 }) 1298 1298 } 1299 1299 1300 + func (rp *Repo) Forks(w http.ResponseWriter, r *http.Request) { 1301 + l := rp.logger.With("handler", "Forks") 1302 + 1303 + user := rp.oauth.GetMultiAccountUser(r) 1304 + f, err := rp.repoResolver.Resolve(r) 1305 + if err != nil { 1306 + l.Error("failed to resolve source repo", "err", err) 1307 + return 1308 + } 1309 + 1310 + page := pagination.FromContext(r.Context()) 1311 + 1312 + forks, err := db.GetReposPaginated(rp.db, page, orm.FilterEq("source", f.RepoDid)) 1313 + if err != nil { 1314 + l.Error("failed to fetch forks", "err", err, "repoAt", f.RepoAt()) 1315 + return 1316 + } 1317 + 1318 + totalCount, err := db.GetForkCount(rp.db, f.RepoDid) 1319 + if err != nil { 1320 + l.Error("failed to fetch fork count", "err", err, "repoAt", f.RepoAt()) 1321 + return 1322 + } 1323 + 1324 + rp.pages.RepoForks(w, pages.RepoForksParams{ 1325 + LoggedInUser: user, 1326 + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 1327 + Forks: forks, 1328 + Page: page, 1329 + TotalCount: totalCount, 1330 + }) 1331 + } 1332 + 1300 1333 // this is used to rollback changes made to the PDS 1301 1334 // 1302 1335 // it is a no-op if the provided ATURI is empty
+1
appview/repo/router.go
··· 48 48 r.Get("/archive/{ref}", rp.DownloadArchive) 49 49 50 50 r.With(middleware.Paginate).Get("/stars", rp.Stars) 51 + r.With(middleware.Paginate).Get("/forks", rp.Forks) 51 52 52 53 r.Route("/fork", func(r chi.Router) { 53 54 r.Use(middleware.AuthMiddleware(rp.oauth))

History

5 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/repo: show number of forks on repo and link to page of forks
merge conflicts detected
expand
  • appview/db/repos.go:301
  • appview/models/repo.go:97
expand 0 comments
1 commit
expand
appview/repo: show number of forks on repo and link to page of forks
expand 0 comments
1 commit
expand
appview/repo: show number of forks on repo and link to page of forks
expand 0 comments
1 commit
expand
appview/repo: show number of forks on repo and link to page of forks
expand 0 comments
1 commit
expand
appview/repo: show number of forks on repo and link to page of forks
expand 0 comments