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