aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issue_milestone.go27
-rw-r--r--models/issue_milestone_test.go2
2 files changed, 25 insertions, 4 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index 198fa7d78c..ba39e6ebc6 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -291,12 +291,33 @@ func updateMilestone(e Engine, m *Milestone) error {
}
// UpdateMilestone updates information of given milestone.
-func UpdateMilestone(m *Milestone) error {
- if err := updateMilestone(x, m); err != nil {
+func UpdateMilestone(m *Milestone, oldIsClosed bool) error {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ if m.IsClosed && !oldIsClosed {
+ m.ClosedDateUnix = timeutil.TimeStampNow()
+ }
+
+ if err := updateMilestone(sess, m); err != nil {
return err
}
- return updateMilestoneCompleteness(x, m.ID)
+ if err := updateMilestoneCompleteness(sess, m.ID); err != nil {
+ return err
+ }
+
+ // if IsClosed changed, update milestone numbers of repository
+ if oldIsClosed != m.IsClosed {
+ if err := updateRepoMilestoneNum(sess, m.RepoID); err != nil {
+ return err
+ }
+ }
+
+ return sess.Commit()
}
func updateMilestoneCompleteness(e Engine, milestoneID int64) error {
diff --git a/models/issue_milestone_test.go b/models/issue_milestone_test.go
index beeccdd0e4..778ebfbda3 100644
--- a/models/issue_milestone_test.go
+++ b/models/issue_milestone_test.go
@@ -160,7 +160,7 @@ func TestUpdateMilestone(t *testing.T) {
milestone := AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
milestone.Name = " newMilestoneName "
milestone.Content = "newMilestoneContent"
- assert.NoError(t, UpdateMilestone(milestone))
+ assert.NoError(t, UpdateMilestone(milestone, milestone.IsClosed))
milestone = AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
assert.EqualValues(t, "newMilestoneName", milestone.Name)
CheckConsistencyFor(t, &Milestone{})