This commit is contained in:
Lunny Xiao 2025-03-25 12:32:29 -07:00
parent 262b562391
commit 450a27bc29
2 changed files with 11 additions and 17 deletions

View File

@ -102,7 +102,7 @@ func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *rep
}
// run generation async
res, err := generateContributorStats(ctx, cache, cacheKey, repo, revision)
res, err := generateContributorStats(ctx, repo, revision)
if err != nil {
return nil, err
}
@ -112,7 +112,7 @@ func GetContributorStats(ctx context.Context, cache cache.StringCache, repo *rep
}
// getExtendedCommitStats return the list of *ExtendedCommitStats for the given revision
func getExtendedCommitStats(ctx context.Context, repoPath string, baseCommit *git.Commit, revision string /*, limit int */) ([]*ExtendedCommitStats, error) {
func getExtendedCommitStats(ctx context.Context, repoPath string, baseCommit *git.Commit) ([]*ExtendedCommitStats, error) {
stdoutReader, stdoutWriter, err := os.Pipe()
if err != nil {
return nil, err
@ -202,7 +202,7 @@ func getExtendedCommitStats(ctx context.Context, repoPath string, baseCommit *gi
return extendedCommitStats, nil
}
func generateContributorStats(ctx context.Context, cache cache.StringCache, cacheKey string, repo *repo_model.Repository, revision string) (map[string]*ContributorData, error) {
func generateContributorStats(ctx context.Context, repo *repo_model.Repository, revision string) (map[string]*ContributorData, error) {
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
@ -216,7 +216,7 @@ func generateContributorStats(ctx context.Context, cache cache.StringCache, cach
if err != nil {
return nil, err
}
extendedCommitStats, err := getExtendedCommitStats(ctx, repo.RepoPath(), baseCommit, revision)
extendedCommitStats, err := getExtendedCommitStats(ctx, repo.RepoPath(), baseCommit)
if err != nil {
return nil, err
}

View File

@ -10,8 +10,6 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
@ -21,18 +19,14 @@ func TestRepository_ContributorsGraph(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
mockCache, err := cache.NewStringCache(setting.Cache{})
data, err := generateContributorStats(t.Context(), repo, "404ref")
assert.ErrorContains(t, err, "object does not exist")
assert.Nil(t, data)
data, err = generateContributorStats(t.Context(), repo, "master")
assert.NoError(t, err)
generateContributorStats(nil, mockCache, "key", repo, "404ref")
var data map[string]*ContributorData
_, getErr := mockCache.GetJSON("key", &data)
assert.NotNil(t, getErr)
assert.ErrorContains(t, getErr.ToError(), "object does not exist")
generateContributorStats(nil, mockCache, "key2", repo, "master")
exist, _ := mockCache.GetJSON("key2", &data)
assert.True(t, exist)
assert.NotNil(t, data)
var keys []string
for k := range data {
keys = append(keys, k)