-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
59 lines (49 loc) · 1 KB
/
handler.go
File metadata and controls
59 lines (49 loc) · 1 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
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"log"
"net/http"
)
type Config struct {
Listen string
}
type Repo struct {
Folder string
Remote string
Branch string
Before string
After string
Bitbucket bool
}
type Repos []Repo
type Handler struct {
Config Config
Repos map[string]Repos
}
func (h Handler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
var pushInfos PushInfos
if req.Method != "POST" {
res.WriteHeader(405)
res.Write([]byte("method not allowed"))
log.Println("wrong method", req.Method, req.URL)
return
}
err := ReadInfos(req.Body, &pushInfos)
if err != nil {
log.Println("couldn't read body")
res.WriteHeader(400)
res.Write([]byte("couldn't read body"))
}
repoName := pushInfos.Repository.Name
if _, ok := h.Repos[repoName]; ok == false {
log.Println("repo not found", repoName)
res.WriteHeader(404)
res.Write([]byte("not found"))
return
}
for _, repo := range h.Repos[repoName] {
h.PullRepo(repo, pushInfos)
}
res.WriteHeader(200)
res.Write([]byte(""))
}