forked from tangled.org/core
this repo has no description
at master 895 B view raw
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 22 branch, err := gr.FindMainBranch() 23 if err != nil { 24 x.Logger.Error("getting default branch", "error", err.Error()) 25 writeError(w, xrpcerr.NewXrpcError( 26 xrpcerr.WithTag("InvalidRequest"), 27 xrpcerr.WithMessage("failed to get default branch"), 28 ), http.StatusInternalServerError) 29 return 30 } 31 32 response := tangled.RepoGetDefaultBranch_Output{ 33 Name: branch, 34 Hash: "", 35 When: time.UnixMicro(0).Format(time.RFC3339), 36 } 37 38 writeJson(w, response) 39}