Skip to content

Commit c42bde7

Browse files
apricotelafriks
authored andcommitted
Only count users own actions for heatmap contributions (#5647)
Signed-off-by: Julian Tölle <[email protected]>
1 parent 97dafdc commit c42bde7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

models/user_heatmap.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
3232
groupByName = groupBy
3333
}
3434

35-
err := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
35+
sess := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
3636
Table("action").
3737
Where("user_id = ?", user.ID).
38-
And("created_unix > ?", (util.TimeStampNow() - 31536000)).
39-
GroupBy(groupByName).
38+
And("created_unix > ?", (util.TimeStampNow() - 31536000))
39+
40+
// * Heatmaps for individual users only include actions that the user themself
41+
// did.
42+
// * For organizations actions by all users that were made in owned
43+
// repositories are counted.
44+
if user.Type == UserTypeIndividual {
45+
sess = sess.And("act_user_id = ?", user.ID)
46+
}
47+
48+
err := sess.GroupBy(groupByName).
4049
OrderBy("timestamp").
4150
Find(&hdata)
51+
4252
return hdata, err
4353
}

0 commit comments

Comments
 (0)