forked from checkr/codeflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_sync.go
71 lines (57 loc) · 1.4 KB
/
git_sync.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package git_sync
import (
"fmt"
"log"
"github.com/checkr/codeflow/server/agent"
"github.com/checkr/codeflow/server/plugins"
)
type GitSync struct {
events chan agent.Event
}
func init() {
agent.RegisterPlugin("git_sync", func() agent.Plugin {
return &GitSync{}
})
}
func (x *GitSync) Description() string {
return "Sync Git repositories and create new features"
}
func (x *GitSync) SampleConfig() string {
return ` `
}
func (x *GitSync) Start(e chan agent.Event) error {
x.events = e
log.Println("Started GitSync")
return nil
}
func (x *GitSync) Stop() {
log.Println("Stopping GitSync")
}
func (x *GitSync) Subscribe() []string {
return []string{
"plugins.GitPing",
"plugins.GitSync:update",
}
}
func (x *GitSync) Process(e agent.Event) error {
log.Printf("Process GitSync event: %s", e.Name)
var err error
gitSyncEvent := e.Payload.(plugins.GitSync)
gitSyncEvent.Action = plugins.Status
gitSyncEvent.State = plugins.Fetching
gitSyncEvent.StateMessage = ""
commits, err := plugins.GitCommits(gitSyncEvent.From, gitSyncEvent.Project, gitSyncEvent.Git)
if err != nil {
log.Println(err)
gitSyncEvent.State = plugins.Failed
gitSyncEvent.StateMessage = fmt.Sprintf("%v (Action: %v)", err.Error(), gitSyncEvent.State)
event := e.NewEvent(gitSyncEvent, err)
x.events <- event
return err
}
for i, _ := range commits {
c := commits[i]
x.events <- e.NewEvent(c, nil)
}
return nil
}