Merge pull request 'fix: correct SQL query for active issues' (#5627) from gusted/forgejo-fix-active-issues into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5627 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
commit
55c30ba266
2 changed files with 31 additions and 2 deletions
|
@ -337,8 +337,7 @@ func newlyCreatedIssues(ctx context.Context, repoID int64, fromTime time.Time) *
|
||||||
func activeIssues(ctx context.Context, repoID int64, fromTime time.Time) *xorm.Session {
|
func activeIssues(ctx context.Context, repoID int64, fromTime time.Time) *xorm.Session {
|
||||||
sess := db.GetEngine(ctx).Where("issue.repo_id = ?", repoID).
|
sess := db.GetEngine(ctx).Where("issue.repo_id = ?", repoID).
|
||||||
And("issue.is_pull = ?", false).
|
And("issue.is_pull = ?", false).
|
||||||
And("issue.created_unix >= ?", fromTime.Unix()).
|
And("issue.created_unix >= ? OR issue.closed_unix >= ?", fromTime.Unix(), fromTime.Unix())
|
||||||
Or("issue.closed_unix >= ?", fromTime.Unix())
|
|
||||||
|
|
||||||
return sess
|
return sess
|
||||||
}
|
}
|
||||||
|
|
30
models/activities/repo_activity_test.go
Normal file
30
models/activities/repo_activity_test.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package activities
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetActivityStats(t *testing.T) {
|
||||||
|
require.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
|
stats, err := GetActivityStats(db.DefaultContext, repo, time.Unix(0, 0), true, true, true, true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.EqualValues(t, 2, stats.ActiveIssueCount())
|
||||||
|
assert.EqualValues(t, 2, stats.OpenedIssueCount())
|
||||||
|
assert.EqualValues(t, 0, stats.ClosedIssueCount())
|
||||||
|
assert.EqualValues(t, 3, stats.ActivePRCount())
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue