appview/repo/tags: add link to auto-generated source archive #442

merged
opened by winter.bsky.social targeting master from winter.bsky.social/core: push-vtrouwuvwzqv
Changed files
+35 -2
appview
pages
templates
repo
repo
+3
appview/pages/funcmap.go
··· 236 236 }, 237 237 "cssContentHash": CssContentHash, 238 238 "fileTree": filetree.FileTree, 239 + "pathEscape": func(s string) string { 240 + return url.PathEscape(s) 241 + }, 239 242 "pathUnescape": func(s string) string { 240 243 u, _ := url.PathUnescape(s) 241 244 return u
+9 -2
appview/pages/templates/repo/tags.html
··· 97 97 {{ $isPushAllowed := $root.RepoInfo.Roles.IsPushAllowed }} 98 98 {{ $artifacts := index $root.ArtifactMap $tag.Tag.Hash }} 99 99 100 - {{ if or (gt (len $artifacts) 0) $isPushAllowed }} 101 100 <h2 class="my-4 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">artifacts</h2> 102 101 <div class="flex flex-col rounded border border-gray-200 dark:border-gray-700"> 102 + <div id="artifact-git-source" class="flex items-center justify-between p-2 border-b border-gray-200 dark:border-gray-700"> 103 + <div id="left-side" class="flex items-center gap-2 min-w-0 max-w-[60%]"> 104 + {{ i "archive" "w-4 h-4" }} 105 + <a href="/{{ $root.RepoInfo.FullName }}/archive/{{ pathEscape (print "refs/tags/" $tag.Name) }}" class="no-underline hover:no-underline"> 106 + Source code (.tar.gz) 107 + </a> 108 + </div> 109 + </div> 110 + 103 111 {{ range $artifact := $artifacts }} 104 112 {{ $args := dict "LoggedInUser" $root.LoggedInUser "RepoInfo" $root.RepoInfo "Artifact" $artifact }} 105 113 {{ template "repo/fragments/artifact" $args }} ··· 108 116 {{ block "uploadArtifact" (list $root $tag) }} {{ end }} 109 117 {{ end }} 110 118 </div> 111 - {{ end }} 112 119 {{ end }} 113 120 114 121 {{ define "uploadArtifact" }}
+19
appview/repo/repo.go
··· 81 81 } 82 82 } 83 83 84 + func (rp *Repo) DownloadArchive(w http.ResponseWriter, r *http.Request) { 85 + refParam := chi.URLParam(r, "ref") 86 + f, err := rp.repoResolver.Resolve(r) 87 + if err != nil { 88 + log.Println("failed to get repo and knot", err) 89 + return 90 + } 91 + 92 + var uri string 93 + if rp.config.Core.Dev { 94 + uri = "http" 95 + } else { 96 + uri = "https" 97 + } 98 + url := fmt.Sprintf("%s://%s/%s/%s/archive/%s.tar.gz", uri, f.Knot, f.OwnerDid(), f.RepoName, url.PathEscape(refParam)) 99 + 100 + http.Redirect(w, r, url, http.StatusFound) 101 + } 102 + 84 103 func (rp *Repo) RepoLog(w http.ResponseWriter, r *http.Request) { 85 104 f, err := rp.repoResolver.Resolve(r) 86 105 if err != nil {
+4
appview/repo/router.go
··· 38 38 r.Get("/blob/{ref}/*", rp.RepoBlob) 39 39 r.Get("/raw/{ref}/*", rp.RepoBlobRaw) 40 40 41 + // intentionally doesn't use /* as this isn't 42 + // a file path 43 + r.Get("/archive/{ref}", rp.DownloadArchive) 44 + 41 45 r.Route("/fork", func(r chi.Router) { 42 46 r.Use(middleware.AuthMiddleware(rp.oauth)) 43 47 r.Get("/", rp.ForkRepo)