-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy patheventid.go
More file actions
71 lines (64 loc) 路 2.71 KB
/
Copy patheventid.go
File metadata and controls
71 lines (64 loc) 路 2.71 KB
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
package devstatscode
import (
"strconv"
"time"
)
// NativeIDBandRule - one generation of GitHub event id sequences: native events created at/after Since get the band
// of their type (Bands) or DefaultBand, see NativeIDBandRules
type NativeIDBandRule struct {
Since time.Time
DefaultBand int64
Bands map[string]int64
}
// NativeIDBandRules - native event id banding rules, newest first: the first rule whose Since <= created_at decides
// the band (see NativeIDBandBase), events older than every rule keep their raw GitHub id (band 0).
// To handle another GitHub sequence reset (or an event type moving to another sequence) PREPEND a rule with a Since a
// few days in the future (every running image must carry the rule before it activates, otherwise old and new binaries
// store the same event under two ids) and with band numbers never used by any other rule (bands must stay < 281), then
// mirror it in rust/devstatscode/src/eventid.rs (the compat tests compare both).
// 2026-09-20 rule: band 1 = the issues/PRs/comments/reviews/stars/forks/releases/... sequence, band 2 = the git
// reference sequence (PushEvent, CreateEvent, DeleteEvent).
var NativeIDBandRules = []NativeIDBandRule{
{
Since: time.Date(2026, 9, 20, 0, 0, 0, 0, time.UTC),
DefaultBand: 1,
Bands: map[string]int64{"PushEvent": 2, "CreateEvent": 2, "DeleteEvent": 2},
},
}
// NativeIDBand - band of a native event given its type and creation time, 0 = raw id
func NativeIDBand(eType string, createdAt time.Time) int64 {
for _, rule := range NativeIDBandRules {
if createdAt.Before(rule.Since) {
continue
}
if band, ok := rule.Bands[eType]; ok {
return band
}
return rule.DefaultBand
}
return 0
}
// NativeEventID - id stored in gha_events.id (and in every *.event_id) for a native GitHub event:
// raw GitHub id + band*NativeIDBandBase; ids outside (0, NativeIDBandBase) are not GitHub sequence ids and are
// returned unchanged
func NativeEventID(rawID int64, eType string, createdAt time.Time) int64 {
if rawID <= 0 || rawID >= NativeIDBandBase {
return rawID
}
return rawID + NativeIDBand(eType, createdAt)*NativeIDBandBase
}
// NativeEventIDString - NativeEventID for the JSON string id, a non-numeric id is returned unchanged
func NativeEventIDString(rawID, eType string, createdAt time.Time) string {
raw, err := strconv.ParseInt(rawID, 10, 64)
if err != nil {
return rawID
}
return strconv.FormatInt(NativeEventID(raw, eType, createdAt), 10)
}
// SplitNativeEventID - (band, raw GitHub id) of a stored native event id, (0, id) for non-native ids
func SplitNativeEventID(id int64) (band, rawID int64) {
if id <= 0 || id >= ArtificialIDBase {
return 0, id
}
return id / NativeIDBandBase, id % NativeIDBandBase
}