forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 86
/
main.go
54 lines (45 loc) · 1 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
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() {
client, err := factory.NewClientFromEnvironment()
if err != nil {
helpers.Fail(err)
return
}
ctx := context.Background()
args := os.Args
if len(args) < 4 {
fmt.Printf("arguments: owner repository path\n")
return
}
owner := args[1]
repo := args[2]
path := args[3]
ref := "master"
if len(args) > 4 {
ref = args[4]
}
fullRepo := scm.Join(owner, repo)
fmt.Printf("getting content for repository %s/%s and path: %s with ref: %s\n", owner, repo, path, ref)
files, _, err := client.Contents.List(ctx, fullRepo, path, ref)
if err != nil {
helpers.Fail(err)
return
}
fmt.Printf("found %d files\n", len(files))
for _, f := range files {
fmt.Printf("\t%s size: %d type %s\n", f.Path, f.Size, f.Type)
}
}
func createListOptions() scm.ListOptions {
return scm.ListOptions{
Size: 1000,
}
}