From b9fba8d71f2ce998cb65fbd67c5aec32fa97b509 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 13 Jun 2024 10:25:26 +0200 Subject: [PATCH 1/3] Fix bug in GetIssueStats --- models/issues/issue_stats.go | 2 +- models/issues/issue_stats_test.go | 34 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 models/issues/issue_stats_test.go diff --git a/models/issues/issue_stats.go b/models/issues/issue_stats.go index 39326616f..dc634cf00 100644 --- a/models/issues/issue_stats.go +++ b/models/issues/issue_stats.go @@ -107,7 +107,7 @@ func GetIssueStats(ctx context.Context, opts *IssuesOptions) (*IssueStats, error accum.YourRepositoriesCount += stats.YourRepositoriesCount accum.AssignCount += stats.AssignCount accum.CreateCount += stats.CreateCount - accum.OpenCount += stats.MentionCount + accum.MentionCount += stats.MentionCount accum.ReviewRequestedCount += stats.ReviewRequestedCount accum.ReviewedCount += stats.ReviewedCount i = chunk diff --git a/models/issues/issue_stats_test.go b/models/issues/issue_stats_test.go new file mode 100644 index 000000000..cf4a47ccc --- /dev/null +++ b/models/issues/issue_stats_test.go @@ -0,0 +1,34 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package issues_test + +import ( + "testing" + + "code.gitea.io/gitea/models/db" + issues_model "code.gitea.io/gitea/models/issues" + + "code.gitea.io/gitea/models/unittest" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetIssueStats(t *testing.T) { + require.NoError(t, unittest.PrepareTestDatabase()) + + ids, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) + require.NoError(t, err) + + stats, err := issues_model.GetIssueStats(db.DefaultContext, &issues_model.IssuesOptions{IssueIDs: ids}) + require.NoError(t, err) + + assert.Equal(t, int64(4), stats.OpenCount) + assert.Equal(t, int64(1), stats.ClosedCount) + assert.Equal(t, int64(0), stats.YourRepositoriesCount) + assert.Equal(t, int64(0), stats.AssignCount) + assert.Equal(t, int64(0), stats.CreateCount) + assert.Equal(t, int64(0), stats.MentionCount) + assert.Equal(t, int64(0), stats.ReviewRequestedCount) + assert.Equal(t, int64(0), stats.ReviewedCount) +} From 4c90d20c9c2af78b3f08073b4248a38dad1a6c80 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Thu, 13 Jun 2024 10:29:23 +0200 Subject: [PATCH 2/3] Add release note --- release-notes/8.0.0/fix/4124.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 release-notes/8.0.0/fix/4124.md diff --git a/release-notes/8.0.0/fix/4124.md b/release-notes/8.0.0/fix/4124.md new file mode 100644 index 000000000..47c65e2ce --- /dev/null +++ b/release-notes/8.0.0/fix/4124.md @@ -0,0 +1 @@ +Fixed bug in `GetIssueStats` From 0233ee0c0d3c6b43388f38d372bedaf4d3196b12 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Sun, 16 Jun 2024 15:59:59 +0200 Subject: [PATCH 3/3] Run make fmt --- models/issues/issue_stats_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/issue_stats_test.go b/models/issues/issue_stats_test.go index cf4a47ccc..fda75a6b4 100644 --- a/models/issues/issue_stats_test.go +++ b/models/issues/issue_stats_test.go @@ -8,8 +8,8 @@ import ( "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" - "code.gitea.io/gitea/models/unittest" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )