-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.go
66 lines (53 loc) · 1.35 KB
/
pipe.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
package cicd
import "time"
type RepoPipe struct {
Action func(*map[string]interface{})
}
func StartPipe(bucle bool, pipe ...*RepoPipe) {
state := map[string]interface{}{}
for {
for _, p := range pipe {
p.Action(&state)
}
if !bucle {
break
}
}
}
func PipeWaitForCommit(repoURL string, branch string, key string, sleepTime int) *RepoPipe {
return &RepoPipe{
Action: func(state *map[string]interface{}) {
commitId, _ := GitLastCommitSSH(repoURL, branch, key)
for {
ncid, ecode := GitLastCommitSSH(repoURL, branch, key)
if ncid != commitId && ecode == 0 {
(*state)["COMMITID"] = ncid
return
}
time.Sleep(time.Duration(sleepTime) * time.Second)
}
},
}
}
func PipeWaitForCommitMulti(repoURL []string, branch []string, key string, sleepTime int) *RepoPipe {
return &RepoPipe{
Action: func(state *map[string]interface{}) {
commitId := make([]string, len(repoURL))
for i := range repoURL {
commitId[i], _ = GitLastCommitSSH(repoURL[i], branch[i], key)
}
for {
for i := range repoURL {
ncid, ecode := GitLastCommitSSH(repoURL[i], branch[i], key)
if ncid != commitId[i] && ecode == 0 {
(*state)["COMMITID"] = ncid
(*state)["REPOURL"] = repoURL[i]
(*state)["BRANCH"] = branch[i]
return
}
time.Sleep(time.Duration(sleepTime) * time.Second)
}
}
},
}
}