this repo has no description
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 Knot string 58 Spindle string 59 RepoAt syntax.ATURI 60 IsStarred bool 61 Stats models.RepoStats 62 Roles RolesInRepo 63 Source *models.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 meta["pulls"] = r.Stats.PullCount.Open 81 meta["issues"] = r.Stats.IssueCount.Open 82 83 // more stuff? 84 85 return meta 86} 87 88type RolesInRepo struct { 89 Roles []string 90} 91 92func (r RolesInRepo) SettingsAllowed() bool { 93 return slices.Contains(r.Roles, "repo:settings") 94} 95 96func (r RolesInRepo) CollaboratorInviteAllowed() bool { 97 return slices.Contains(r.Roles, "repo:invite") 98} 99 100func (r RolesInRepo) RepoDeleteAllowed() bool { 101 return slices.Contains(r.Roles, "repo:delete") 102} 103 104func (r RolesInRepo) IsOwner() bool { 105 return slices.Contains(r.Roles, "repo:owner") 106} 107 108func (r RolesInRepo) IsCollaborator() bool { 109 return slices.Contains(r.Roles, "repo:collaborator") 110} 111 112func (r RolesInRepo) IsPushAllowed() bool { 113 return slices.Contains(r.Roles, "repo:push") 114}