-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_release.go
80 lines (67 loc) · 1.82 KB
/
type_release.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
73
74
75
76
77
78
79
80
package ghid
import (
"fmt"
"strconv"
"github.com/vmihailenco/msgpack/v5"
)
func init() {
RegisterDecodeV1(TypeRelease, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode release id: %w", err)
}
return ReleaseKeyV1{ID: id}, nil
})
RegisterDecodeV2(TypeRelease, func(key msgpack.RawMessage) (KeyV2, error) {
arr, err := decodeV2UintArr(TypeRelease, 0, 2, key)
if err != nil {
return nil, err
}
return ReleaseKeyV2{RepoID: RepoID(arr[0]), ID: arr[1]}, nil
})
}
var (
_ KeyV1 = ReleaseKeyV1{}
_ KeyV2 = ReleaseKeyV2{}
)
// ReleaseKeyV1 is a unique IDv1 key for Release nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#release.
type ReleaseKeyV1 struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r ReleaseKeyV1) Type() string {
return TypeRelease
}
// KeyV1 implements KeyV1.
func (r ReleaseKeyV1) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// WithRepoV2 implements KeyV1NoRepo.
func (r ReleaseKeyV1) WithRepoV2(repo RepoID) KeyV2 {
return ReleaseKeyV2{RepoID: repo, ID: r.ID}
}
// ReleaseKeyV2 is a unique IDv2 key for Release nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#release.
type ReleaseKeyV2 struct {
RepoID RepoID // corresponds to repository.databaseId
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r ReleaseKeyV2) Type() string {
return TypeRelease
}
// GetRepoID implements KeyWithRepo.
func (r ReleaseKeyV2) GetRepoID() RepoID {
return r.RepoID
}
// KeyV1 implements KeyV1.
func (r ReleaseKeyV2) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r ReleaseKeyV2) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.RepoID), uint(r.ID)})
}