-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdolly.go
More file actions
51 lines (42 loc) · 1.06 KB
/
Copy pathdolly.go
File metadata and controls
51 lines (42 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os/exec"
"strconv"
"encoding/json"
"time"
"github.com/gorilla/mux"
)
// Config - struct that will get the config file
type Config struct {
DeployEndpoint string `json:"deploy_endpoint"`
Email string `json:"email"`
}
// CreateServer - it set up the web server to liten the hook
func CreateServer(p *int, h *string) {
routes := mux.NewRouter().StrictSlash(true)
routes.HandleFunc("/"+*h, deployhook)
http.ListenAndServe(":"+strconv.Itoa(*p), routes)
log.Println("listening on {*p}")
}
func deployhook(w http.ResponseWriter, r *http.Request) {
gitPullCmd()
}
func gitPullCmd() {
Out, Err := exec.Command("git", "pull", "origin", "master").Output()
if Err != nil {
s := fmt.Sprint(Err) + ": Out - Error on Pull"
writeFile(s+"\n", "error")
} else {
t := time.Now().UTC()
s := string(Out)
writeFile("["+t.Format("2006-01-02 15:04:05")+"] "+s+"\n", "success")
}
}
func writeFile(in string, logName string) {
fout := []byte(in)
ioutil.WriteFile("./"+logName+"-logs.txt", fout, 0644)
}