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