summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-09-05 19:38:54 +0200
committerGitHub <noreply@github.com>2020-09-05 13:38:54 -0400
commit1ea1cade8559e1d2aa75916c0dbfe31903423101 (patch)
treebcbf57e73c97b741f2c710804acb0b392fe71e79 /models
parent74047864202f2b34ded176597ca0b94034665b52 (diff)
downloadgitea-1ea1cade8559e1d2aa75916c0dbfe31903423101.tar.gz
gitea-1ea1cade8559e1d2aa75916c0dbfe31903423101.zip
Add Created & Updated to Milestone (#12662)
* Add Created and Updated to Milestone table and expose via API * Expose to UI - To Overloaded ?!? * fix unit test Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r--models/issue_milestone.go9
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v149.go25
3 files changed, 35 insertions, 1 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index f4fba84ec0..5c34834e2a 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -7,6 +7,7 @@ package models
import (
"fmt"
"strings"
+ "time"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -31,11 +32,14 @@ type Milestone struct {
Completeness int // Percentage(1-100).
IsOverdue bool `xorm:"-"`
- DeadlineString string `xorm:"-"`
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
DeadlineUnix timeutil.TimeStamp
ClosedDateUnix timeutil.TimeStamp
+ DeadlineString string `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"`
+ TimeSinceUpdate int64 `xorm:"-"`
}
// BeforeUpdate is invoked from XORM before updating this object.
@@ -50,6 +54,9 @@ func (m *Milestone) BeforeUpdate() {
// AfterLoad is invoked from XORM after setting the value of a field of
// this object.
func (m *Milestone) AfterLoad() {
+ if !m.UpdatedUnix.IsZero() {
+ m.TimeSinceUpdate = time.Now().Unix() - m.UpdatedUnix.AsTime().Unix()
+ }
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
if m.DeadlineUnix.Year() == 9999 {
return
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 6d27934f6d..aca3891f3d 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -230,6 +230,8 @@ var migrations = []Migration{
NewMigration("create review for 0 review id code comments", createReviewsForCodeComments),
// v148 -> v149
NewMigration("remove issue dependency comments who refer to non existing issues", purgeInvalidDependenciesComments),
+ // v149 -> v150
+ NewMigration("Add Created and Updated to Milestone table", addCreatedAndUpdatedToMilestones),
}
// GetCurrentDBVersion returns the current db version
diff --git a/models/migrations/v149.go b/models/migrations/v149.go
new file mode 100644
index 0000000000..60c0fae8bc
--- /dev/null
+++ b/models/migrations/v149.go
@@ -0,0 +1,25 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+
+ "code.gitea.io/gitea/modules/timeutil"
+
+ "xorm.io/xorm"
+)
+
+func addCreatedAndUpdatedToMilestones(x *xorm.Engine) error {
+ type Milestone struct {
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
+ }
+
+ if err := x.Sync2(new(Milestone)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ return nil
+}