Skip to content

Commit

Permalink
feat(api): add checkout endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Jul 30, 2019
1 parent 79cb4b8 commit 18980f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func NewServerRoutes(s Server) *http.ServeMux {
fsih := NewFSIHandlers(s.Instance, cfg.API.ReadOnly)
m.Handle("/status/", s.middleware(fsih.StatusHandler))
m.Handle("/init/", s.middleware(fsih.InitHandler))
m.Handle("/checkout/", s.middleware(fsih.CheckoutHandler))

renderh := NewRenderHandlers(node.Repo)
m.Handle("/render/", s.middleware(renderh.RenderHandler))
Expand Down
34 changes: 33 additions & 1 deletion api/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (h *FSIHandlers) statusHandler(w http.ResponseWriter, r *http.Request) {
// InitHandler creates a new FSI-linked dataset
func (h *FSIHandlers) InitHandler(w http.ResponseWriter, r *http.Request) {
if h.ReadOnly {
readOnlyResponse(w, "/fsi/init")
readOnlyResponse(w, "/init")
return
}

Expand Down Expand Up @@ -97,3 +97,35 @@ func (h *FSIHandlers) initHandler(w http.ResponseWriter, r *http.Request) {

util.WriteResponse(w, map[string]string{"ref": name})
}

// CheckoutHandler invokes checkout via an API call
func (h *FSIHandlers) CheckoutHandler(w http.ResponseWriter, r *http.Request) {
if h.ReadOnly {
readOnlyResponse(w, "/checkout")
return
}

switch r.Method {
case "OPTIONS":
util.EmptyOkHandler(w, r)
case "POST":
h.checkoutHandler(w, r)
default:
util.NotFoundHandler(w,r)
}
}

func (h *FSIHandlers) checkoutHandler(w http.ResponseWriter, r *http.Request) {
p := &lib.CheckoutParams{
Dir: r.FormValue("dir"),
Ref: r.FormValue("ref"),
}

var res string
if err := h.Checkout(p, &res); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}

util.WriteResponse(w, p)
}

0 comments on commit 18980f9

Please sign in to comment.