feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
"""API endpoints for Forgejo issue operations."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
2026-05-20 01:44:31 -05:00
|
|
|
from sqlalchemy import cast, String
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
from sqlmodel import select, func
|
|
|
|
|
|
2026-05-19 20:14:16 -05:00
|
|
|
from app.api.deps import get_board_for_user_write, require_org_member
|
|
|
|
|
from app.core.auth import AuthContext, get_auth_context
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
from app.db import crud
|
|
|
|
|
from app.db.session import get_session
|
2026-05-19 04:02:04 -05:00
|
|
|
from app.models.board_repository_links import BoardRepositoryLink
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
from app.models.forgejo_issues import ForgejoIssue
|
2026-05-19 04:02:04 -05:00
|
|
|
from app.schemas.forgejo_issues import ForgejoIssueListResponse, ForgejoIssueRead, CloseIssueResponse
|
|
|
|
|
from app.services.forgejo_issue_close import close_issue_by_id, CloseIssueNotFoundError, CloseIssueAccessError, CloseIssueRemoteError
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
from app.services.organizations import OrganizationContext
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/forgejo/issues", tags=["forgejo-issues"])
|
|
|
|
|
SESSION_DEP = Depends(get_session)
|
|
|
|
|
AUTH_DEP = Depends(get_auth_context)
|
2026-05-19 20:14:16 -05:00
|
|
|
ORG_MEMBER_DEP = Depends(require_org_member)
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("", response_model=ForgejoIssueListResponse)
|
|
|
|
|
async def list_issues(
|
|
|
|
|
session: AsyncSession = SESSION_DEP,
|
2026-05-19 20:14:16 -05:00
|
|
|
ctx: OrganizationContext = ORG_MEMBER_DEP,
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
repository_id: str | None = Query(None, description="Filter by repository ID"),
|
|
|
|
|
state: str | None = Query(None, description="Filter by state (open, closed)"),
|
|
|
|
|
label: str | None = Query(None, description="Filter by label name"),
|
|
|
|
|
assignee: str | None = Query(None, description="Filter by assignee login"),
|
|
|
|
|
search: str | None = Query(None, description="Search in title and body"),
|
|
|
|
|
page: int = Query(1, ge=1, description="Page number"),
|
|
|
|
|
limit: int = Query(30, ge=1, le=100, description="Items per page"),
|
|
|
|
|
) -> ForgejoIssueListResponse:
|
|
|
|
|
"""List cached issues with optional filters."""
|
|
|
|
|
# Build query with filters
|
|
|
|
|
statement = select(ForgejoIssue).where(ForgejoIssue.organization_id == ctx.organization.id)
|
|
|
|
|
|
|
|
|
|
if repository_id:
|
|
|
|
|
try:
|
|
|
|
|
repo_uuid = UUID(repository_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail="Invalid repository_id format")
|
|
|
|
|
statement = statement.where(ForgejoIssue.repository_id == repo_uuid)
|
|
|
|
|
|
|
|
|
|
if state:
|
|
|
|
|
statement = statement.where(ForgejoIssue.state == state)
|
|
|
|
|
|
2026-05-20 01:44:31 -05:00
|
|
|
if label:
|
|
|
|
|
# Filter by label name — search within the JSON labels array cast to text
|
|
|
|
|
statement = statement.where(
|
|
|
|
|
cast(ForgejoIssue.labels, String).ilike(f"%{label}%")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if assignee:
|
|
|
|
|
# Filter by assignee login — search within the JSON assignees array cast to text
|
|
|
|
|
statement = statement.where(
|
|
|
|
|
cast(ForgejoIssue.assignees, String).ilike(f"%{assignee}%")
|
|
|
|
|
)
|
|
|
|
|
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
if search:
|
|
|
|
|
statement = statement.where(
|
|
|
|
|
(ForgejoIssue.title.ilike(f"%{search}%")) |
|
2026-05-20 01:44:31 -05:00
|
|
|
(ForgejoIssue.body_preview.ilike(f"%{search}%")) |
|
|
|
|
|
(ForgejoIssue.body.ilike(f"%{search}%"))
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Count total
|
|
|
|
|
total_statement = select(func.count()).select_from(ForgejoIssue).where(ForgejoIssue.organization_id == ctx.organization.id)
|
|
|
|
|
if repository_id:
|
|
|
|
|
try:
|
|
|
|
|
repo_uuid = UUID(repository_id)
|
|
|
|
|
total_statement = total_statement.where(ForgejoIssue.repository_id == repo_uuid)
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
if state:
|
|
|
|
|
total_statement = total_statement.where(ForgejoIssue.state == state)
|
2026-05-20 01:44:31 -05:00
|
|
|
if label:
|
|
|
|
|
total_statement = total_statement.where(
|
|
|
|
|
cast(ForgejoIssue.labels, String).ilike(f"%{label}%")
|
|
|
|
|
)
|
|
|
|
|
if assignee:
|
|
|
|
|
total_statement = total_statement.where(
|
|
|
|
|
cast(ForgejoIssue.assignees, String).ilike(f"%{assignee}%")
|
|
|
|
|
)
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
if search:
|
|
|
|
|
total_statement = total_statement.where(
|
|
|
|
|
(ForgejoIssue.title.ilike(f"%{search}%")) |
|
2026-05-20 01:44:31 -05:00
|
|
|
(ForgejoIssue.body_preview.ilike(f"%{search}%")) |
|
|
|
|
|
(ForgejoIssue.body.ilike(f"%{search}%"))
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
)
|
|
|
|
|
total_result = await session.exec(total_statement)
|
|
|
|
|
total = total_result.one()
|
|
|
|
|
|
|
|
|
|
# Pagination
|
|
|
|
|
offset = (page - 1) * limit
|
|
|
|
|
statement = statement.offset(offset).limit(limit).order_by(ForgejoIssue.forgejo_issue_number.desc())
|
|
|
|
|
|
|
|
|
|
issues = (await session.exec(statement)).all()
|
|
|
|
|
items = [ForgejoIssueRead.model_validate(issue) for issue in issues]
|
|
|
|
|
|
|
|
|
|
return ForgejoIssueListResponse(
|
|
|
|
|
items=items,
|
|
|
|
|
total=total,
|
|
|
|
|
page=page,
|
|
|
|
|
limit=limit,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/{issue_id}", response_model=ForgejoIssueRead)
|
|
|
|
|
async def get_issue(
|
|
|
|
|
issue_id: str,
|
|
|
|
|
session: AsyncSession = SESSION_DEP,
|
2026-05-19 20:14:16 -05:00
|
|
|
ctx: OrganizationContext = ORG_MEMBER_DEP,
|
feat(forgejo): add validation, cached issues, sync service, and human issue APIs (Issues 5-8); add connection and repository admin UI (Issues 3-4); fix migration graph and client bugs
Backend Issues 5-8:
- POST /forgejo/connections/{id}/validate and /repositories/{id}/validate
- ForgejoIssue model with unique constraint (repo_id, issue_number)
- IssueSyncService with pagination and upsert
- GET /forgejo/issues with filtering, search, pagination
- GET /forgejo/issues/{id} with org-scoped access
- Fixed ForgejoAPIClient /api/v1 path prefix
- Fixed get_forgejo_client async context (was async def, now regular def)
- Fixed Forgejo API response parsing (list, not dict with items)
- Fixed None-safe handling for labels/assignees
Frontend Issues 3-4:
- Connections list, new, edit pages with token masking
- Repositories list, new, edit pages with connection selector
- ForgejoConnectionForm, ForgejoConnectionsTable components
- ForgejoRepositoryForm, ForgejoRepositoriesTable components
- api-forgejo.ts client library
Migration cleanup:
- Consolidated forgejo_issues table into f5a2b3c4d5e6 migration
- Removed orphan branch migrations for already-existing tables
- Fixed migration graph to single head (f5a2b3c4d5e6)
- Stamped DB to correct revision
2026-05-19 03:10:32 -05:00
|
|
|
) -> ForgejoIssueRead:
|
|
|
|
|
"""Get one cached issue by ID."""
|
|
|
|
|
try:
|
|
|
|
|
uuid = UUID(issue_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail="Invalid issue_id format")
|
|
|
|
|
|
|
|
|
|
issue = await crud.get_by_id(session, ForgejoIssue, uuid)
|
|
|
|
|
if issue is None:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
|
|
|
|
if issue.organization_id != ctx.organization.id:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
|
|
|
|
|
|
|
|
|
return ForgejoIssueRead.model_validate(issue)
|
2026-05-19 04:02:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
|
"/{issue_id}/close",
|
|
|
|
|
response_model=CloseIssueResponse,
|
|
|
|
|
summary="Close a Forgejo issue (human user)",
|
|
|
|
|
description=(
|
|
|
|
|
"Close a Forgejo issue by its local ID. The user must have write access "
|
|
|
|
|
"to the board that the issue's repository is linked to."
|
|
|
|
|
),
|
|
|
|
|
responses={
|
|
|
|
|
status.HTTP_200_OK: {
|
|
|
|
|
"description": "Issue closed successfully",
|
|
|
|
|
"content": {
|
|
|
|
|
"application/json": {
|
|
|
|
|
"example": {
|
|
|
|
|
"success": True,
|
|
|
|
|
"issue_id": "123e4567-e89b-12d3-a456-426614174000",
|
|
|
|
|
"forgejo_issue_number": 42,
|
|
|
|
|
"state": "closed",
|
|
|
|
|
"forgejo_closed_at": "2026-05-19T03:43:00+00:00",
|
|
|
|
|
"last_synced_at": "2026-05-19T03:43:00+00:00",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
status.HTTP_404_NOT_FOUND: {
|
|
|
|
|
"description": "Issue not found or not linked to a board",
|
|
|
|
|
},
|
|
|
|
|
status.HTTP_403_FORBIDDEN: {
|
|
|
|
|
"description": "User lacks write access to the board",
|
|
|
|
|
},
|
|
|
|
|
status.HTTP_409_CONFLICT: {
|
|
|
|
|
"description": "Organization mismatch or access denied",
|
|
|
|
|
},
|
|
|
|
|
status.HTTP_502_BAD_GATEWAY: {
|
|
|
|
|
"description": "Forgejo API call failed",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
async def close_issue(
|
|
|
|
|
issue_id: str,
|
|
|
|
|
session: AsyncSession = SESSION_DEP,
|
2026-05-19 20:14:16 -05:00
|
|
|
auth: AuthContext = AUTH_DEP,
|
|
|
|
|
ctx: OrganizationContext = ORG_MEMBER_DEP,
|
2026-05-19 04:02:04 -05:00
|
|
|
) -> CloseIssueResponse:
|
|
|
|
|
"""Close a Forgejo issue as an authenticated user.
|
|
|
|
|
|
|
|
|
|
The user must have write access to the board that the issue's repository
|
|
|
|
|
is linked to. The issue must belong to a repository linked to that board.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
uuid = UUID(issue_id)
|
|
|
|
|
except ValueError:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail="Invalid issue_id format")
|
|
|
|
|
|
|
|
|
|
issue = await crud.get_by_id(session, ForgejoIssue, uuid)
|
|
|
|
|
if issue is None:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Issue not found")
|
|
|
|
|
|
|
|
|
|
# Get the board linked to this issue's repository
|
|
|
|
|
link_statement = select(BoardRepositoryLink).where(
|
|
|
|
|
BoardRepositoryLink.repository_id == issue.repository_id,
|
|
|
|
|
)
|
2026-05-19 04:16:32 -05:00
|
|
|
link = (await session.exec(link_statement)).first()
|
2026-05-19 04:02:04 -05:00
|
|
|
if link is None:
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
|
detail="Issue repository is not linked to any board",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Verify the user has write access to the board
|
2026-05-19 20:14:16 -05:00
|
|
|
await get_board_for_user_write(
|
2026-05-19 04:02:04 -05:00
|
|
|
board_id=str(link.board_id),
|
|
|
|
|
session=session,
|
2026-05-19 20:14:16 -05:00
|
|
|
auth=auth,
|
2026-05-19 04:02:04 -05:00
|
|
|
)
|
2026-05-19 20:14:16 -05:00
|
|
|
if auth.user is None:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
2026-05-19 04:02:04 -05:00
|
|
|
|
|
|
|
|
# Close the issue using the service
|
|
|
|
|
try:
|
|
|
|
|
result = await close_issue_by_id(
|
|
|
|
|
session=session,
|
|
|
|
|
issue_id=uuid,
|
2026-05-19 20:14:16 -05:00
|
|
|
actor_user_id=auth.user.id,
|
2026-05-19 04:02:04 -05:00
|
|
|
)
|
|
|
|
|
except CloseIssueNotFoundError as e:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e))
|
|
|
|
|
except CloseIssueAccessError as e:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=str(e))
|
|
|
|
|
except CloseIssueRemoteError as e:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail=str(e))
|
|
|
|
|
|
|
|
|
|
return CloseIssueResponse(
|
|
|
|
|
success=result["success"],
|
|
|
|
|
issue_id=result["issue_id"],
|
|
|
|
|
forgejo_issue_number=result["forgejo_issue_number"],
|
|
|
|
|
state=result["state"],
|
|
|
|
|
forgejo_closed_at=result.get("forgejo_closed_at"),
|
|
|
|
|
last_synced_at=result.get("last_synced_at") or "",
|
|
|
|
|
)
|