From d6538d8918e88fd01d80096fc9df778ebd919ee4 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Tue, 1 Oct 2019 22:18:51 -0300 Subject: [PATCH 1/3] Add test for FilterModeMention --- models/issue_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/models/issue_test.go b/models/issue_test.go index 317fc7bbc882..2335d5a0bbf7 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -279,6 +279,19 @@ func TestGetUserIssueStats(t *testing.T) { ClosedCount: 2, }, }, + { + UserIssueStatsOptions{ + UserID: 1, + FilterMode: FilterModeMention, + }, + IssueStats{ + YourRepositoriesCount: 0, + AssignCount: 2, + CreateCount: 2, + OpenCount: 0, + ClosedCount: 0, + }, + }, } { stats, err := GetUserIssueStats(test.Opts) if !assert.NoError(t, err) { From 6d7ef8cf0e7d22531ff6c4e9676312ce90b3c0c0 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Tue, 1 Oct 2019 22:19:32 -0300 Subject: [PATCH 2/3] Fix column name ambiguity --- models/issue.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/issue.go b/models/issue.go index da98fac7df36..422fa9d66096 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1655,14 +1655,14 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) { return nil, err } case FilterModeAssign: - stats.OpenCount, err = x.Where(cond).And("is_closed = ?", false). + stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id"). And("issue_assignees.assignee_id = ?", opts.UserID). Count(new(Issue)) if err != nil { return nil, err } - stats.ClosedCount, err = x.Where(cond).And("is_closed = ?", true). + stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id"). And("issue_assignees.assignee_id = ?", opts.UserID). Count(new(Issue)) @@ -1683,14 +1683,14 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) { return nil, err } case FilterModeMention: - stats.OpenCount, err = x.Where(cond).And("is_closed = ?", false). + stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true). And("issue_user.uid = ?", opts.UserID). Count(new(Issue)) if err != nil { return nil, err } - stats.ClosedCount, err = x.Where(cond).And("is_closed = ?", true). + stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true). Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true). And("issue_user.uid = ?", opts.UserID). Count(new(Issue)) From 919ef1eef1cdb80d557db3144f14c184b55a6928 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Tue, 1 Oct 2019 22:20:12 -0300 Subject: [PATCH 3/3] Fix fmt --- models/issue_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issue_test.go b/models/issue_test.go index 2335d5a0bbf7..9cd9ff0ad98a 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -281,8 +281,8 @@ func TestGetUserIssueStats(t *testing.T) { }, { UserIssueStatsOptions{ - UserID: 1, - FilterMode: FilterModeMention, + UserID: 1, + FilterMode: FilterModeMention, }, IssueStats{ YourRepositoriesCount: 0,