mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
Check ignored errors for issue and milestone count (#3213)
This commit is contained in:
parent
9a0e2a8b07
commit
0e384c6376
3 changed files with 57 additions and 21 deletions
|
@ -165,31 +165,33 @@ func UpdateMilestone(m *Milestone) error {
|
||||||
return updateMilestone(x, m)
|
return updateMilestone(x, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func countRepoMilestones(e Engine, repoID int64) int64 {
|
func countRepoMilestones(e Engine, repoID int64) (int64, error) {
|
||||||
count, _ := e.
|
return e.
|
||||||
Where("repo_id=?", repoID).
|
Where("repo_id=?", repoID).
|
||||||
Count(new(Milestone))
|
Count(new(Milestone))
|
||||||
return count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func countRepoClosedMilestones(e Engine, repoID int64) int64 {
|
func countRepoClosedMilestones(e Engine, repoID int64) (int64, error) {
|
||||||
closed, _ := e.
|
return e.
|
||||||
Where("repo_id=? AND is_closed=?", repoID, true).
|
Where("repo_id=? AND is_closed=?", repoID, true).
|
||||||
Count(new(Milestone))
|
Count(new(Milestone))
|
||||||
return closed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountRepoClosedMilestones returns number of closed milestones in given repository.
|
// CountRepoClosedMilestones returns number of closed milestones in given repository.
|
||||||
func CountRepoClosedMilestones(repoID int64) int64 {
|
func CountRepoClosedMilestones(repoID int64) (int64, error) {
|
||||||
return countRepoClosedMilestones(x, repoID)
|
return countRepoClosedMilestones(x, repoID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MilestoneStats returns number of open and closed milestones of given repository.
|
// MilestoneStats returns number of open and closed milestones of given repository.
|
||||||
func MilestoneStats(repoID int64) (open int64, closed int64) {
|
func MilestoneStats(repoID int64) (open int64, closed int64, err error) {
|
||||||
open, _ = x.
|
open, err = x.
|
||||||
Where("repo_id=? AND is_closed=?", repoID, false).
|
Where("repo_id=? AND is_closed=?", repoID, false).
|
||||||
Count(new(Milestone))
|
Count(new(Milestone))
|
||||||
return open, CountRepoClosedMilestones(repoID)
|
if err != nil {
|
||||||
|
return 0, 0, nil
|
||||||
|
}
|
||||||
|
closed, err = CountRepoClosedMilestones(repoID)
|
||||||
|
return open, closed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeMilestoneStatus changes the milestone open/closed status.
|
// ChangeMilestoneStatus changes the milestone open/closed status.
|
||||||
|
@ -210,8 +212,17 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
|
numMilestones, err := countRepoMilestones(sess, repo.ID)
|
||||||
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
numClosedMilestones, err := countRepoClosedMilestones(sess, repo.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.NumMilestones = int(numMilestones)
|
||||||
|
repo.NumClosedMilestones = int(numClosedMilestones)
|
||||||
|
|
||||||
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -324,8 +335,17 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.NumMilestones = int(countRepoMilestones(sess, repo.ID))
|
numMilestones, err := countRepoMilestones(sess, repo.ID)
|
||||||
repo.NumClosedMilestones = int(countRepoClosedMilestones(sess, repo.ID))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
numClosedMilestones, err := countRepoClosedMilestones(sess, repo.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
repo.NumMilestones = int(numMilestones)
|
||||||
|
repo.NumClosedMilestones = int(numClosedMilestones)
|
||||||
|
|
||||||
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
if _, err = sess.ID(repo.ID).Cols("num_milestones, num_closed_milestones").Update(repo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,31 +146,42 @@ func TestCountRepoMilestones(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
test := func(repoID int64) {
|
test := func(repoID int64) {
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||||
assert.EqualValues(t, repo.NumMilestones, countRepoMilestones(x, repoID))
|
count, err := countRepoMilestones(x, repoID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, repo.NumMilestones, count)
|
||||||
}
|
}
|
||||||
test(1)
|
test(1)
|
||||||
test(2)
|
test(2)
|
||||||
test(3)
|
test(3)
|
||||||
assert.EqualValues(t, 0, countRepoMilestones(x, NonexistentID))
|
|
||||||
|
count, err := countRepoMilestones(x, NonexistentID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 0, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCountRepoClosedMilestones(t *testing.T) {
|
func TestCountRepoClosedMilestones(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
test := func(repoID int64) {
|
test := func(repoID int64) {
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||||
assert.EqualValues(t, repo.NumClosedMilestones, CountRepoClosedMilestones(repoID))
|
count, err := CountRepoClosedMilestones(repoID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, repo.NumClosedMilestones, count)
|
||||||
}
|
}
|
||||||
test(1)
|
test(1)
|
||||||
test(2)
|
test(2)
|
||||||
test(3)
|
test(3)
|
||||||
assert.EqualValues(t, 0, countRepoMilestones(x, NonexistentID))
|
|
||||||
|
count, err := CountRepoClosedMilestones(NonexistentID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 0, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMilestoneStats(t *testing.T) {
|
func TestMilestoneStats(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
test := func(repoID int64) {
|
test := func(repoID int64) {
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||||
open, closed := MilestoneStats(repoID)
|
open, closed, err := MilestoneStats(repoID)
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, repo.NumMilestones-repo.NumClosedMilestones, open)
|
assert.EqualValues(t, repo.NumMilestones-repo.NumClosedMilestones, open)
|
||||||
assert.EqualValues(t, repo.NumClosedMilestones, closed)
|
assert.EqualValues(t, repo.NumClosedMilestones, closed)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +189,8 @@ func TestMilestoneStats(t *testing.T) {
|
||||||
test(2)
|
test(2)
|
||||||
test(3)
|
test(3)
|
||||||
|
|
||||||
open, closed := MilestoneStats(NonexistentID)
|
open, closed, err := MilestoneStats(NonexistentID)
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 0, open)
|
assert.EqualValues(t, 0, open)
|
||||||
assert.EqualValues(t, 0, closed)
|
assert.EqualValues(t, 0, closed)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1067,7 +1067,11 @@ func Milestones(ctx *context.Context) {
|
||||||
ctx.Data["PageIsMilestones"] = true
|
ctx.Data["PageIsMilestones"] = true
|
||||||
|
|
||||||
isShowClosed := ctx.Query("state") == "closed"
|
isShowClosed := ctx.Query("state") == "closed"
|
||||||
openCount, closedCount := models.MilestoneStats(ctx.Repo.Repository.ID)
|
openCount, closedCount, err := models.MilestoneStats(ctx.Repo.Repository.ID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "MilestoneStats", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Data["OpenCount"] = openCount
|
ctx.Data["OpenCount"] = openCount
|
||||||
ctx.Data["ClosedCount"] = closedCount
|
ctx.Data["ClosedCount"] = closedCount
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue