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