web frontend for git (tangled's grandpa)
7
fork

Configure Feed

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

routes: multiplex git and web ui

+47 -1
+2
go.mod
··· 18 18 github.com/emirpasic/gods v1.18.1 // indirect 19 19 github.com/go-git/gcfg v1.5.0 // indirect 20 20 github.com/go-git/go-billy/v5 v5.3.1 // indirect 21 + github.com/gofrs/uuid v4.0.0+incompatible // indirect 21 22 github.com/imdario/mergo v0.3.13 // indirect 22 23 github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 23 24 github.com/kevinburke/ssh_config v1.2.0 // indirect 24 25 github.com/pjbgf/sha1cd v0.2.3 // indirect 25 26 github.com/sergi/go-diff v1.2.0 // indirect 26 27 github.com/skeema/knownhosts v1.1.0 // indirect 28 + github.com/sosedoff/gitkit v0.3.0 // indirect 27 29 github.com/xanzy/ssh-agent v0.3.3 // indirect 28 30 golang.org/x/crypto v0.4.0 // indirect 29 31 golang.org/x/mod v0.7.0 // indirect
+5
go.sum
··· 35 35 github.com/go-git/go-git-fixtures/v4 v4.3.1/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo= 36 36 github.com/go-git/go-git/v5 v5.5.1 h1:5vtv2TB5PM/gPM+EvsHJ16hJh4uAkdGcKilcwY7FYwo= 37 37 github.com/go-git/go-git/v5 v5.5.1/go.mod h1:uz5PQ3d0gz7mSgzZhSJToM6ALPaKCdSnl58/Xb5hzr8= 38 + github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= 39 + github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= 38 40 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 39 41 github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 40 42 github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= ··· 66 68 github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 67 69 github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= 68 70 github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag= 71 + github.com/sosedoff/gitkit v0.3.0 h1:TfINVRNUM+GcFa+LGhZ3RcWN86Im1M6i8qs0IsgMy90= 72 + github.com/sosedoff/gitkit v0.3.0/go.mod h1:V3EpGZ0nvCBhXerPsbDeqtyReNb48cwP9KtkUYTKT5I= 69 73 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 70 74 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 71 75 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= ··· 75 79 github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= 76 80 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 77 81 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 82 + golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= 78 83 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 79 84 golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 80 85 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+40 -1
routes/handler.go
··· 1 1 package routes 2 2 3 3 import ( 4 + "log" 4 5 "net/http" 6 + "path/filepath" 7 + "regexp" 5 8 6 9 "github.com/alexedwards/flow" 10 + "github.com/sosedoff/gitkit" 7 11 "icyphox.sh/legit/config" 8 12 ) 9 13 14 + type depsWrapper struct { 15 + actualDeps deps 16 + gitsvc *gitkit.Server 17 + } 18 + 19 + // Checks for gitprotocol-http(5) specific query params; if found, passes 20 + // the request on to the git http service, else render the web frontend. 21 + func (dw *depsWrapper) Multiplex(w http.ResponseWriter, r *http.Request) { 22 + path := flow.Param(r.Context(), "...") 23 + name := flow.Param(r.Context(), "name") 24 + name = filepath.Clean(name) 25 + gitCommand := regexp.MustCompile(`git-(upload|receive)-pack`) 26 + 27 + if path == "info/refs" && gitCommand.MatchString(r.URL.RawQuery) && r.Method == "GET" { 28 + dw.gitsvc.ServeHTTP(w, r) 29 + } else if gitCommand.MatchString(path) && r.Method == "POST" { 30 + dw.gitsvc.ServeHTTP(w, r) 31 + } else if r.Method == "GET" { 32 + log.Println("index:", r.URL.String()) 33 + dw.actualDeps.Index(w, r) 34 + } 35 + } 36 + 10 37 func Handlers(c *config.Config) *flow.Mux { 11 38 mux := flow.New() 12 39 d := deps{c} 13 40 41 + gitsvc := gitkit.New(gitkit.Config{ 42 + Dir: c.Repo.ScanPath, 43 + AutoCreate: false, 44 + }) 45 + if err := gitsvc.Setup(); err != nil { 46 + log.Fatalf("git server: %s", err) 47 + } 48 + 49 + dw := depsWrapper{actualDeps: d, gitsvc: gitsvc} 50 + 14 51 mux.NotFound = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { 15 52 d.Write404(w) 16 53 }) 17 54 18 55 mux.HandleFunc("/", d.Index, "GET") 19 - mux.HandleFunc("/:name", d.RepoIndex, "GET") 56 + mux.HandleFunc("/:name", dw.Multiplex, "GET", "POST") 57 + mux.HandleFunc("/:name/...", dw.Multiplex, "GET", "POST") 20 58 mux.HandleFunc("/:name/tree/:ref/...", d.RepoTree, "GET") 21 59 mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET") 22 60 mux.HandleFunc("/:name/log/:ref", d.Log, "GET") 23 61 mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET") 24 62 mux.HandleFunc("/:name/refs", d.Refs, "GET") 63 + 25 64 return mux 26 65 }