This repository was archived by the owner on Jan 28, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathpull.go
More file actions
80 lines (76 loc) · 1.93 KB
/
Copy pathpull.go
File metadata and controls
80 lines (76 loc) · 1.93 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
72
73
74
75
76
77
78
79
80
package snub
import (
"fmt"
"strconv"
"github.com/nbd-wtf/go-nostr"
"nostrocket/engine/library"
)
func GetRepoFromEvent(event nostr.Event) (r RepoAnchor, err error) {
name, ok := library.GetFirstTag(event, "name")
if !ok {
return RepoAnchor{}, fmt.Errorf("could not find repo name")
}
d, ok := library.GetFirstTag(event, "d")
if !ok {
return RepoAnchor{}, fmt.Errorf("could not find repo d tag")
}
maintainers := library.GetTagSlice(event, "maintainers")
if len(maintainers) == 0 {
return RepoAnchor{}, fmt.Errorf("could not find repo maintainers")
}
r.Name = name
r.Maintainers = maintainers
r.DTag = d
r.CreatedBy = event.PubKey
r.LastUpdate = event.CreatedAt.Time().Unix()
forknode, ok := library.GetFirstTag(event, "forknode")
if ok && len(forknode) == 40 {
r.ForkedAt = forknode
}
rocket, ok := library.GetFirstTag(event, "rocket")
if ok && len(rocket) == 64 {
r.Rocket = rocket
}
root, ok := library.GetRoot(event)
if ok && len(root) == 64 {
r.UpstreamDTag = root
}
return
}
func GetBranchFromEvent(event nostr.Event) (r Branch, err error) {
name, ok := library.GetFirstTag(event, "name")
if !ok {
return r, fmt.Errorf("could not find branch name")
}
d, ok := library.GetFirstTag(event, "d")
if !ok {
return r, fmt.Errorf("could not find branch d tag")
}
a, ok := library.GetFirstTag(event, "a")
if !ok {
return r, fmt.Errorf("could not find branch d tag")
}
r.ATag = nostr.Tag{"a", a}
r.Name = name
r.DTag = d
r.LastUpdate = event.CreatedAt.Time().Unix()
head, ok := library.GetFirstTag(event, "head")
if ok && len(head) == 40 {
r.Head = head
}
commits := library.GetTagSlice(event, "commits")
for _, commit := range commits {
r.CommitEventIDs[commit] = ""
}
length, ok := library.GetFirstTag(event, "len")
if ok {
parseInt, err := strconv.ParseInt(length, 10, 64)
if err == nil {
r.Length = parseInt
}
if err != nil {
r.Length = int64(len(r.CommitEventIDs))
}
}
return
}