Skip to content

Commit 69b6e52

Browse files
committed
new: git watcher added
Cloudwatcher can now notify all the changes applied to a git repository
1 parent 4b88dca commit 69b6e52

7 files changed

Lines changed: 685 additions & 1 deletion

File tree

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Currently it implements the watchers for the following services:
1212
- Amazon S3
1313
- Google Drive
1414
- Dropbox
15+
- Git
1516
- local filesystem (fsnotify/polling)
1617

1718
It is possible specify the directory to monitor and the polling time (how much often the watcher should check that directory),
@@ -124,4 +125,26 @@ It is not mandatory to call the `SetConfig()` function, and the polling time arg
124125

125126
Setting `disable_fsnotify` parameter on config to "true" the watcher doesn't use fsnotify and use the listing approach instead.
126127

127-
> :warning: not set `disable_fsnotify` to "true" if you plan to use it on a big directory!!! It could increase the I/O on disk
128+
> :warning: not set `disable_fsnotify` to "true" if you plan to use it on a big directory!!! It could increase the I/O on disk
129+
130+
## Git
131+
132+
Git watcher has the following configurations:
133+
134+
| Name | Description
135+
| --- | --- |
136+
| `debug` | if "true" the debug mode is enabled (default "false") |
137+
| `monitor_type` | it can be "file" or "repo" (default is "repo") |
138+
| `auth_type` | authentication type to use: "none", "ssh", "http_token", "http_user_pass" (default "none") |
139+
| `ssh_pkey` | path of the ssh private key (required if auth_type = "ssh") |
140+
| `ssh_pkey_password` | password of the private key if set |
141+
| `http_token` | token to use if auth_type = "http_token" |
142+
| `http_username` | username of github account (auth_type = "http_user_pass") |
143+
| `http_password` | password of github account (auth_type = "http_user_pass") |
144+
| `repo_url` | url of the repository |
145+
| `repo_branch` | branch to watch (if `monitor_type` is "repo" you can leave it empty to watch all the branches) |
146+
| `assemble_events` | if "true" the events could contain one or more commit events (only if `monitor_type` = "repo") |
147+
| `temp_dir` | temporary directory to use for clone the repo: if empty the tmp dir will be used |
148+
149+
If `monitor_type` is set to "repo", the event channel will receive an event with the `Object` field filled with commits or tags.
150+
If `assemble_events` is "true" the `Object` field could contains one or more commits.

examples/git/git_file.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/Matrix86/cloudwatcher"
6+
"time"
7+
)
8+
9+
func main() {
10+
s, err := cloudwatcher.New("git", "", 2*time.Second)
11+
if err != nil {
12+
fmt.Printf("ERROR: %s", err)
13+
return
14+
}
15+
16+
config := map[string]string{
17+
"debug": "true",
18+
"monitor_type": "file",
19+
"repo_url": "git@github.com:Matrix86/cloudwatcher.git",
20+
"repo_branch": "main",
21+
}
22+
23+
err = s.SetConfig(config)
24+
if err != nil {
25+
fmt.Printf("ERROR: %s", err)
26+
return
27+
}
28+
29+
err = s.Start()
30+
defer s.Close()
31+
for {
32+
select {
33+
case v := <-s.GetEvents():
34+
fmt.Printf("EVENT: %s %s\n", v.Key, v.TypeString())
35+
36+
case e := <-s.GetErrors():
37+
fmt.Printf("ERROR: %s\n", e)
38+
}
39+
}
40+
}

examples/git/git_repo.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/Matrix86/cloudwatcher"
6+
"time"
7+
)
8+
9+
func main() {
10+
s, err := cloudwatcher.New("git", "", 2*time.Second)
11+
if err != nil {
12+
fmt.Printf("ERROR: %s", err)
13+
return
14+
}
15+
16+
config := map[string]string{
17+
"debug": "true",
18+
"monitor_type": "repo",
19+
"repo_url": "git@github.com:Matrix86/cloudwatcher.git",
20+
"assemble_events": "true",
21+
}
22+
23+
err = s.SetConfig(config)
24+
if err != nil {
25+
fmt.Printf("ERROR: %s", err)
26+
return
27+
}
28+
29+
err = s.Start()
30+
defer s.Close()
31+
for {
32+
select {
33+
case v := <-s.GetEvents():
34+
if v.Key == "commit" {
35+
fmt.Println("New commits:")
36+
for _, c := range v.Object.(*cloudwatcher.GitObject).Commits {
37+
fmt.Printf("- hash=%s branch=%s : %s\n", c.Hash, c.Branch, c.Message)
38+
}
39+
} else if v.Key == "tag" {
40+
fmt.Println("New tags:")
41+
for _, c := range v.Object.(*cloudwatcher.GitObject).Commits {
42+
fmt.Printf("- %s\n", c.Message)
43+
}
44+
}
45+
46+
case e := <-s.GetErrors():
47+
fmt.Printf("ERROR: %s\n", e)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)