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