Skip to content

Commit

Permalink
Add Created & Updated to Milestone (#12662)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
6543 and techknowlogick committed Sep 5, 2020
1 parent 7404786 commit 1ea1cad
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 1 deletion.
9 changes: 8 additions & 1 deletion models/issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"fmt"
"strings"
"time"

"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions models/migrations/v149.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions modules/convert/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions modules/convert/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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))
}
4 changes: 4 additions & 0 deletions modules/structs/issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions templates/repo/issue/milestones.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}
Expand Down
10 changes: 10 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1ea1cad

Please sign in to comment.