forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.go
55 lines (49 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
52
53
54
55
package main
import (
"context"
"fmt"
"os"
"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/go-scm/scm/factory"
"github.com/jenkins-x/go-scm/scm/factory/examples/helpers"
)
func main() {
args := os.Args
if len(args) < 2 {
fmt.Println("usage: repo ref")
os.Exit(1)
return
}
repo := args[1]
ref := "master"
if len(args) > 2 {
ref = args[2]
}
client, err := factory.NewClientFromEnvironment()
if err != nil {
helpers.Fail(err)
return
}
fmt.Printf("finding in repo: %s ref: %s\n", repo, ref)
ctx := context.Background()
changes, _, err := client.Git.ListChanges(ctx, repo, ref, scm.ListOptions{
Page: 1,
Size: 100,
})
if err != nil {
helpers.Fail(err)
return
}
fmt.Printf("found %d changes\n", len(changes))
for _, change := range changes {
action := "changed"
if change.Added {
action = "added"
} else if change.Deleted {
action = "deleted"
} else if change.Renamed {
action = "renamed"
}
fmt.Printf("%s on path %s at: %s\n", action, change.Path, change.Sha)
}
}