···
+
"github.com/bluesky-social/indigo/atproto/syntax"
+
"tangled.org/core/api/tangled"
+
"tangled.org/core/appview/models"
+
// FindReferences resolves refLinks to Issue/PR/IssueComment/PullComment ATURIs.
+
// It will ignore missing refLinks.
+
func FindReferences(e Execer, refLinks []models.ReferenceLink) ([]syntax.ATURI, error) {
+
issueRefs []models.ReferenceLink
+
pullRefs []models.ReferenceLink
+
for _, ref := range refLinks {
+
case models.RefKindIssue:
+
issueRefs = append(issueRefs, ref)
+
case models.RefKindPull:
+
pullRefs = append(pullRefs, ref)
+
issueUris, err := findIssueReferences(e, issueRefs)
+
pullUris, err := findPullReferences(e, pullRefs)
+
return append(issueUris, pullUris...), nil
+
func findIssueReferences(e Execer, refLinks []models.ReferenceLink) ([]syntax.ATURI, error) {
+
if len(refLinks) == 0 {
+
vals := make([]string, len(refLinks))
+
args := make([]any, 0, len(refLinks)*4)
+
for i, ref := range refLinks {
+
vals[i] = "(?, ?, ?, ?)"
+
args = append(args, ref.Handle, ref.Repo, ref.SubjectId, ref.CommentId)
+
`with input(owner_did, name, issue_id, comment_id) as (
+
on r.did = inp.owner_did
+
on i.repo_at = r.at_uri
+
and i.issue_id = inp.issue_id
+
left join issue_comments c
+
on inp.comment_id is not null
+
and c.issue_at = i.at_uri
+
and c.id = inp.comment_id
+
strings.Join(vals, ","),
+
rows, err := e.Query(query, args...)
+
var uris []syntax.ATURI
+
var issueOwner, issueRkey string
+
var commentOwner, commentRkey sql.NullString
+
if err := rows.Scan(&issueOwner, &issueRkey, &commentOwner, &commentRkey); err != nil {
+
if commentOwner.Valid && commentRkey.Valid {
+
uri = syntax.ATURI(fmt.Sprintf(
+
tangled.RepoIssueCommentNSID,
+
uri = syntax.ATURI(fmt.Sprintf(
+
uris = append(uris, uri)
+
func findPullReferences(e Execer, refLinks []models.ReferenceLink) ([]syntax.ATURI, error) {
+
if len(refLinks) == 0 {
+
vals := make([]string, len(refLinks))
+
args := make([]any, 0, len(refLinks)*4)
+
for i, ref := range refLinks {
+
vals[i] = "(?, ?, ?, ?)"
+
args = append(args, ref.Handle, ref.Repo, ref.SubjectId, ref.CommentId)
+
`with input(owner_did, name, pull_id, comment_id) as (
+
on r.did = inp.owner_did
+
on p.repo_at = r.at_uri
+
and p.pull_id = inp.pull_id
+
left join pull_comments c
+
on inp.comment_id is not null
+
and c.repo_at = r.at_uri and c.pull_id = p.pull_id
+
and c.id = inp.comment_id
+
strings.Join(vals, ","),
+
rows, err := e.Query(query, args...)
+
var uris []syntax.ATURI
+
var pullOwner, pullRkey string
+
var commentOwner, commentRkey sql.NullString
+
if err := rows.Scan(&pullOwner, &pullRkey, &commentOwner, &commentRkey); err != nil {
+
if commentOwner.Valid && commentRkey.Valid {
+
uri = syntax.ATURI(fmt.Sprintf(
+
tangled.RepoPullCommentNSID,
+
uri = syntax.ATURI(fmt.Sprintf(
+
uris = append(uris, uri)