forked from tangled.org/core
Monorepo for Tangled

appview/db: populate pull-source in GetPulls

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li c174b225 5c9bf597

verified
Changed files
+25
appview
+25
appview/db/pulls.go
··· 3 3 import ( 4 4 "cmp" 5 5 "database/sql" 6 + "errors" 6 7 "fmt" 7 8 "maps" 8 9 "slices" ··· 230 231 p.Submissions = submissions 231 232 } 232 233 } 234 + 233 235 // collect allLabels for each issue 234 236 allLabels, err := GetLabels(e, FilterIn("subject", pullAts)) 235 237 if err != nil { ··· 238 240 for pullAt, labels := range allLabels { 239 241 if p, ok := pulls[pullAt]; ok { 240 242 p.Labels = labels 243 + } 244 + } 245 + 246 + // collect pull source for all pulls that need it 247 + var sourceAts []syntax.ATURI 248 + for _, p := range pulls { 249 + if p.PullSource.RepoAt != nil { 250 + sourceAts = append(sourceAts, *p.PullSource.RepoAt) 251 + } 252 + } 253 + sourceRepos, err := GetRepos(e, 0, FilterIn("at_uri", sourceAts)) 254 + if err != nil && !errors.Is(err, sql.ErrNoRows) { 255 + return nil, fmt.Errorf("failed to get source repos: %w", err) 256 + } 257 + sourceRepoMap := make(map[syntax.ATURI]*models.Repo) 258 + for _, r := range sourceRepos { 259 + sourceRepoMap[r.RepoAt()] = &r 260 + } 261 + for _, p := range pulls { 262 + if p.PullSource.RepoAt != nil { 263 + if sourceRepo, ok := sourceRepoMap[*p.PullSource.RepoAt]; ok { 264 + p.PullSource.Repo = sourceRepo 265 + } 241 266 } 242 267 } 243 268