Skip to content

Commit 63f4a95

Browse files
committed
Add endpoint for accessing the aggregate per-branch limits
This is required to check on branch creation/modification within which bounds the operation may be conducted.
1 parent 8a3d16b commit 63f4a95

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/api/_util/resourcelimit.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,18 @@ async def project_available(session: AsyncSession, project: Project) -> Resource
716716
(await project_limits(project)).total - await project_allocations(session, project),
717717
await organization_available(session, await project.awaitable_attrs.organization),
718718
)
719+
720+
721+
async def project_branch_maxima(session: AsyncSession, project: Project) -> Resources:
722+
"""Minimum per-branch limit across the hierarchy (project > organization > system).
723+
724+
Returns None for any field where no per-branch limit has been configured at any level.
725+
"""
726+
organization = await project.awaitable_attrs.organization
727+
return Resources.min(
728+
Resources.min(
729+
(await project_limits(project)).per_branch,
730+
(await organization_limits(organization)).per_branch,
731+
),
732+
(await system_limits(session)).per_branch,
733+
)

src/api/organization/project/resources.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
from ....models.resources import EntityType
44
from ..._util import Forbidden, NotFound, Unauthenticated
5-
from ..._util.resourcelimit import Limits, Resources, project_allocations, project_available, project_limits
5+
from ..._util.resourcelimit import (
6+
Limits,
7+
Resources,
8+
project_allocations,
9+
project_available,
10+
project_branch_maxima,
11+
project_limits,
12+
)
613
from ...dependencies import ProjectDep, SessionDep
714

815
api = APIRouter()
@@ -49,3 +56,12 @@ async def allocations(session: SessionDep, project: ProjectDep) -> Resources:
4956
)
5057
async def available(session: SessionDep, project: ProjectDep) -> Resources:
5158
return await project_available(session, project)
59+
60+
61+
@api.get(
62+
"/branch-maxima/",
63+
name="organizations:projects:resources:branch-maxima",
64+
responses={401: Unauthenticated, 403: Forbidden, 404: NotFound},
65+
)
66+
async def branch_maxima(session: SessionDep, project: ProjectDep) -> Resources:
67+
return await project_branch_maxima(session, project)

0 commit comments

Comments
 (0)