Monorepo for Tangled

appview/pulls: use simpler comment count in og cards

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

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