-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_issue.go
149 lines (126 loc) · 3.65 KB
/
type_issue.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package ghid
import (
"fmt"
"strconv"
"github.com/vmihailenco/msgpack/v5"
)
func init() {
RegisterDecodeV1(TypeIssue, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode issue id: %w", err)
}
return IssueKeyV1{ID: id}, nil
})
RegisterDecodeV1(TypeIssueComment, func(key []byte) (KeyV1, error) {
id, err := strconv.ParseUint(string(key), 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to decode issue comment id: %w", err)
}
return IssueCommentKeyV1{ID: id}, nil
})
RegisterDecodeV2(TypeIssue, func(key msgpack.RawMessage) (KeyV2, error) {
arr, err := decodeV2UintArr(TypeIssue, 0, 2, key)
if err != nil {
return nil, err
}
return IssueKeyV2{RepoID: RepoID(arr[0]), ID: arr[1]}, nil
})
RegisterDecodeV2(TypeIssueComment, func(key msgpack.RawMessage) (KeyV2, error) {
arr, err := decodeV2UintArr(TypeIssueComment, 0, 2, key)
if err != nil {
return nil, err
}
return IssueCommentKeyV2{RepoID: RepoID(arr[0]), ID: arr[1]}, nil
})
}
var (
_ KeyV1NoRepo = IssueKeyV1{}
_ KeyV2 = IssueKeyV2{}
)
// IssueKeyV1 is a unique IDv1 key for Issue nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#issue.
type IssueKeyV1 struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r IssueKeyV1) Type() string {
return TypeIssue
}
// KeyV1 implements KeyV1.
func (r IssueKeyV1) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// WithRepoV2 implements KeyV1NoRepo.
func (r IssueKeyV1) WithRepoV2(repo RepoID) KeyV2 {
return IssueKeyV2{RepoID: repo, ID: r.ID}
}
// IssueKeyV2 is a unique IDv2 key for Issue nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#issue.
type IssueKeyV2 struct {
RepoID RepoID // corresponds to repository.databaseId
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r IssueKeyV2) Type() string {
return TypeIssue
}
// GetRepoID implements KeyWithRepo.
func (r IssueKeyV2) GetRepoID() RepoID {
return r.RepoID
}
// KeyV1 implements KeyV1.
func (r IssueKeyV2) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r IssueKeyV2) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.RepoID), uint(r.ID)})
}
var (
_ KeyV1NoRepo = IssueCommentKeyV1{}
_ KeyV2 = IssueCommentKeyV2{}
)
// IssueCommentKeyV1 is a unique IDv1 key for IssueComment nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#issuecomment.
type IssueCommentKeyV1 struct {
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r IssueCommentKeyV1) Type() string {
return TypeIssueComment
}
// KeyV1 implements KeyV1.
func (r IssueCommentKeyV1) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// WithRepoV2 implements KeyV1NoRepo.
func (r IssueCommentKeyV1) WithRepoV2(repo RepoID) KeyV2 {
return IssueCommentKeyV2{RepoID: repo, ID: r.ID}
}
// IssueCommentKeyV2 is a unique IDv2 key for IssueComment nodes.
//
// See https://docs.github.com/en/graphql/reference/objects#issuecomment.
type IssueCommentKeyV2 struct {
RepoID RepoID // corresponds to repository.databaseId
ID uint64 // corresponds to databaseId
}
// Type implements Key.
func (r IssueCommentKeyV2) Type() string {
return TypeIssueComment
}
// GetRepoID implements KeyWithRepo.
func (r IssueCommentKeyV2) GetRepoID() RepoID {
return r.RepoID
}
// KeyV1 implements KeyV1.
func (r IssueCommentKeyV2) KeyV1() string {
return strconv.FormatUint(r.ID, 10)
}
// KeyV2 implements KeyV2.
func (r IssueCommentKeyV2) KeyV2() msgpack.RawMessage {
return mustEncodeV2([]any{uint(0), uint(r.RepoID), uint(r.ID)})
}