Skip to content

Commit df6f221

Browse files
committed
fix: commit activity comes in oldest first from github
1 parent 8a4532a commit df6f221

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

scoring/commit_activity_scorer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ type CommitActivityScorer struct {
1515

1616
func (s CommitActivityScorer) GetScore(currentScore float64, penalties []ScoringPenalty) (float64, []ScoringPenalty) {
1717
weeksWithoutActivity := 0
18-
for _, commit := range s.data.CommitActivity {
18+
// loop in reverse because we get oldest first from github
19+
for i := len(s.data.CommitActivity) - 1; i >= 0; i-- {
20+
commit := s.data.CommitActivity[i]
1921
if commit.GetTotal() == 0 {
2022
weeksWithoutActivity++
2123
} else {

scoring/commit_activity_scorer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import (
1212
)
1313

1414
func getTestCommitActivityData(inactiveWeekCount int) []*github.WeeklyCommitActivity {
15-
// prepare commit activity data
15+
// prepare commit activity data: first an active week, then append inactive ones (we loop in reverse)
1616
activity := make([]*github.WeeklyCommitActivity, 0)
17+
one := 1
18+
firstActiveTime := github.Timestamp{Time: time.Now().Local().AddDate(0, 0, -7*inactiveWeekCount+2)}
19+
activity = append(activity, &github.WeeklyCommitActivity{Week: &firstActiveTime, Total: &one})
1720
if inactiveWeekCount > 0 {
1821
zero := 0
1922
for i := 1; i < inactiveWeekCount+1; i++ {
2023
time := github.Timestamp{Time: time.Now().Local().AddDate(0, 0, -7*i)}
2124
activity = append(activity, &github.WeeklyCommitActivity{Week: &time, Total: &zero})
2225
}
2326
}
24-
one := 1
25-
firstActiveTime := github.Timestamp{Time: time.Now().Local().AddDate(0, 0, -7*inactiveWeekCount+2)}
26-
activity = append(activity, &github.WeeklyCommitActivity{Week: &firstActiveTime, Total: &one})
2727
return activity
2828
}
2929

0 commit comments

Comments
 (0)