Monorepo for Tangled tangled.org
4

Configure Feed

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

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