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

appview/pulls: use simpler comment count in og cards

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

oppi.li df9dddd2 770359e6

verified
+4 -12
+4 -12
appview/pulls/opengraph.go
··· 10 10 "log" 11 11 "net/http" 12 12 13 - "tangled.org/core/appview/db" 14 13 "tangled.org/core/appview/models" 15 14 "tangled.org/core/appview/ogcard" 16 - "tangled.org/core/orm" 17 15 "tangled.org/core/patchutil" 18 16 "tangled.org/core/types" 19 17 ) 20 18 21 - func (s *Pulls) drawPullSummaryCard(pull *models.Pull, repo *models.Repo, commentCount int, diffStats types.DiffFileStat, filesChanged int) (*ogcard.Card, error) { 19 + func (s *Pulls) drawPullSummaryCard(pull *models.Pull, repo *models.Repo, diffStats types.DiffFileStat, filesChanged int) (*ogcard.Card, error) { 22 20 width, height := ogcard.DefaultSize() 23 21 mainCard, err := ogcard.NewCard(width, height) 24 22 if err != nil { ··· 192 194 } 193 195 194 196 currentX += iconSize + 15 197 + commentCount := pull.TotalComments() 195 198 commentText := fmt.Sprintf("%d comments", commentCount) 196 199 if commentCount == 1 { 197 200 commentText = "1 comment" ··· 283 284 return 284 285 } 285 286 286 - // Get comment count from database 287 - comments, err := db.GetPullComments(s.db, orm.FilterEq("pull_id", pull.ID)) 288 - if err != nil { 289 - log.Printf("failed to get pull comments: %v", err) 290 - } 291 - commentCount := len(comments) 292 - 293 287 // Calculate diff stats from latest submission using patchutil 294 288 var diffStats types.DiffFileStat 295 289 filesChanged := 0 296 290 if len(pull.Submissions) > 0 { 297 - latestSubmission := pull.Submissions[len(pull.Submissions)-1] 291 + latestSubmission := pull.LatestSubmission() 298 292 niceDiff := patchutil.AsNiceDiff(latestSubmission.Patch, pull.TargetBranch) 299 293 diffStats.Insertions = int64(niceDiff.Stat.Insertions) 300 294 diffStats.Deletions = int64(niceDiff.Stat.Deletions) 301 295 filesChanged = niceDiff.Stat.FilesChanged 302 296 } 303 297 304 - card, err := s.drawPullSummaryCard(pull, f, commentCount, diffStats, filesChanged) 298 + card, err := s.drawPullSummaryCard(pull, f, diffStats, filesChanged) 305 299 if err != nil { 306 300 log.Println("failed to draw pull summary card", err) 307 301 http.Error(w, "failed to draw pull summary card", http.StatusInternalServerError)