mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 05:52:43 +00:00
Some refactors for issues stats (#24793)
This PR - [x] Move some functions from `issues.go` to `issue_stats.go` and `issue_label.go` - [x] Remove duplicated issue options `UserIssueStatsOption` to keep only one `IssuesOptions`
This commit is contained in:
parent
c757765a9e
commit
38cf43d060
12 changed files with 948 additions and 948 deletions
|
@ -17,6 +17,7 @@ import (
|
|||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/builder"
|
||||
|
@ -204,14 +205,16 @@ func TestIssues(t *testing.T) {
|
|||
func TestGetUserIssueStats(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
for _, test := range []struct {
|
||||
Opts issues_model.UserIssueStatsOptions
|
||||
FilterMode int
|
||||
Opts issues_model.IssuesOptions
|
||||
ExpectedIssueStats issues_model.IssueStats
|
||||
}{
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
RepoIDs: []int64{1},
|
||||
FilterMode: issues_model.FilterModeAll,
|
||||
issues_model.FilterModeAll,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
RepoIDs: []int64{1},
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 6
|
||||
|
@ -222,11 +225,12 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
RepoIDs: []int64{1},
|
||||
FilterMode: issues_model.FilterModeAll,
|
||||
IsClosed: true,
|
||||
issues_model.FilterModeAll,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
RepoIDs: []int64{1},
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 6
|
||||
|
@ -237,9 +241,10 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
FilterMode: issues_model.FilterModeAssign,
|
||||
issues_model.FilterModeAssign,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 6
|
||||
|
@ -250,9 +255,10 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
FilterMode: issues_model.FilterModeCreate,
|
||||
issues_model.FilterModeCreate,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 6
|
||||
|
@ -263,9 +269,10 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
FilterMode: issues_model.FilterModeMention,
|
||||
issues_model.FilterModeMention,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 6
|
||||
|
@ -277,10 +284,11 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 1,
|
||||
FilterMode: issues_model.FilterModeCreate,
|
||||
IssueIDs: []int64{1},
|
||||
issues_model.FilterModeCreate,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}),
|
||||
IssueIDs: []int64{1},
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 1, // 1
|
||||
|
@ -291,11 +299,12 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
issues_model.UserIssueStatsOptions{
|
||||
UserID: 2,
|
||||
Org: unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}),
|
||||
Team: unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 7}),
|
||||
FilterMode: issues_model.FilterModeAll,
|
||||
issues_model.FilterModeAll,
|
||||
issues_model.IssuesOptions{
|
||||
User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}),
|
||||
Org: unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}),
|
||||
Team: unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 7}),
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
},
|
||||
issues_model.IssueStats{
|
||||
YourRepositoriesCount: 2,
|
||||
|
@ -306,7 +315,7 @@ func TestGetUserIssueStats(t *testing.T) {
|
|||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%#v", test.Opts), func(t *testing.T) {
|
||||
stats, err := issues_model.GetUserIssueStats(test.Opts)
|
||||
stats, err := issues_model.GetUserIssueStats(test.FilterMode, test.Opts)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
@ -495,7 +504,7 @@ func TestCorrectIssueStats(t *testing.T) {
|
|||
// Now we will call the GetIssueStats with these IDs and if working,
|
||||
// get the correct stats back.
|
||||
issueStats, err := issues_model.GetIssueStats(&issues_model.IssuesOptions{
|
||||
RepoID: 1,
|
||||
RepoIDs: []int64{1},
|
||||
IssueIDs: ids,
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue