1package models
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/bluesky-social/indigo/atproto/syntax"
8 securejoin "github.com/cyphar/filepath-securejoin"
9 "tangled.org/core/api/tangled"
10)
11
12type Repo struct {
13 Id int64
14 Did string
15 Name string
16 Knot string
17 Rkey string
18 Created time.Time
19 Description string
20 Spindle string
21 Labels []string
22
23 // optionally, populate this when querying for reverse mappings
24 RepoStats *RepoStats
25
26 // optional
27 Source string
28}
29
30func (r *Repo) AsRecord() tangled.Repo {
31 var source, spindle, description *string
32
33 if r.Source != "" {
34 source = &r.Source
35 }
36
37 if r.Spindle != "" {
38 spindle = &r.Spindle
39 }
40
41 if r.Description != "" {
42 description = &r.Description
43 }
44
45 return tangled.Repo{
46 Knot: r.Knot,
47 Name: r.Name,
48 Description: description,
49 CreatedAt: r.Created.Format(time.RFC3339),
50 Source: source,
51 Spindle: spindle,
52 Labels: r.Labels,
53 }
54}
55
56func (r Repo) RepoAt() syntax.ATURI {
57 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.RepoNSID, r.Rkey))
58}
59
60func (r Repo) DidSlashRepo() string {
61 p, _ := securejoin.SecureJoin(r.Did, r.Name)
62 return p
63}
64
65type RepoStats struct {
66 Language string
67 StarCount int
68 IssueCount IssueCount
69 PullCount PullCount
70}
71
72type IssueCount struct {
73 Open int
74 Closed int
75}
76
77type PullCount struct {
78 Open int
79 Merged int
80 Closed int
81 Deleted int
82}
83
84type RepoLabel struct {
85 Id int64
86 RepoAt syntax.ATURI
87 LabelAt syntax.ATURI
88}