Skip to content

fix: only count users own actions for heatmap contributions #5647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 6, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions models/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
groupByName = groupBy
}

var isOrganization string
switch user.Type {
case UserTypeIndividual:
// For invidividual users only their own contributions count
isOrganization = "0"
case UserTypeOrganization:
// For organisations contributions by every user in owned repos count
isOrganization = "1" // mssql does not support boolean literal for expressions
}

err := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
Table("action").
Where("user_id = ?", user.ID).
And("(1 = ? OR act_user_id = ?)", isOrganization, user.ID).
And("created_unix > ?", (util.TimeStampNow() - 31536000)).
GroupBy(groupByName).
OrderBy("timestamp").
Expand Down