A vibe coded tangled fork which supports pijul.
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/pages/repoinfo"
10 "tangled.org/core/appview/session"
11)
12
13// MakeRepoInfo constructs [repoinfo.RepoInfo] object from given [models.Repo].
14//
15// NOTE: [repoinfo.RepoInfo] is bad design and should be removed in future.
16// Avoid using this method if you can.
17func (s *Service) MakeRepoInfo(
18 ctx context.Context,
19 ownerId *identity.Identity,
20 baseRepo *models.Repo,
21 currentDir, ref string,
22) repoinfo.RepoInfo {
23 var (
24 repoAt = baseRepo.RepoAt()
25 isStarred = false
26 roles = repoinfo.RolesInRepo{}
27 l = s.logger.With("method", "MakeRepoInfo").With("repoAt", repoAt)
28 )
29 sess, ok := session.FromContext(ctx)
30 if ok {
31 isStarred = db.GetStarStatus(s.db, sess.User.Did, repoAt)
32 roles.Roles = s.enforcer.GetPermissionsInRepo(sess.User.Did, baseRepo.Knot, baseRepo.DidSlashRepo())
33 }
34
35 stats := baseRepo.RepoStats
36 if stats == nil {
37 starCount, err := db.GetStarCount(s.db, repoAt)
38 if err != nil {
39 l.Error("failed to get star count", "err", err)
40 }
41 issueCount, err := db.GetIssueCount(s.db, repoAt)
42 if err != nil {
43 l.Error("failed to get issue count", "err", err)
44 }
45 pullCount, err := db.GetPullCount(s.db, repoAt)
46 if err != nil {
47 l.Error("failed to get pull count", "err", err)
48 }
49 stats = &models.RepoStats{
50 StarCount: starCount,
51 IssueCount: issueCount,
52 PullCount: pullCount,
53 }
54 }
55
56 var sourceRepo *models.Repo
57 var err error
58 if baseRepo.Source != "" {
59 sourceRepo, err = db.GetRepoByAtUri(s.db, baseRepo.Source)
60 if err != nil {
61 l.Error("failed to get source repo", "source", baseRepo.Source, "err", err)
62 }
63 }
64
65 return repoinfo.RepoInfo{
66 // this is basically a models.Repo
67 OwnerDid: baseRepo.Did,
68 OwnerHandle: ownerId.Handle.String(), // TODO: shouldn't use
69 Name: baseRepo.Name,
70 Rkey: baseRepo.Rkey,
71 Description: baseRepo.Description,
72 Website: baseRepo.Website,
73 Topics: baseRepo.Topics,
74 Knot: baseRepo.Knot,
75 Spindle: baseRepo.Spindle,
76 Stats: *stats,
77
78 // fork repo upstream
79 Source: sourceRepo,
80
81 // repo path (context)
82 CurrentDir: currentDir,
83 Ref: ref,
84
85 // info related to the session
86 IsStarred: isStarred,
87 Roles: roles,
88 }
89}