Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

appview/db: populate pull-source in GetPulls

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

oppi.li c174b225 5c9bf597

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