this repo has no description
1package repo 2 3import ( 4 "context" 5 6 "github.com/bluesky-social/indigo/atproto/identity" 7 "tangled.org/core/appview/db" 8 "tangled.org/core/appview/models" 9 "tangled.org/core/appview/oauth" 10 "tangled.org/core/appview/pages/repoinfo" 11) 12 13// GetRepoInfo converts given `Repo` to `RepoInfo` object. 14// The `user` can be nil. 15// NOTE: RepoInfo is bad design and should be removed in future. 16// avoid using this method if you can. 17func (s *Service) GetRepoInfo( 18 ctx context.Context, 19 ownerId *identity.Identity, 20 baseRepo *models.Repo, 21 currentDir, ref string, 22 user *oauth.User, 23) (*repoinfo.RepoInfo, error) { 24 var ( 25 repoAt = baseRepo.RepoAt() 26 isStarred = false 27 roles = repoinfo.RolesInRepo{} 28 ) 29 if user != nil { 30 isStarred = db.GetStarStatus(s.db, user.Did, repoAt) 31 roles.Roles = s.enforcer.GetPermissionsInRepo(user.Did, baseRepo.Knot, baseRepo.DidSlashRepo()) 32 } 33 34 stats := baseRepo.RepoStats 35 if stats == nil { 36 starCount, err := db.GetStarCount(s.db, repoAt) 37 if err != nil { 38 return nil, err 39 } 40 issueCount, err := db.GetIssueCount(s.db, repoAt) 41 if err != nil { 42 return nil, err 43 } 44 pullCount, err := db.GetPullCount(s.db, repoAt) 45 if err != nil { 46 return nil, err 47 } 48 stats = &models.RepoStats{ 49 StarCount: starCount, 50 IssueCount: issueCount, 51 PullCount: pullCount, 52 } 53 } 54 55 var sourceRepo *models.Repo 56 var err error 57 if baseRepo.Source != "" { 58 sourceRepo, err = db.GetRepoByAtUri(s.db, baseRepo.Source) 59 if err != nil { 60 return nil, err 61 } 62 } 63 64 repoInfo := &repoinfo.RepoInfo{ 65 // ok this is basically a models.Repo 66 OwnerDid: baseRepo.Did, 67 OwnerHandle: ownerId.Handle.String(), // TODO: shouldn't use 68 Name: baseRepo.Name, 69 Rkey: baseRepo.Rkey, 70 Description: baseRepo.Description, 71 Website: baseRepo.Website, 72 Topics: baseRepo.Topics, 73 Knot: baseRepo.Knot, 74 Spindle: baseRepo.Spindle, 75 Stats: *stats, 76 77 // fork repo upstream 78 Source: sourceRepo, 79 80 // repo path (context) 81 CurrentDir: currentDir, 82 Ref: ref, 83 84 // info related to the session 85 IsStarred: isStarred, 86 Roles: roles, 87 } 88 89 return repoInfo, nil 90}