refactor(issue-sync): streamline issue closing logic and enhance error handling

This commit is contained in:
null 2026-05-22 22:20:28 -05:00
parent 1076ca27bb
commit 11d950a13a
2 changed files with 210 additions and 209 deletions

View File

@ -694,7 +694,10 @@ async def close_issue(
if auth.user is None: if auth.user is None:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
# Get boards linked to this issue's repository for this organization. # Check board links — used for authorization and activity logging.
# If the repository is not linked to any board the user can still close
# the issue (org membership is sufficient); we just skip the board-scoped
# activity event.
links = ( links = (
await session.exec( await session.exec(
select(BoardRepositoryLink).where( select(BoardRepositoryLink).where(
@ -703,12 +706,9 @@ async def close_issue(
) )
) )
).all() ).all()
if not links:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Issue repository is not linked to any board",
)
authorized_board_id: object = None
if links:
allowed_board_ids = set(await list_accessible_board_ids(session, member=ctx.member, write=True)) allowed_board_ids = set(await list_accessible_board_ids(session, member=ctx.member, write=True))
authorized_board_id = next( authorized_board_id = next(
(link.board_id for link in links if link.board_id in allowed_board_ids), (link.board_id for link in links if link.board_id in allowed_board_ids),
@ -735,6 +735,7 @@ async def close_issue(
raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail=str(e)) raise HTTPException(status_code=status.HTTP_502_BAD_GATEWAY, detail=str(e))
repository_full_name = str(result.get("repository_full_name") or "unknown/unknown") repository_full_name = str(result.get("repository_full_name") or "unknown/unknown")
if authorized_board_id is not None:
record_activity( record_activity(
session, session,
event_type="forgejo.issue.closed", event_type="forgejo.issue.closed",