this repo has no description
1package models 2 3import ( 4 "fmt" 5 6 "github.com/bluesky-social/indigo/atproto/syntax" 7 "tangled.org/core/api/tangled" 8) 9 10type Profile struct { 11 // ids 12 ID int 13 Did string 14 15 // data 16 Avatar string // CID of the avatar blob 17 Description string 18 IncludeBluesky bool 19 Location string 20 Links [5]string 21 Stats [2]VanityStat 22 PinnedRepos [6]syntax.ATURI 23 Pronouns string 24} 25 26func (p Profile) IsLinksEmpty() bool { 27 for _, l := range p.Links { 28 if l != "" { 29 return false 30 } 31 } 32 return true 33} 34 35func (p Profile) IsStatsEmpty() bool { 36 for _, s := range p.Stats { 37 if s.Kind != "" { 38 return false 39 } 40 } 41 return true 42} 43 44func (p Profile) IsPinnedReposEmpty() bool { 45 for _, r := range p.PinnedRepos { 46 if r != "" { 47 return false 48 } 49 } 50 return true 51} 52 53type VanityStatKind string 54 55const ( 56 VanityStatMergedPRCount VanityStatKind = "merged-pull-request-count" 57 VanityStatClosedPRCount VanityStatKind = "closed-pull-request-count" 58 VanityStatOpenPRCount VanityStatKind = "open-pull-request-count" 59 VanityStatOpenIssueCount VanityStatKind = "open-issue-count" 60 VanityStatClosedIssueCount VanityStatKind = "closed-issue-count" 61 VanityStatRepositoryCount VanityStatKind = "repository-count" 62) 63 64func (v VanityStatKind) String() string { 65 switch v { 66 case VanityStatMergedPRCount: 67 return "Merged PRs" 68 case VanityStatClosedPRCount: 69 return "Closed PRs" 70 case VanityStatOpenPRCount: 71 return "Open PRs" 72 case VanityStatOpenIssueCount: 73 return "Open Issues" 74 case VanityStatClosedIssueCount: 75 return "Closed Issues" 76 case VanityStatRepositoryCount: 77 return "Repositories" 78 } 79 return "" 80} 81 82type VanityStat struct { 83 Kind VanityStatKind 84 Value uint64 85} 86 87func (p *Profile) ProfileAt() syntax.ATURI { 88 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.Did, tangled.ActorProfileNSID, "self")) 89} 90 91type RepoEvent struct { 92 Repo *Repo 93 Source *Repo 94} 95 96type ProfileTimeline struct { 97 ByMonth []ByMonth 98} 99 100func (p *ProfileTimeline) IsEmpty() bool { 101 if p == nil { 102 return true 103 } 104 105 for _, m := range p.ByMonth { 106 if !m.IsEmpty() { 107 return false 108 } 109 } 110 111 return true 112} 113 114type ByMonth struct { 115 Commits int 116 RepoEvents []RepoEvent 117 IssueEvents IssueEvents 118 PullEvents PullEvents 119} 120 121func (b ByMonth) IsEmpty() bool { 122 return len(b.RepoEvents) == 0 && 123 len(b.IssueEvents.Items) == 0 && 124 len(b.PullEvents.Items) == 0 && 125 b.Commits == 0 126} 127 128type IssueEvents struct { 129 Items []*Issue 130} 131 132type IssueEventStats struct { 133 Open int 134 Closed int 135} 136 137func (i IssueEvents) Stats() IssueEventStats { 138 var open, closed int 139 for _, issue := range i.Items { 140 if issue.Open { 141 open += 1 142 } else { 143 closed += 1 144 } 145 } 146 147 return IssueEventStats{ 148 Open: open, 149 Closed: closed, 150 } 151} 152 153type PullEvents struct { 154 Items []*Pull 155} 156 157func (p PullEvents) Stats() PullEventStats { 158 var open, merged, closed int 159 for _, pull := range p.Items { 160 switch pull.State { 161 case PullOpen: 162 open += 1 163 case PullMerged: 164 merged += 1 165 case PullClosed: 166 closed += 1 167 } 168 } 169 170 return PullEventStats{ 171 Open: open, 172 Merged: merged, 173 Closed: closed, 174 } 175} 176 177type PullEventStats struct { 178 Closed int 179 Open int 180 Merged int 181}