summaryrefslogtreecommitdiffstats
path: root/models/issue_milestone.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-12-18 06:06:51 -0800
committerLauris BH <lauris@nix.lv>2017-12-18 16:06:51 +0200
commit0e384c6376ceb8fb7eb03636ba44c8aea338ad7a (patch)
tree7ceb927f0e33b21062828dab3695987fc1f65392 /models/issue_milestone.go
parent9a0e2a8b074d209b043b8d9e3d16f1ce4cdcab2d (diff)
downloadgitea-0e384c6376ceb8fb7eb03636ba44c8aea338ad7a.tar.gz
gitea-0e384c6376ceb8fb7eb03636ba44c8aea338ad7a.zip
Check ignored errors for issue and milestone count (#3213)
Diffstat (limited to 'models/issue_milestone.go')
-rw-r--r--models/issue_milestone.go48
1 files changed, 34 insertions, 14 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index 6ec8291233..761b598e92 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -165,31 +165,33 @@ func UpdateMilestone(m *Milestone) error {
return updateMilestone(x, m)
}
-func countRepoMilestones(e Engine, repoID int64) int64 {
- count, _ := e.
+func countRepoMilestones(e Engine, repoID int64) (int64, error) {
+ return e.
Where("repo_id=?", repoID).
Count(new(Milestone))
- return count
}
-func countRepoClosedMilestones(e Engine, repoID int64) int64 {
- closed, _ := e.
+func countRepoClosedMilestones(e Engine, repoID int64) (int64, error) {
+ return e.
Where("repo_id=? AND is_closed=?", repoID, true).
Count(new(Milestone))
- return closed
}
// CountRepoClosedMilestones returns number of closed milestones in given repository.
-func CountRepoClosedMilestones(repoID int64) int64 {
+func CountRepoClosedMilestones(repoID int64) (int64, error) {
return countRepoClosedMilestones(x, repoID)
}
// MilestoneStats returns number of open and closed milestones of given repository.
-func MilestoneStats(repoID int64) (open int64, closed int64) {
- open, _ = x.
+func MilestoneStats(repoID int64) (open int64, closed int64, err error) {
+ open, err = x.
Where("repo_id=? AND is_closed=?", repoID, false).
Count(new(Milestone))
- return open, CountRepoClosedMilestones(repoID)
+ if err != nil {
+ return 0, 0, nil
+ }
+ closed, err = CountRepoClosedMilestones(repoID)
+ return open, closed, err
}
// ChangeMilestoneStatus changes the milestone open/closed status.
@@ -210,8 +212,17 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
return err
}
- repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
- repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
+ numMilestones, err := countRepoMilestones(sess, repo.ID)
+ if err != nil {
+ return err
+ }
+ numClosedMilestones, err := countRepoClosedMilestones(sess, repo.ID)
+ if err != nil {
+ return err
+ }
+ repo.NumMilestones = int(numMilestones)
+ repo.NumClosedMilestones = int(numClosedMilestones)
+
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
return err
}
@@ -324,8 +335,17 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
return err
}
- repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
- repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
+ numMilestones, err := countRepoMilestones(sess, repo.ID)
+ if err != nil {
+ return err
+ }
+ numClosedMilestones, err := countRepoClosedMilestones(sess, repo.ID)
+ if err != nil {
+ return err
+ }
+ repo.NumMilestones = int(numMilestones)
+ repo.NumClosedMilestones = int(numClosedMilestones)
+
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
return err
}