forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 83
/
main.go
66 lines (56 loc) · 1.33 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
56
57
58
59
60
61
62
63
64
65
66
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) < 7 {
fmt.Printf("arguments: owner repository remotePath localPath branch commitMsg\n")
return
}
owner := args[1]
repo := args[2]
remotePath := args[3]
localPath := args[4]
branch := args[5]
commitMsg := args[6]
data, err := os.ReadFile(localPath) // #nosec
if err != nil {
fmt.Printf("unable to load file from localPath : %v", err)
return
}
fullRepo := scm.Join(owner, repo)
cp := &scm.ContentParams{
Ref: "",
Branch: branch,
Message: commitMsg,
Data: data,
Sha: "",
}
fmt.Printf("creating content for repository %s/%s and remotePath: %s with branch: %s\n", owner, repo, remotePath, branch)
_, err = client.Contents.Create(ctx, fullRepo, remotePath, cp)
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,
}
}