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.8 kB 108 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.Route("/fork", func(r chi.Router) { 51 r.Use(middleware.AuthMiddleware(rp.oauth)) 52 r.Get("/", rp.ForkRepo) 53 r.Post("/", rp.ForkRepo) 54 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/sync", func(r chi.Router) { 55 r.Post("/", rp.SyncRepoFork) 56 }) 57 }) 58 59 r.Route("/compare", func(r chi.Router) { 60 r.Get("/", rp.CompareNew) // start an new comparison 61 62 // we have to wildcard here since we want to support GitHub's compare syntax 63 // /compare/{ref1}...{ref2} 64 // for example: 65 // /compare/master...some/feature 66 // /compare/master...example.com:another/feature <- this is a fork 67 r.Get("/*", rp.Compare) 68 }) 69 70 // label panel in issues/pulls/discussions/tasks 71 r.Route("/label", func(r chi.Router) { 72 r.Get("/", rp.LabelPanel) 73 r.Get("/edit", rp.EditLabelPanel) 74 }) 75 76 // settings routes, needs auth 77 r.Group(func(r chi.Router) { 78 r.Use(middleware.AuthMiddleware(rp.oauth)) 79 r.With(mw.RepoPermissionMiddleware("repo:settings")).Route("/settings", func(r chi.Router) { 80 r.Get("/", rp.Settings) 81 r.With(mw.RepoPermissionMiddleware("repo:owner")).Put("/base", rp.EditBaseSettings) 82 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/spindle", rp.EditSpindle) 83 r.With(mw.RepoPermissionMiddleware("repo:owner")).Put("/label", rp.AddLabelDef) 84 r.With(mw.RepoPermissionMiddleware("repo:owner")).Delete("/label", rp.DeleteLabelDef) 85 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/label/subscribe", rp.SubscribeLabel) 86 r.With(mw.RepoPermissionMiddleware("repo:owner")).Post("/label/unsubscribe", rp.UnsubscribeLabel) 87 r.With(mw.RepoPermissionMiddleware("repo:invite")).Put("/collaborator", rp.AddCollaborator) 88 r.With(mw.RepoPermissionMiddleware("repo:delete")).Delete("/delete", rp.DeleteRepo) 89 r.Put("/branches/default", rp.SetDefaultBranch) 90 r.Put("/secrets", rp.Secrets) 91 r.Delete("/secrets", rp.Secrets) 92 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/sites", func(r chi.Router) { 93 r.Put("/", rp.SaveRepoSiteConfig) 94 r.Delete("/", rp.DeleteRepoSiteConfig) 95 }) 96 r.With(mw.RepoPermissionMiddleware("repo:owner")).Route("/hooks", func(r chi.Router) { 97 r.Get("/", rp.Webhooks) 98 r.Post("/", rp.AddWebhook) 99 r.Put("/{id}", rp.UpdateWebhook) 100 r.Delete("/{id}", rp.DeleteWebhook) 101 r.Post("/{id}/toggle", rp.ToggleWebhook) 102 r.Get("/{id}/deliveries", rp.WebhookDeliveries) 103 }) 104 }) 105 }) 106 107 return r 108}