summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--models/issue_milestone.go9
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v149.go25
-rw-r--r--modules/convert/issue.go2
-rw-r--r--modules/convert/issue_test.go4
-rw-r--r--modules/structs/issue_milestone.go4
-rw-r--r--options/locale/locale_en-US.ini1
-rw-r--r--templates/repo/issue/milestones.tmpl1
-rw-r--r--templates/swagger/v1_json.tmpl10
9 files changed, 57 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
+}
diff --git a/modules/convert/issue.go b/modules/convert/issue.go
index a335f6326b..e89021cbcc 100644
--- a/modules/convert/issue.go
+++ b/modules/convert/issue.go
@@ -152,6 +152,8 @@ func ToAPIMilestone(m *models.Milestone) *api.Milestone {
Description: m.Content,
OpenIssues: m.NumOpenIssues,
ClosedIssues: m.NumClosedIssues,
+ Created: m.CreatedUnix.AsTime(),
+ Updated: m.UpdatedUnix.AsTimePtr(),
}
if m.IsClosed {
apiMilestone.Closed = m.ClosedDateUnix.AsTimePtr()
diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go
index e5676293f8..2f8f56e99a 100644
--- a/modules/convert/issue_test.go
+++ b/modules/convert/issue_test.go
@@ -34,6 +34,8 @@ func TestMilestone_APIFormat(t *testing.T) {
IsClosed: false,
NumOpenIssues: 5,
NumClosedIssues: 6,
+ CreatedUnix: timeutil.TimeStamp(time.Date(1999, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()),
+ UpdatedUnix: timeutil.TimeStamp(time.Date(1999, time.March, 1, 0, 0, 0, 0, time.UTC).Unix()),
DeadlineUnix: timeutil.TimeStamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()),
}
assert.Equal(t, api.Milestone{
@@ -43,6 +45,8 @@ func TestMilestone_APIFormat(t *testing.T) {
Description: milestone.Content,
OpenIssues: milestone.NumOpenIssues,
ClosedIssues: milestone.NumClosedIssues,
+ Created: milestone.CreatedUnix.AsTime(),
+ Updated: milestone.UpdatedUnix.AsTimePtr(),
Deadline: milestone.DeadlineUnix.AsTimePtr(),
}, *ToAPIMilestone(milestone))
}
diff --git a/modules/structs/issue_milestone.go b/modules/structs/issue_milestone.go
index ec940c2604..ace783ebbc 100644
--- a/modules/structs/issue_milestone.go
+++ b/modules/structs/issue_milestone.go
@@ -17,6 +17,10 @@ type Milestone struct {
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
// swagger:strfmt date-time
+ Created time.Time `json:"created_at"`
+ // swagger:strfmt date-time
+ Updated *time.Time `json:"updated_at"`
+ // swagger:strfmt date-time
Closed *time.Time `json:"closed_at"`
// swagger:strfmt date-time
Deadline *time.Time `json:"due_on"`
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 94389a6355..91c1cbd8b2 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1241,6 +1241,7 @@ milestones.new = New Milestone
milestones.open_tab = %d Open
milestones.close_tab = %d Closed
milestones.closed = Closed %s
+milestones.update_ago = Updated %s ago
milestones.no_due_date = No due date
milestones.open = Open
milestones.close = Close
diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl
index bee1cee65b..1fb4906e45 100644
--- a/templates/repo/issue/milestones.tmpl
+++ b/templates/repo/issue/milestones.tmpl
@@ -65,6 +65,7 @@
{{svg "octicon-issue-opened" 16}} {{$.i18n.Tr "repo.issues.open_tab" .NumOpenIssues}}
{{svg "octicon-issue-closed" 16}} {{$.i18n.Tr "repo.issues.close_tab" .NumClosedIssues}}
{{if .TotalTrackedTime}}{{svg "octicon-clock" 16}} {{.TotalTrackedTime|Sec2Time}}{{end}}
+ {{if .UpdatedUnix}}{{svg "octicon-clock" 16}} {{$.i18n.Tr "repo.milestones.update_ago" (.TimeSinceUpdate|Sec2Time)}}{{end}}
</span>
</div>
{{if and (or $.CanWriteIssues $.CanWritePulls) (not $.Repository.IsArchived)}}
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index 09acd3a0a5..8381ebe774 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -13613,6 +13613,11 @@
"format": "int64",
"x-go-name": "ClosedIssues"
},
+ "created_at": {
+ "type": "string",
+ "format": "date-time",
+ "x-go-name": "Created"
+ },
"description": {
"type": "string",
"x-go-name": "Description"
@@ -13638,6 +13643,11 @@
"title": {
"type": "string",
"x-go-name": "Title"
+ },
+ "updated_at": {
+ "type": "string",
+ "format": "date-time",
+ "x-go-name": "Updated"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"