mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 23:53:52 +03:00
Add issue closed time column to fix activity closed issues list (#3537)
Signed-off-by: Lauris Bukšis-Haberkorns <lauris@nix.lv>
This commit is contained in:
parent
fb2c176491
commit
58893384e8
6 changed files with 50 additions and 6 deletions
|
@ -49,6 +49,7 @@ type Issue struct {
|
||||||
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
|
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
|
||||||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||||
|
ClosedUnix util.TimeStamp `xorm:"INDEX"`
|
||||||
|
|
||||||
Attachments []*Attachment `xorm:"-"`
|
Attachments []*Attachment `xorm:"-"`
|
||||||
Comments []*Comment `xorm:"-"`
|
Comments []*Comment `xorm:"-"`
|
||||||
|
@ -612,8 +613,13 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
issue.IsClosed = isClosed
|
issue.IsClosed = isClosed
|
||||||
|
if isClosed {
|
||||||
|
issue.ClosedUnix = util.TimeStampNow()
|
||||||
|
} else {
|
||||||
|
issue.ClosedUnix = 0
|
||||||
|
}
|
||||||
|
|
||||||
if err = updateIssueCols(e, issue, "is_closed"); err != nil {
|
if err = updateIssueCols(e, issue, "is_closed", "closed_unix"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,13 +214,15 @@ func TestChangeMilestoneIssueStats(t *testing.T) {
|
||||||
"is_closed=0").(*Issue)
|
"is_closed=0").(*Issue)
|
||||||
|
|
||||||
issue.IsClosed = true
|
issue.IsClosed = true
|
||||||
_, err := x.Cols("is_closed").Update(issue)
|
issue.ClosedUnix = util.TimeStampNow()
|
||||||
|
_, err := x.Cols("is_closed", "closed_unix").Update(issue)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NoError(t, changeMilestoneIssueStats(x.NewSession(), issue))
|
assert.NoError(t, changeMilestoneIssueStats(x.NewSession(), issue))
|
||||||
CheckConsistencyFor(t, &Milestone{})
|
CheckConsistencyFor(t, &Milestone{})
|
||||||
|
|
||||||
issue.IsClosed = false
|
issue.IsClosed = false
|
||||||
_, err = x.Cols("is_closed").Update(issue)
|
issue.ClosedUnix = 0
|
||||||
|
_, err = x.Cols("is_closed", "closed_unix").Update(issue)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NoError(t, changeMilestoneIssueStats(x.NewSession(), issue))
|
assert.NoError(t, changeMilestoneIssueStats(x.NewSession(), issue))
|
||||||
CheckConsistencyFor(t, &Milestone{})
|
CheckConsistencyFor(t, &Milestone{})
|
||||||
|
|
|
@ -166,6 +166,8 @@ var migrations = []Migration{
|
||||||
NewMigration("add writable deploy keys", addModeToDeploKeys),
|
NewMigration("add writable deploy keys", addModeToDeploKeys),
|
||||||
// v56 -> v57
|
// v56 -> v57
|
||||||
NewMigration("remove is_owner, num_teams columns from org_user", removeIsOwnerColumnFromOrgUser),
|
NewMigration("remove is_owner, num_teams columns from org_user", removeIsOwnerColumnFromOrgUser),
|
||||||
|
// v57 -> v58
|
||||||
|
NewMigration("add closed_unix column for issues", addIssueClosedTime),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
|
|
30
models/migrations/v57.go
Normal file
30
models/migrations/v57.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2017 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/util"
|
||||||
|
|
||||||
|
"github.com/go-xorm/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addIssueClosedTime(x *xorm.Engine) error {
|
||||||
|
// Issue see models/issue.go
|
||||||
|
type Issue struct {
|
||||||
|
ClosedUnix util.TimeStamp `xorm:"INDEX"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := x.Sync2(new(Issue)); err != nil {
|
||||||
|
return fmt.Errorf("Sync2: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := x.Exec("UPDATE `issue` SET `closed_unix` = `updated_unix` WHERE `is_closed` = ?", true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -176,7 +176,7 @@ func (stats *ActivityStats) FillIssues(repoID int64, fromTime time.Time) error {
|
||||||
|
|
||||||
// Closed issues
|
// Closed issues
|
||||||
sess := issuesForActivityStatement(repoID, fromTime, true, false)
|
sess := issuesForActivityStatement(repoID, fromTime, true, false)
|
||||||
sess.OrderBy("issue.updated_unix DESC")
|
sess.OrderBy("issue.closed_unix DESC")
|
||||||
stats.ClosedIssues = make(IssueList, 0)
|
stats.ClosedIssues = make(IssueList, 0)
|
||||||
if err = sess.Find(&stats.ClosedIssues); err != nil {
|
if err = sess.Find(&stats.ClosedIssues); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -228,7 +228,11 @@ func issuesForActivityStatement(repoID int64, fromTime time.Time, closed, unreso
|
||||||
|
|
||||||
if !unresolved {
|
if !unresolved {
|
||||||
sess.And("issue.is_pull = ?", false)
|
sess.And("issue.is_pull = ?", false)
|
||||||
|
if closed {
|
||||||
|
sess.And("issue.closed_unix >= ?", fromTime.Unix())
|
||||||
|
} else {
|
||||||
sess.And("issue.created_unix >= ?", fromTime.Unix())
|
sess.And("issue.created_unix >= ?", fromTime.Unix())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sess.And("issue.created_unix < ?", fromTime.Unix())
|
sess.And("issue.created_unix < ?", fromTime.Unix())
|
||||||
sess.And("issue.updated_unix >= ?", fromTime.Unix())
|
sess.And("issue.updated_unix >= ?", fromTime.Unix())
|
||||||
|
|
|
@ -134,7 +134,7 @@
|
||||||
<p class="desc">
|
<p class="desc">
|
||||||
<div class="ui red label">{{$.i18n.Tr "repo.activity.closed_issue_label"}}</div>
|
<div class="ui red label">{{$.i18n.Tr "repo.activity.closed_issue_label"}}</div>
|
||||||
#{{.Index}} <a class="title has-emoji" href="{{$.Repository.HTMLURL}}/issues/{{.Index}}">{{.Title}}</a>
|
#{{.Index}} <a class="title has-emoji" href="{{$.Repository.HTMLURL}}/issues/{{.Index}}">{{.Title}}</a>
|
||||||
{{TimeSinceUnix .UpdatedUnix $.Lang}}
|
{{TimeSinceUnix .ClosedUnix $.Lang}}
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue