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 import ( 4 "cmp" 5 "database/sql" 6 "fmt" 7 "maps" 8 "slices" ··· 231 p.Submissions = submissions 232 } 233 } 234 // collect allLabels for each issue 235 allLabels, err := GetLabels(e, FilterIn("subject", pullAts)) 236 if err != nil { ··· 240 for pullAt, labels := range allLabels { 241 if p, ok := pulls[pullAt]; ok { 242 p.Labels = labels 243 } 244 } 245
··· 3 import ( 4 "cmp" 5 "database/sql" 6 + "errors" 7 "fmt" 8 "maps" 9 "slices" ··· 230 p.Submissions = submissions 231 } 232 } 233 + 234 // collect allLabels for each issue 235 allLabels, err := GetLabels(e, FilterIn("subject", pullAts)) 236 if err != nil { ··· 238 for pullAt, labels := range allLabels { 239 if p, ok := pulls[pullAt]; ok { 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 + } 264 } 265 } 266