Some checks failed
Build and Release / Create Release (push) Has been skipped
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 1m41s
Build and Release / Lint (push) Failing after 2m0s
Build and Release / Build Binaries (amd64, darwin) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux) (push) Has been skipped
Build and Release / Build Binaries (amd64, windows) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 2m1s
- Rename OrgOverviewStats fields to match template expectations - Add TotalStars field to show aggregate star count - Add CountOrgRepoStars function to repo model - Fix API struct and handler to use new field names 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package org
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/organization"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
)
|
|
|
|
// GetOrgPinnedReposWithDetails returns all pinned repos with repo and group details loaded
|
|
func GetOrgPinnedReposWithDetails(ctx context.Context, orgID int64) ([]*organization.OrgPinnedRepo, error) {
|
|
pinnedRepos, err := organization.GetOrgPinnedRepos(ctx, orgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(pinnedRepos) == 0 {
|
|
return pinnedRepos, nil
|
|
}
|
|
|
|
// Load repos
|
|
repoIDs := make([]int64, len(pinnedRepos))
|
|
for i, p := range pinnedRepos {
|
|
repoIDs[i] = p.RepoID
|
|
}
|
|
|
|
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Load groups
|
|
if err := organization.LoadPinnedRepoGroups(ctx, pinnedRepos, orgID); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Attach repos
|
|
for _, p := range pinnedRepos {
|
|
p.Repo = repos[p.RepoID]
|
|
}
|
|
|
|
return pinnedRepos, nil
|
|
}
|
|
|
|
// GetOrgOverviewStats returns statistics for the organization overview page
|
|
func GetOrgOverviewStats(ctx context.Context, orgID int64) (*organization.OrgOverviewStats, error) {
|
|
stats := &organization.OrgOverviewStats{}
|
|
|
|
memberCount, teamCount, err := organization.GetOrgMemberAndTeamCounts(ctx, orgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
stats.TotalMembers = memberCount
|
|
stats.TotalTeams = teamCount
|
|
|
|
// Repo count
|
|
stats.TotalRepos, err = repo_model.CountRepositories(ctx, repo_model.CountRepositoryOptions{
|
|
OwnerID: orgID,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Total stars across all repos
|
|
stats.TotalStars, err = repo_model.CountOrgRepoStars(ctx, orgID)
|
|
if err != nil {
|
|
// Non-fatal, just log and continue
|
|
stats.TotalStars = 0
|
|
}
|
|
|
|
return stats, nil
|
|
}
|