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
10
server/git_pull_recipe.sh
Normal file
10
server/git_pull_recipe.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# modify this
|
||||
# .sh for linux
|
||||
# .bat for windows
|
||||
|
||||
# pull only 1 file
|
||||
|
||||
git clone --depth 1 --no-checkout --filter=blob:none ssh://ikong@192.168.10.159/1TBHDD/ikong/repo/cofffeemachineConfig
|
||||
cd cofffeemachineConfig
|
||||
git checkout master -- coffeethai02_577.json
|
||||
cd ..
|
||||
|
|
@ -3,3 +3,5 @@ module recipe-manager
|
|||
go 1.21.1
|
||||
|
||||
require github.com/go-chi/chi/v5 v5.0.10
|
||||
|
||||
require github.com/go-chi/cors v1.2.1 // indirect
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
|
||||
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
|
||||
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||
|
|
|
|||
|
|
@ -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