From 34795770c337c3bfcc56600a41a9c4bec31d0a8e Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Wed, 5 Aug 2015 20:52:17 +0800
Subject: [PATCH] fix issue stats with milestone filter

---
 models/issue.go       | 5 ++++-
 routers/repo/issue.go | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/models/issue.go b/models/issue.go
index 9fd53b47f9..80afb415bb 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -426,7 +426,7 @@ const (
 )
 
 // GetIssueStats returns issue statistic information by given conditions.
-func GetIssueStats(repoID, uid, labelID int64, isShowClosed bool, filterMode int) *IssueStats {
+func GetIssueStats(repoID, uid, labelID, milestoneID int64, isShowClosed bool, filterMode int) *IssueStats {
 	stats := &IssueStats{}
 	issue := new(Issue)
 
@@ -434,6 +434,9 @@ func GetIssueStats(repoID, uid, labelID int64, isShowClosed bool, filterMode int
 	if labelID > 0 {
 		queryStr += " AND issue.label_ids like '%$" + com.ToStr(labelID) + "|%'"
 	}
+	if milestoneID > 0 {
+		queryStr += " AND milestone_id=" + com.ToStr(milestoneID)
+	}
 	switch filterMode {
 	case FM_ALL:
 		stats.OpenCount, _ = x.Where(queryStr, repoID, false).Count(issue)
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 84046ef784..42b0e1856b 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -95,7 +95,7 @@ func Issues(ctx *middleware.Context) {
 	selectLabels := ctx.Query("labels")
 	milestoneID := ctx.QueryInt64("milestone")
 	isShowClosed := ctx.Query("state") == "closed"
-	issueStats := models.GetIssueStats(repo.Id, uid, com.StrTo(selectLabels).MustInt64(), isShowClosed, filterMode)
+	issueStats := models.GetIssueStats(repo.Id, uid, com.StrTo(selectLabels).MustInt64(), milestoneID, isShowClosed, filterMode)
 
 	page := ctx.QueryInt("page")
 	if page <= 1 {