This repository has no description
0

Configure Feed

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

core / appview / repo / router.go
3.9 kB 111 lines
1package repo 2 3import ( 4 "net/http" 5 6 "github.com/go-chi/chi/v5" 7 "tangled.org/core/appview/middleware" 8) 9 10func (rp *Repo) Router(mw *middleware.Middleware) http.Handler { 11 r := chi.NewRouter() 12 r.Get("/", rp.Index) 13 r.Get("/opengraph", rp.Opengraph) 14 r.Get("/feed.atom", rp.AtomFeed) 15 r.Get("/commits/{ref}", rp.Log) 16 r.Route("/tree/{ref}", func(r chi.Router) { 17 r.Get("/", rp.Index) 18 r.Get("/*", rp.Tree) 19 }) 20 r.Get("/commit/{ref}.diff", rp.CommitRawDiff) 21 r.Get("/commit/{ref}.patch", rp.CommitRawPatch) 22 r.Get("/commit/{ref}", rp.Commit) 23 r.Get("/branches", rp.Branches) 24 r.Delete("/branches", rp.DeleteBranch) 25 r.Route("/tags", func(r chi.Router) { 26 r.Get("/", rp.Tags) 27 r.Route("/{tag}", func(r chi.Router) { 28 r.Get("/", rp.Tag) 29 r.Get("/download/{file}", rp.DownloadArtifact) 30 31 // require repo:push to upload or delete artifacts 32 // 33 // additionally: only the uploader can truly delete an artifact 34 // (record+blob will live on their pds) 35 r.Group(func(r chi.Router) { 36 r.Use(middleware.AuthMiddleware(rp.oauth)) 37 r.Use(mw.RepoPermissionMiddleware("repo:push")) 38 r.Post("/upload", rp.AttachArtifact) 39 r.Delete("/{file}", rp.DeleteArtifact) 40 }) 41 }) 42 }) 43 r.Get("/blob/{ref}/*", rp.Blob) 44 r.Get("/raw/{ref}/*", rp.RepoBlobRaw) 45 46 // intentionally doesn't use /* as this isn't 47 // a file path 48 r.Get("/archive/{ref}", rp.DownloadArchive) 49 50 r.With(middleware.Paginate).Get("/stars", rp.Stars) 51 52 r.Route("/fork", func(r chi.Router) { 53 r.Use(middleware.AuthMiddleware(rp.oauth)) 54 r.Get("/", rp.ForkRepo) 55 r.Post("/", rp.ForkRepo) 56 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/sync", func(r chi.Router) { 57 r.Post("/", rp.SyncRepoFork) 58 }) 59 }) 60 61 r.Route("/compare", func(r chi.Router) { 62 r.Get("/", rp.CompareNew) // start an new comparison 63 64 // we have to wildcard here since we want to support GitHub's compare syntax 65 // /compare/{ref1}...{ref2} 66 // for example: 67 // /compare/master...some/feature 68 // /compare/master...example.com:another/feature <- this is a fork 69 r.Get("/*", rp.Compare) 70 }) 71 72 // label panel in issues/pulls/discussions/tasks 73 r.Route("/label", func(r chi.Router) { 74 r.Get("/", rp.LabelPanel) 75 r.Get("/edit", rp.EditLabelPanel) 76 }) 77 78 // settings routes, needs auth 79 r.Group(func(r chi.Router) { 80 r.Use(middleware.AuthMiddleware(rp.oauth)) 81 r.With(mw.RepoPermissionMiddleware("repo:settings")).Route("/settings", func(r chi.Router) { 82 r.Get("/", rp.Settings) 83 r.With(mw.RepoPermissionMiddleware("repo:owner")).Put("/base", rp.EditBaseSettings) 84 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/spindle", rp.EditSpindle) 85 r.With(mw.RepoPermissionMiddleware("repo:owner")).Put("/label", rp.AddLabelDef) 86 r.With(mw.RepoPermissionMiddleware("repo:owner")).Delete("/label", rp.DeleteLabelDef) 87 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/label/subscribe", rp.SubscribeLabel) 88 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/label/unsubscribe", rp.UnsubscribeLabel) 89 r.With(mw.RepoPermissionMiddleware("repo:invite")).Put("/collaborator", rp.AddCollaborator) 90 r.With(mw.RepoPermissionMiddleware("repo:delete")).Delete("/delete", rp.DeleteRepo) 91 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/rename", rp.RenameRepo) 92 r.Put("/branches/default", rp.SetDefaultBranch) 93 r.Put("/secrets", rp.Secrets) 94 r.Delete("/secrets", rp.Secrets) 95 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/sites", func(r chi.Router) { 96 r.Put("/", rp.SaveRepoSiteConfig) 97 r.Delete("/", rp.DeleteRepoSiteConfig) 98 }) 99 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/hooks", func(r chi.Router) { 100 r.Get("/", rp.Webhooks) 101 r.Post("/", rp.AddWebhook) 102 r.Put("/{id}", rp.UpdateWebhook) 103 r.Delete("/{id}", rp.DeleteWebhook) 104 r.Post("/{id}/toggle", rp.ToggleWebhook) 105 r.Get("/{id}/deliveries", rp.WebhookDeliveries) 106 }) 107 }) 108 }) 109 110 return r 111}