-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
51 lines (44 loc) · 1.01 KB
/
main.go
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"
"os"
"os/signal"
"syscall"
R "github.com/qjw/doc-server/router"
"github.com/qjw/kelly"
"gopkg.in/src-d/go-git.v4"
)
func main() {
c := make(chan os.Signal, 10)
signal.Notify(c, syscall.SIGUSR2)
config := R.InitConfig()
var r *git.Repository = nil
var err error = nil
if len(config.GitOrigin) > 0 {
R.RemoveContents(config.LocalDir)
r, err = git.PlainClone(config.LocalDir, false, &git.CloneOptions{
URL: config.GitOrigin,
Progress: os.Stdout,
})
} else {
r, err = git.PlainOpen(config.LocalDir)
}
R.CheckIfError(err)
w, err := r.Worktree()
R.CheckIfError(err)
go func(w *git.Worktree) {
for {
//阻塞直至有信号传入
<-c
fmt.Println("new pull request")
err := w.Pull(&git.PullOptions{RemoteName: "origin"})
if err != nil && err != git.NoErrAlreadyUpToDate {
R.CheckIfError(err)
}
fmt.Println("pull request end")
}
}(w)
router := kelly.New()
R.Init(r, router, config)
router.Run(fmt.Sprintf("0.0.0.0:%d", config.Port))
}