Add merge ops (not yet import py api)
This commit is contained in:
parent
a6a7397dce
commit
850c483d5b
13 changed files with 220 additions and 1676 deletions
|
|
@ -6,10 +6,13 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/routers"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/cors"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
|
@ -33,7 +36,52 @@ func (s *Server) Run() error {
|
|||
|
||||
func createHandler() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: []string{"https://*", "http://*"},
|
||||
AllowCredentials: true,
|
||||
ExposedHeaders: []string{"Content-Type"},
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||
}))
|
||||
r.Post("/merge", func(w http.ResponseWriter, r *http.Request) {
|
||||
var targetMap map[string]interface{}
|
||||
err := json.NewDecoder(r.Body).Decode(&targetMap)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
log.Fatalln("Merge request failed: ", err)
|
||||
return
|
||||
}
|
||||
log.Println(targetMap)
|
||||
master_version := targetMap["master"].(string)
|
||||
dev_version := targetMap["dev"].(string)
|
||||
|
||||
// find target file in the cofffeemachineConfig
|
||||
if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + master_version + ".json"); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
log.Fatalln("Merge request failed. Master file not found: ", err)
|
||||
return
|
||||
}
|
||||
if _, err := os.Stat("coffeemachineConfig/coffeethai02_" + dev_version + ".json"); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
log.Fatalln("Merge request failed. Dev file not found: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
repo_path := "coffeemachineConfig/coffeethai02_"
|
||||
master_path := repo_path + master_version + ".json"
|
||||
dev_path := repo_path + dev_version + ".json"
|
||||
|
||||
// output path
|
||||
output_path := ""
|
||||
|
||||
// changelog path
|
||||
changelog_path := ""
|
||||
|
||||
// TODO: Call merge api if found
|
||||
err = exec.Command("python", "merge", master_path, dev_path, output_path, changelog_path).Run()
|
||||
if err != nil {
|
||||
log.Fatalln("Merge request failed. Python merge failed: ", err)
|
||||
}
|
||||
})
|
||||
rr := routers.NewRecipeRouter(data.NewData())
|
||||
rr.Route(r)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue