Add additional sections.

This commit is contained in:
2025-12-11 11:03:20 +00:00
parent 9ded096839
commit 8073711f4b
18 changed files with 497 additions and 82 deletions
+4
View File
@@ -19,6 +19,10 @@ type Commit struct {
MeaningfulAdditions int `json:"meaningful_additions"`
MeaningfulDeletions int `json:"meaningful_deletions"`
// Comment line counts
CommentAdditions int `json:"comment_additions"`
CommentDeletions int `json:"comment_deletions"`
// Derived fields
HasTests bool `json:"has_tests"`
}
+4
View File
@@ -27,6 +27,10 @@ type ContributorMetrics struct {
MeaningfulLinesAdded int `json:"meaningful_lines_added"`
MeaningfulLinesDeleted int `json:"meaningful_lines_deleted"`
// Comment and documentation line counts
CommentLinesAdded int `json:"comment_lines_added"`
CommentLinesDeleted int `json:"comment_lines_deleted"`
// PR metrics
PRsOpened int `json:"prs_opened"`
PRsMerged int `json:"prs_merged"`
+7
View File
@@ -42,6 +42,8 @@ func (c *Calculator) Calculate(metrics *models.GlobalMetrics) *models.GlobalMetr
existing.LinesDeleted += cm.LinesDeleted
existing.MeaningfulLinesAdded += cm.MeaningfulLinesAdded
existing.MeaningfulLinesDeleted += cm.MeaningfulLinesDeleted
existing.CommentLinesAdded += cm.CommentLinesAdded
existing.CommentLinesDeleted += cm.CommentLinesDeleted
existing.PRsOpened += cm.PRsOpened
existing.PRsMerged += cm.PRsMerged
existing.ReviewsGiven += cm.ReviewsGiven
@@ -257,6 +259,11 @@ func (c *Calculator) checkAchievements(cm *models.ContributorMetrics) []string {
earned = float64(cm.OutOfHoursCount) >= ach.Condition.Threshold
case "work_week_streak":
earned = float64(cm.WorkWeekStreak) >= ach.Condition.Threshold
// Documentation & comments
case "comment_lines_added":
earned = float64(cm.CommentLinesAdded) >= ach.Condition.Threshold
case "comment_lines_deleted":
earned = float64(cm.CommentLinesDeleted) >= ach.Condition.Threshold
}
if earned {
+125
View File
@@ -878,3 +878,128 @@ func TestCalculator_MeaningfulLinesScoring(t *testing.T) {
assert.Equal(t, 50, contributor.Score.Total)
})
}
func TestCalculator_CommentLinesAchievements(t *testing.T) {
t.Parallel()
t.Run("earns documentation achievements for adding comments", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "documenter",
CommitCount: 10,
CommentLinesAdded: 1500, // Should earn docs-100, docs-500, docs-1000
CommentLinesDeleted: 100, // Should earn docs-del-50
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have documentation achievements
assert.Contains(t, contributor.Achievements, "docs-100", "Should earn docs-100 for 100+ comment lines")
assert.Contains(t, contributor.Achievements, "docs-500", "Should earn docs-500 for 500+ comment lines")
assert.Contains(t, contributor.Achievements, "docs-1000", "Should earn docs-1000 for 1000+ comment lines")
assert.NotContains(t, contributor.Achievements, "docs-2500", "Should not earn docs-2500 for <2500 comment lines")
// Should have comment cleanup achievement
assert.Contains(t, contributor.Achievements, "docs-del-50", "Should earn docs-del-50 for 50+ comment deletions")
assert.NotContains(t, contributor.Achievements, "docs-del-200", "Should not earn docs-del-200 for <200 deletions")
})
t.Run("earns all documentation deletion achievements", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo",
Contributors: []models.ContributorMetrics{
{
Login: "cleanup-expert",
CommitCount: 50,
CommentLinesAdded: 100,
CommentLinesDeleted: 3000, // Should earn all deletion tiers
RepositoriesContributed: []string{"owner/repo"},
},
},
},
},
}
result := calc.Calculate(metrics)
contributor := result.Repositories[0].Contributors[0]
// Should have all comment cleanup achievements
assert.Contains(t, contributor.Achievements, "docs-del-50")
assert.Contains(t, contributor.Achievements, "docs-del-200")
assert.Contains(t, contributor.Achievements, "docs-del-500")
assert.Contains(t, contributor.Achievements, "docs-del-1000")
assert.Contains(t, contributor.Achievements, "docs-del-2500")
})
t.Run("aggregates comment lines across multiple repositories", func(t *testing.T) {
t.Parallel()
cfg := config.DefaultConfig()
cfg.Scoring.Enabled = true
calc := NewCalculator(cfg)
metrics := &models.GlobalMetrics{
Repositories: []models.RepositoryMetrics{
{
FullName: "owner/repo1",
Contributors: []models.ContributorMetrics{
{
Login: "multi-repo-doc",
CommitCount: 5,
CommentLinesAdded: 300,
CommentLinesDeleted: 30,
RepositoriesContributed: []string{"owner/repo1"},
},
},
},
{
FullName: "owner/repo2",
Contributors: []models.ContributorMetrics{
{
Login: "multi-repo-doc",
CommitCount: 5,
CommentLinesAdded: 300,
CommentLinesDeleted: 30,
RepositoriesContributed: []string{"owner/repo2"},
},
},
},
},
}
result := calc.Calculate(metrics)
// Check leaderboard entry (aggregated)
require.Len(t, result.Leaderboard, 1)
entry := result.Leaderboard[0]
// Aggregated: 300 + 300 = 600 comment lines added, 30 + 30 = 60 deleted
assert.Contains(t, entry.Achievements, "docs-100")
assert.Contains(t, entry.Achievements, "docs-500")
assert.NotContains(t, entry.Achievements, "docs-1000", "600 < 1000")
assert.Contains(t, entry.Achievements, "docs-del-50")
assert.NotContains(t, entry.Achievements, "docs-del-200", "60 < 200")
})
}