From 5ffcb3fe6d107aa74ee8d3f0b12e9b3610a52ecd Mon Sep 17 00:00:00 2001 From: Jacob Kozol Date: Wed, 13 Nov 2019 13:55:48 +0100 Subject: [PATCH] api: add undo blueprint route Add a route to set a blueprint back to its state at a particular change. The route `blueprints/undo/:blueprint/:commit` requires the blueprint name and the commit hash for the change that the blueprint should be reverted too. Also, the commit message for the change created when a blueprint is pushed is now passed from the api to the store's PushBlueprint funtion. --- internal/weldr/api.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/weldr/api.go b/internal/weldr/api.go index df97766f6..f22dd39e4 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -70,6 +70,7 @@ func New(rpmmd rpmmd.RPMMD, repo rpmmd.RepoConfig, logger *log.Logger, store *st api.router.GET("/api/v0/blueprints/changes/*blueprints", api.blueprintsChangesHandler) api.router.POST("/api/v0/blueprints/new", api.blueprintsNewHandler) api.router.POST("/api/v0/blueprints/workspace", api.blueprintsWorkspaceHandler) + api.router.POST("/api/v0/blueprints/undo/:blueprint/:commit", api.blueprintUndoHandler) api.router.DELETE("/api/v0/blueprints/delete/:blueprint", api.blueprintDeleteHandler) api.router.DELETE("/api/v0/blueprints/workspace/:blueprint", api.blueprintDeleteWorkspaceHandler) @@ -877,7 +878,8 @@ func (api *API) blueprintsNewHandler(writer http.ResponseWriter, request *http.R return } - api.store.PushBlueprint(blueprint) + commitMsg := "Recipe " + blueprint.Name + ", version " + blueprint.Version + " saved." + api.store.PushBlueprint(blueprint, commitMsg) statusResponseOK(writer) } @@ -909,6 +911,16 @@ func (api *API) blueprintsWorkspaceHandler(writer http.ResponseWriter, request * statusResponseOK(writer) } +func (api *API) blueprintUndoHandler(writer http.ResponseWriter, request *http.Request, params httprouter.Params) { + name := params.ByName("blueprint") + commit := params.ByName("commit") + bpChange := api.store.GetBlueprintChange(name, commit) + bp := bpChange.Blueprint + commitMsg := name + ".toml reverted to commit " + commit + api.store.PushBlueprint(bp, commitMsg) + statusResponseOK(writer) +} + func (api *API) blueprintDeleteHandler(writer http.ResponseWriter, request *http.Request, params httprouter.Params) { api.store.DeleteBlueprint(params.ByName("blueprint")) statusResponseOK(writer)