this repo has no description

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 { ··· 194 192 } 195 193 196 194 currentX += iconSize + 15 195 + commentCount := pull.TotalComments() 197 196 commentText := fmt.Sprintf("%d comments", commentCount) 198 197 if commentCount == 1 { 199 198 commentText = "1 comment" ··· 284 283 return 285 284 } 286 285 287 - // Get comment count from database 288 - comments, err := db.GetPullComments(s.db, orm.FilterEq("pull_id", pull.ID)) 289 - if err != nil { 290 - log.Printf("failed to get pull comments: %v", err) 291 - } 292 - commentCount := len(comments) 293 - 294 286 // Calculate diff stats from latest submission using patchutil 295 287 var diffStats types.DiffFileStat 296 288 filesChanged := 0 297 289 if len(pull.Submissions) > 0 { 298 - latestSubmission := pull.Submissions[len(pull.Submissions)-1] 290 + latestSubmission := pull.LatestSubmission() 299 291 niceDiff := patchutil.AsNiceDiff(latestSubmission.Patch, pull.TargetBranch) 300 292 diffStats.Insertions = int64(niceDiff.Stat.Insertions) 301 293 diffStats.Deletions = int64(niceDiff.Stat.Deletions) 302 294 filesChanged = niceDiff.Stat.FilesChanged 303 295 } 304 296 305 - card, err := s.drawPullSummaryCard(pull, f, commentCount, diffStats, filesChanged) 297 + card, err := s.drawPullSummaryCard(pull, f, diffStats, filesChanged) 306 298 if err != nil { 307 299 log.Println("failed to draw pull summary card", err) 308 300 http.Error(w, "failed to draw pull summary card", http.StatusInternalServerError)