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.
This commit is contained in:
Jacob Kozol 2019-11-13 13:55:48 +01:00 committed by Tom Gundersen
parent 1b46a83522
commit 5ffcb3fe6d

View file

@ -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)