Signed-off-by: Anirudh Oppiliappan anirudh@tangled.sh
+73
-2
appview/db/issues.go
+73
-2
appview/db/issues.go
···
48
48
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", i.OwnerDid, tangled.RepoIssueNSID, i.Rkey))
49
49
}
50
50
51
+
func IssueFromRecord(did, rkey string, record tangled.RepoIssue) Issue {
52
+
created, err := time.Parse(time.RFC3339, record.CreatedAt)
53
+
if err != nil {
54
+
created = time.Now()
55
+
}
56
+
57
+
body := ""
58
+
if record.Body != nil {
59
+
body = *record.Body
60
+
}
61
+
62
+
return Issue{
63
+
RepoAt: syntax.ATURI(record.Repo),
64
+
OwnerDid: record.Owner,
65
+
Rkey: rkey,
66
+
Created: created,
67
+
Title: record.Title,
68
+
Body: body,
69
+
Open: true, // new issues are open by default
70
+
}
71
+
}
72
+
73
+
func ResolveIssueFromAtUri(e Execer, issueUri syntax.ATURI) (syntax.ATURI, int, error) {
74
+
ownerDid := issueUri.Authority().String()
75
+
issueRkey := issueUri.RecordKey().String()
76
+
77
+
var repoAt string
78
+
var issueId int
79
+
80
+
query := `select repo_at, issue_id from issues where owner_did = ? and rkey = ?`
81
+
err := e.QueryRow(query, ownerDid, issueRkey).Scan(&repoAt, &issueId)
82
+
if err != nil {
83
+
return "", 0, err
84
+
}
85
+
86
+
return syntax.ATURI(repoAt), issueId, nil
87
+
}
88
+
89
+
func IssueCommentFromRecord(e Execer, did, rkey string, record tangled.RepoIssueComment) (Comment, error) {
90
+
created, err := time.Parse(time.RFC3339, record.CreatedAt)
91
+
if err != nil {
92
+
created = time.Now()
93
+
}
94
+
95
+
ownerDid := did
96
+
if record.Owner != nil {
97
+
ownerDid = *record.Owner
98
+
}
99
+
100
+
issueUri, err := syntax.ParseATURI(record.Issue)
101
+
if err != nil {
102
+
return Comment{}, err
103
+
}
104
+
105
+
repoAt, issueId, err := ResolveIssueFromAtUri(e, issueUri)
106
+
if err != nil {
107
+
return Comment{}, err
108
+
}
109
+
110
+
comment := Comment{
111
+
OwnerDid: ownerDid,
112
+
RepoAt: repoAt,
113
+
Rkey: rkey,
114
+
Body: record.Body,
115
+
Issue: issueId,
116
+
Created: &created,
117
+
}
118
+
119
+
return comment, nil
120
+
}
121
+
51
122
func NewIssue(tx *sql.Tx, issue *Issue) error {
52
123
defer tx.Rollback()
53
124
···
145
216
body,
146
217
open,
147
218
comment_count
148
-
from
219
+
from
149
220
numbered_issue
150
-
where
221
+
where
151
222
row_num between ? and ?`,
152
223
repoAt, openValue, page.Offset+1, page.Offset+page.Limit)
153
224
if err != nil {