-
Notifications
You must be signed in to change notification settings - Fork 2
/
git_refs.go
72 lines (58 loc) · 1.54 KB
/
git_refs.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
67
68
69
70
71
72
package github
import (
"context"
"github.com/google/go-github/v60/github"
"go.autokitteh.dev/autokitteh/sdk/sdkmodule"
"go.autokitteh.dev/autokitteh/sdk/sdktypes"
)
// https://docs.github.com/en/rest/git/refs#create-a-reference
func (i integration) createRef(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error) {
var owner, repo, ref, sha string
err := sdkmodule.UnpackArgs(args, kwargs,
"owner", &owner,
"repo", &repo,
"ref", &ref,
"sha", &sha,
)
if err != nil {
return sdktypes.InvalidValue, err
}
ghRef := github.Reference{
Ref: &ref,
Object: &github.GitObject{
SHA: &sha,
},
}
// Invoke the API method.
gh, err := i.NewClient(ctx, owner)
if err != nil {
return sdktypes.InvalidValue, err
}
c, _, err := gh.Git.CreateRef(ctx, owner, repo, &ghRef)
if err != nil {
return sdktypes.InvalidValue, err
}
return sdktypes.WrapValue(c)
}
// https://docs.github.com/en/rest/git/refs#get-a-reference
func (i integration) getRef(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error) {
var owner, repo, ref string
err := sdkmodule.UnpackArgs(args, kwargs,
"owner", &owner,
"repo", &repo,
"ref", &ref,
)
if err != nil {
return sdktypes.InvalidValue, err
}
// Invoke the API method.
gh, err := i.NewClient(ctx, owner)
if err != nil {
return sdktypes.InvalidValue, err
}
c, _, err := gh.Git.GetRef(ctx, owner, repo, ref)
if err != nil {
return sdktypes.InvalidValue, err
}
return sdktypes.WrapValue(c)
}