this repo has no description
1package repoinfo 2 3import ( 4 "fmt" 5 "path" 6 "slices" 7 "strings" 8 9 "github.com/bluesky-social/indigo/atproto/syntax" 10 "tangled.sh/tangled.sh/core/appview/db" 11 "tangled.sh/tangled.sh/core/appview/state/userutil" 12) 13 14func (r RepoInfo) OwnerWithAt() string { 15 if r.OwnerHandle != "" { 16 return fmt.Sprintf("@%s", r.OwnerHandle) 17 } else { 18 return r.OwnerDid 19 } 20} 21 22func (r RepoInfo) FullName() string { 23 return path.Join(r.OwnerWithAt(), r.Name) 24} 25 26func (r RepoInfo) OwnerWithoutAt() string { 27 if strings.HasPrefix(r.OwnerWithAt(), "@") { 28 return strings.TrimPrefix(r.OwnerWithAt(), "@") 29 } else { 30 return userutil.FlattenDid(r.OwnerDid) 31 } 32} 33 34func (r RepoInfo) FullNameWithoutAt() string { 35 return path.Join(r.OwnerWithoutAt(), r.Name) 36} 37 38func (r RepoInfo) GetTabs() [][]string { 39 tabs := [][]string{ 40 {"overview", "/", "square-chart-gantt"}, 41 {"issues", "/issues", "circle-dot"}, 42 {"pulls", "/pulls", "git-pull-request"}, 43 {"pipelines", "/pipelines", "layers-2"}, 44 } 45 46 if r.Roles.SettingsAllowed() { 47 tabs = append(tabs, []string{"settings", "/settings", "cog"}) 48 } 49 50 return tabs 51} 52 53type RepoInfo struct { 54 Name string 55 OwnerDid string 56 OwnerHandle string 57 Description string 58 Knot string 59 RepoAt syntax.ATURI 60 IsStarred bool 61 Stats db.RepoStats 62 Roles RolesInRepo 63 Source *db.Repo 64 SourceHandle string 65 Ref string 66 DisableFork bool 67 CurrentDir string 68} 69 70// each tab on a repo could have some metadata: 71// 72// issues -> number of open issues etc. 73// settings -> a warning icon to setup branch protection? idk 74// 75// we gather these bits of info here, because go templates 76// are difficult to program in 77func (r RepoInfo) TabMetadata() map[string]any { 78 meta := make(map[string]any) 79 80 if r.Stats.PullCount.Open > 0 { 81 meta["pulls"] = r.Stats.PullCount.Open 82 } 83 84 if r.Stats.IssueCount.Open > 0 { 85 meta["issues"] = r.Stats.IssueCount.Open 86 } 87 88 // more stuff? 89 90 return meta 91} 92 93type RolesInRepo struct { 94 Roles []string 95} 96 97func (r RolesInRepo) SettingsAllowed() bool { 98 return slices.Contains(r.Roles, "repo:settings") 99} 100 101func (r RolesInRepo) CollaboratorInviteAllowed() bool { 102 return slices.Contains(r.Roles, "repo:invite") 103} 104 105func (r RolesInRepo) RepoDeleteAllowed() bool { 106 return slices.Contains(r.Roles, "repo:delete") 107} 108 109func (r RolesInRepo) IsOwner() bool { 110 return slices.Contains(r.Roles, "repo:owner") 111} 112 113func (r RolesInRepo) IsCollaborator() bool { 114 return slices.Contains(r.Roles, "repo:collaborator") 115} 116 117func (r RolesInRepo) IsPushAllowed() bool { 118 return slices.Contains(r.Roles, "repo:push") 119}