forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 84
/
main.go
52 lines (43 loc) · 978 Bytes
/
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
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)
content, _, err := client.Contents.Find(ctx, fullRepo, path, ref)
if err != nil {
helpers.Fail(err)
return
}
fmt.Printf("result path %s\n", content.Path)
fmt.Printf("%s\n", string(content.Data))
}
func createListOptions() scm.ListOptions {
return scm.ListOptions{
Size: 1000,
}
}