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