This repository has no description
0

Configure Feed

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

core / knotmirror / xrpc / git_get_merge_base.go
1.6 kB 57 lines
1package xrpc 2 3import ( 4 "fmt" 5 "net/http" 6 "os/exec" 7 "strings" 8 9 "github.com/bluesky-social/indigo/atproto/atclient" 10 "github.com/bluesky-social/indigo/atproto/syntax" 11 "tangled.org/core/api/tangled" 12) 13 14func (x *Xrpc) GetMergeBase(w http.ResponseWriter, r *http.Request) { 15 var ( 16 repoQuery = r.URL.Query().Get("repo") 17 base = r.URL.Query().Get("base") 18 head = r.URL.Query().Get("head") 19 ) 20 21 repo, err := syntax.ParseDID(repoQuery) 22 if err != nil { 23 writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: fmt.Sprintf("repo parameter invalid: %s", repoQuery)}) 24 return 25 } 26 27 if base == "" { 28 writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: "missing base parameter"}) 29 return 30 } 31 if head == "" { 32 writeJson(w, http.StatusBadRequest, atclient.ErrorBody{Name: "BadRequest", Message: "missing head parameter"}) 33 return 34 } 35 36 l := x.logger.With("method", "git.getMergeBase", "repo", repo, "base", base, "head", head) 37 l.Debug("request") 38 39 ctx := r.Context() 40 41 repoPath, err := x.makeRepoPath(ctx, repo) 42 if err != nil { 43 writeJson(w, http.StatusNotFound, atclient.ErrorBody{Name: "RepoNotFound", Message: fmt.Sprintf("unknown repository: %q", repo)}) 44 return 45 } 46 47 cmd := exec.Command("git", "-C", repoPath, "merge-base", head, base) 48 out, err := cmd.Output() 49 if err != nil { 50 writeJson(w, http.StatusInternalServerError, atclient.ErrorBody{Name: "InternalError", Message: "failed to compute merge-base"}) 51 return 52 } 53 54 writeJson(w, http.StatusOK, tangled.GitTempGetMergeBase_Output{ 55 Commit: strings.TrimSpace(string(out)), 56 }) 57}