From 902cb5dd23e795e718fe85697992a4360092e8a3 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Mon, 31 Oct 2016 15:37:00 -0700 Subject: [PATCH] mvp --- cmd/hoboken/main.go | 20 +++++++++++++++++--- http.go | 37 +++++++++++++++++++++++++++++++++++++ test/test.sh | 9 +++++++++ test/test.yaml | 2 ++ test/test2.yaml | 2 ++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 http.go create mode 100755 test/test.sh create mode 100644 test/test.yaml create mode 100644 test/test2.yaml diff --git a/cmd/hoboken/main.go b/cmd/hoboken/main.go index f2216aa..f85a3e4 100644 --- a/cmd/hoboken/main.go +++ b/cmd/hoboken/main.go @@ -1,11 +1,25 @@ package main -import "git.barakmich.com/barak/hoboken" +import ( + "flag" + "path/filepath" + + "git.barakmich.com/barak/hoboken" +) + +var ( + path = flag.String("path", "./", "Set working path to watch for new projects") + host = flag.String("host", "0.0.0.0", "Listen host") + port = flag.String("port", "8081", "Listen port") +) func main() { - p, err := hoboken.NewProjects("./") + flag.Parse() + p, err := hoboken.NewProjects(*path) if err != nil { panic(err) } - hoboken.WatchDir("./...", p) + go hoboken.WatchDir(filepath.Join(*path, "/..."), p) + hp := *host + ":" + *port + hoboken.Listen(hp, p) } diff --git a/http.go b/http.go new file mode 100644 index 0000000..bf8b901 --- /dev/null +++ b/http.go @@ -0,0 +1,37 @@ +package hoboken + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func Listen(host string, p *Projects) { + r := gin.Default() + r.GET("/", func(c *gin.Context) { + for _, x := range p.projects { + c.String(http.StatusOK, "%s\n", x.Name) + } + }) + r.GET("/hook", func(c *gin.Context) { + project := c.Query("project") + if project == "" { + c.AbortWithStatus(http.StatusBadRequest) + } + p.RLock() + defer p.RUnlock() + for _, x := range p.projects { + if x.Name == project { + err := x.Exec() + if err != nil { + c.String(http.StatusInternalServerError, "Err, didn't run") + return + } + c.String(http.StatusOK, "Successfully ran") + return + } + } + c.String(http.StatusBadRequest, "No such project") + }) + r.Run(host) +} diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..73fced3 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +cd $1 +mkdir -p src/git.barakmich.com/barak/hoboken +export GOPATH=$1 +git clone https://git.barakmich.com/barak/hoboken.git src/git.barakmich.com/barak/hoboken +go get git.barakmich.com/barak/hoboken +go build git.barakmich.com/barak/hoboken/cmd/hoboken +cp ./hoboken /tmp diff --git a/test/test.yaml b/test/test.yaml new file mode 100644 index 0000000..326d467 --- /dev/null +++ b/test/test.yaml @@ -0,0 +1,2 @@ +name: barakFoo +script: test.sh diff --git a/test/test2.yaml b/test/test2.yaml new file mode 100644 index 0000000..0b0a6f7 --- /dev/null +++ b/test/test2.yaml @@ -0,0 +1,2 @@ +name: Foo3 +script: test.sh