This repository has no description
0

Configure Feed

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

core / knotserver / xrpc / repo_get_default_branch.go
1.0 kB 44 lines
1package xrpc 2 3import ( 4 "net/http" 5 "time" 6 7 "tangled.org/core/api/tangled" 8 "tangled.org/core/knotserver/git" 9 xrpcerr "tangled.org/core/xrpc/errors" 10) 11 12func (x *Xrpc) RepoGetDefaultBranch(w http.ResponseWriter, r *http.Request) { 13 repo := r.URL.Query().Get("repo") 14 repoPath, err := x.parseRepoParam(repo) 15 if err != nil { 16 writeError(w, err.(xrpcerr.XrpcError), http.StatusBadRequest) 17 return 18 } 19 20 gr, err := git.PlainOpen(repoPath) 21 if err != nil { 22 x.Logger.Error("failed to open", "error", err.Error()) 23 writeError(w, xrpcerr.RepoNotFoundError, http.StatusNotFound) 24 return 25 } 26 27 branch, err := gr.FindMainBranch() 28 if err != nil { 29 x.Logger.Error("getting default branch", "error", err.Error()) 30 writeError(w, xrpcerr.NewXrpcError( 31 xrpcerr.WithTag("InvalidRequest"), 32 xrpcerr.WithMessage("failed to get default branch"), 33 ), http.StatusInternalServerError) 34 return 35 } 36 37 response := tangled.RepoGetDefaultBranch_Output{ 38 Name: branch, 39 Hash: "", 40 When: time.UnixMicro(0).Format(time.RFC3339), 41 } 42 43 x.writeJson(w, response) 44}