A vibe coded tangled fork which supports pijul.
at master 95 lines 2.7 kB view raw
1package xrpc 2 3import ( 4 "net/http" 5 6 "tangled.org/core/knotserver/vcs" 7 xrpcerr "tangled.org/core/xrpc/errors" 8) 9 10// PijulChannelListResponse is the response for listing Pijul channels 11type PijulChannelListResponse struct { 12 Channels []PijulChannel `json:"channels"` 13} 14 15// PijulChannel represents a Pijul channel 16type PijulChannel struct { 17 Name string `json:"name"` 18 IsCurrent bool `json:"is_current,omitempty"` 19} 20 21// RepoChannelList handles the sh.tangled.repo.channelList endpoint 22// Kept for backwards compatibility - delegates to the unified Branches interface. 23func (x *Xrpc) RepoChannelList(w http.ResponseWriter, r *http.Request) { 24 repo := r.URL.Query().Get("repo") 25 repoPath, err := x.parseRepoParam(repo) 26 if err != nil { 27 writeError(w, err.(xrpcerr.XrpcError), http.StatusBadRequest) 28 return 29 } 30 31 rv, err := vcs.PlainOpen(repoPath) 32 if err != nil { 33 writeError(w, xrpcerr.NewXrpcError( 34 xrpcerr.WithTag("RepoNotFound"), 35 xrpcerr.WithMessage("failed to open repository"), 36 ), http.StatusNotFound) 37 return 38 } 39 40 branches, err := rv.Branches(nil) 41 if err != nil { 42 x.Logger.Error("fetching channels", "error", err.Error()) 43 writeError(w, xrpcerr.NewXrpcError( 44 xrpcerr.WithTag("InternalServerError"), 45 xrpcerr.WithMessage("failed to list channels"), 46 ), http.StatusInternalServerError) 47 return 48 } 49 50 channelList := make([]PijulChannel, len(branches)) 51 for i, b := range branches { 52 channelList[i] = PijulChannel{ 53 Name: b.Name, 54 IsCurrent: b.IsDefault, 55 } 56 } 57 58 writeJson(w, PijulChannelListResponse{Channels: channelList}) 59} 60 61// PijulGetDefaultChannelResponse is the response for getting the default channel 62type PijulGetDefaultChannelResponse struct { 63 Channel string `json:"channel"` 64} 65 66// RepoGetDefaultChannel handles the sh.tangled.repo.getDefaultChannel endpoint 67func (x *Xrpc) RepoGetDefaultChannel(w http.ResponseWriter, r *http.Request) { 68 repo := r.URL.Query().Get("repo") 69 repoPath, err := x.parseRepoParam(repo) 70 if err != nil { 71 writeError(w, err.(xrpcerr.XrpcError), http.StatusBadRequest) 72 return 73 } 74 75 rv, err := vcs.PlainOpen(repoPath) 76 if err != nil { 77 writeError(w, xrpcerr.NewXrpcError( 78 xrpcerr.WithTag("RepoNotFound"), 79 xrpcerr.WithMessage("failed to open repository"), 80 ), http.StatusNotFound) 81 return 82 } 83 84 channel, err := rv.DefaultBranch() 85 if err != nil { 86 x.Logger.Error("finding default channel", "error", err.Error()) 87 writeError(w, xrpcerr.NewXrpcError( 88 xrpcerr.WithTag("InternalServerError"), 89 xrpcerr.WithMessage("failed to find default channel"), 90 ), http.StatusInternalServerError) 91 return 92 } 93 94 writeJson(w, PijulGetDefaultChannelResponse{Channel: channel}) 95}