mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-22 12:57:58 +00:00
feat(links): add repository commit listing endpoint
Expose GET /links/repositories/{repo}/commits, resolving {owner}
server-side from the session's linked Forgejo identity like the sibling
branches route.
Take the ref as a query parameter instead of a path segment: branch names
contain slashes (docs/readme, feature/learn-public-links), which a single
path param cannot capture without a path converter. As a query param,
`ref` may also default to main.
Dropping the path default and declaring `repo` were both required for the
module to import: FastAPI asserts that path parameters have no defaults,
and an undeclared path param raised NameError at call time.
This commit is contained in:
parent
984b382758
commit
82d50bff59
1 changed files with 30 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Annotated, Literal
|
from typing import Annotated, Literal
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Path, status
|
from fastapi import APIRouter, Depends, HTTPException, Path, Query, status
|
||||||
from pydantic import BaseModel, EmailStr
|
from pydantic import BaseModel, EmailStr
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
@ -94,3 +94,32 @@ async def get_repository_branches(
|
||||||
app_settings, access_token, owner, repo, limit=limit, page=page
|
app_settings, access_token, owner, repo, limit=limit, page=page
|
||||||
)
|
)
|
||||||
return branches
|
return branches
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/repositories/{repo}/commits")
|
||||||
|
async def get_repository_commits(
|
||||||
|
app_settings: Annotated[AppSettings, Depends(get_app_settings)],
|
||||||
|
sess: Annotated[UserBrowserSession, Depends(get_current_session)],
|
||||||
|
access_token: Annotated[str, Depends(get_forgejo_token)],
|
||||||
|
db: Annotated[AsyncSession, Depends(get_db)],
|
||||||
|
repo: Annotated[str, Path(min_length=1, description="The name of the repository")],
|
||||||
|
ref: Annotated[str, Query(description="Branch name, commit sha, or tag")] = "main",
|
||||||
|
limit: int = 10,
|
||||||
|
page: int = 1,
|
||||||
|
):
|
||||||
|
# Derive {owner} path param from users linked identity provider server-side
|
||||||
|
stmt = select(LinkedIdentity).where(
|
||||||
|
LinkedIdentity.user_id == sess.user_id, LinkedIdentity.provider == "forgejo"
|
||||||
|
)
|
||||||
|
result = await db.execute(stmt)
|
||||||
|
identity = result.scalar_one_or_none()
|
||||||
|
if identity is None:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
detail="No linked identity for forgejo was found. Please sign-in and try again.",
|
||||||
|
)
|
||||||
|
owner = identity.provider_username
|
||||||
|
commits = await forgejo.get_commits(
|
||||||
|
app_settings, access_token, owner, repo, ref=ref, limit=limit, page=page
|
||||||
|
)
|
||||||
|
return commits
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue