This repository has no description
0

Configure Feed

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

core / spindle / xrpc / ci_query_pipelines.go
1.9 kB 77 lines
1package xrpc 2 3import ( 4 "fmt" 5 "net/http" 6 "strconv" 7 8 "tangled.org/core/api/tangled" 9 xrpcerr "tangled.org/core/xrpc/errors" 10) 11 12func (x *Xrpc) HandleCiQueryPipelines(w http.ResponseWriter, r *http.Request) { 13 l := x.Logger 14 fail := func(e xrpcerr.XrpcError, status int) { 15 l.Error("failed", "kind", e.Tag, "error", e.Message) 16 writeError(w, e, status) 17 } 18 19 repo := r.URL.Query().Get("repo") 20 if repo == "" { 21 fail(xrpcerr.GenericError(fmt.Errorf("missing repo parameter")), http.StatusBadRequest) 22 return 23 } 24 25 commits := r.URL.Query()["commits"] 26 cursor := r.URL.Query().Get("cursor") 27 limitStr := r.URL.Query().Get("limit") 28 29 limit := 30 30 if limitStr != "" { 31 if val, err := strconv.Atoi(limitStr); err == nil && val > 0 { 32 limit = val 33 } 34 } 35 36 pipelines, nextCursor, total, err := x.Db.QueryPipelines(r.Context(), repo, commits, cursor, limit) 37 if err != nil { 38 fail(xrpcerr.GenericError(err), http.StatusInternalServerError) 39 return 40 } 41 42 output := tangled.CiQueryPipelines_Output{ 43 Pipelines: pipelines, 44 Total: total, 45 } 46 if nextCursor != "" { 47 output.Cursor = &nextCursor 48 } 49 50 if err := writeJson(w, http.StatusOK, output); err != nil { 51 fail(xrpcerr.GenericError(err), http.StatusInternalServerError) 52 } 53} 54 55func (x *Xrpc) HandleCiGetPipeline(w http.ResponseWriter, r *http.Request) { 56 l := x.Logger 57 fail := func(e xrpcerr.XrpcError, status int) { 58 l.Error("failed", "kind", e.Tag, "error", e.Message) 59 writeError(w, e, status) 60 } 61 62 pipeline := r.URL.Query().Get("pipeline") 63 if pipeline == "" { 64 fail(xrpcerr.GenericError(fmt.Errorf("missing pipeline parameter")), http.StatusBadRequest) 65 return 66 } 67 68 p, err := x.Db.GetPipeline(r.Context(), pipeline) 69 if err != nil { 70 fail(xrpcerr.GenericError(err), http.StatusInternalServerError) 71 return 72 } 73 74 if err := writeJson(w, http.StatusOK, p); err != nil { 75 fail(xrpcerr.GenericError(err), http.StatusInternalServerError) 76 } 77}