diff --git a/src/components/git/review-comments.tsx b/src/components/git/review-comments.tsx new file mode 100644 index 0000000..c0eea5c --- /dev/null +++ b/src/components/git/review-comments.tsx @@ -0,0 +1,61 @@ +import { StyleSheet, View } from 'react-native'; +import { useTranslation } from 'react-i18next'; + +import { AppText } from '@/components/ui/app-text'; +import { Avatar } from '@/components/ui/avatar'; +import { useTheme } from '@/theme/theme-provider'; +import { fontFamily, spacing } from '@/theme/tokens'; +import { useReviewComments } from '@/features/issues/queries'; + +export interface ReviewCommentsProps { + owner: string; + name: string; + index: number; + reviewId: number; + baseUrl?: string; +} + +/** Inline (line-level) comments attached to a single review. */ +export function ReviewComments({ owner, name, index, reviewId }: ReviewCommentsProps) { + const { t } = useTranslation(); + const { colors } = useTheme(); + const query = useReviewComments(owner, name, index, reviewId); + const comments = query.data ?? []; + + if (comments.length === 0) return null; + + return ( + + {comments.map((comment) => ( + + + + + {comment.user?.login ?? t('common.unknown')} + + {comment.path ? ( + + {comment.path} + {comment.position ? `:${comment.position}` : ''} + + ) : null} + + {comment.body ? ( + + {comment.body} + + ) : null} + + ))} + + ); +} + +const styles = StyleSheet.create({ + container: { gap: spacing.md, marginTop: spacing.sm }, + item: { borderLeftWidth: 2, paddingLeft: spacing.md, gap: spacing.xs }, + header: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm }, + login: { fontWeight: '600' }, + path: { flexShrink: 1, fontFamily: fontFamily.mono }, + body: { fontSize: 14 }, +}); diff --git a/src/core/api/endpoints.ts b/src/core/api/endpoints.ts index 8a318d8..b937b19 100644 --- a/src/core/api/endpoints.ts +++ b/src/core/api/endpoints.ts @@ -36,6 +36,7 @@ import type { PublicKey, PullRequest, PullReview, + PullReviewComment, Release, Repository, ReviewEvent, @@ -1117,6 +1118,38 @@ export function listPullReviews( }); } +/** Inline comments attached to a specific review. */ +export function listReviewComments( + client: GiteaClient, + owner: string, + repo: string, + index: number, + reviewId: number, + options?: RequestOptions, +): Promise { + return client.get( + `${repoPath(owner, repo)}/pulls/${index}/reviews/${reviewId}/comments`, + options, + ); +} + +/** Reply to an inline review comment. */ +export function replyToReviewComment( + client: GiteaClient, + owner: string, + repo: string, + index: number, + commentId: number, + body: string, + options?: RequestOptions, +): Promise { + return client.post( + `${repoPath(owner, repo)}/pulls/${index}/comments/${commentId}/replies`, + { body }, + options, + ); +} + export interface CreateReviewInput { event: ReviewEvent; body?: string; diff --git a/src/core/api/query-keys.ts b/src/core/api/query-keys.ts index 67fc58a..0e5cbef 100644 --- a/src/core/api/query-keys.ts +++ b/src/core/api/query-keys.ts @@ -180,6 +180,14 @@ export const queryKeys = { pullReviews: (accountId: string, owner: string, name: string, index: number) => [...queryKeys.pull(accountId, owner, name, index), 'reviews'] as const, + pullReviewComments: ( + accountId: string, + owner: string, + name: string, + index: number, + reviewId: number, + ) => [...queryKeys.pullReviews(accountId, owner, name, index), reviewId, 'comments'] as const, + combinedStatus: (accountId: string, owner: string, name: string, ref: string) => [...queryKeys.repo(accountId, owner, name), 'status', ref] as const, diff --git a/src/core/api/types.ts b/src/core/api/types.ts index e7df63f..6bf08ef 100644 --- a/src/core/api/types.ts +++ b/src/core/api/types.ts @@ -626,6 +626,23 @@ export interface PullReview { html_url?: string; } +/** An inline (line-level) review comment. */ +export interface PullReviewComment { + id?: number; + body?: string; + path?: string; + position?: number; + original_position?: number; + diff_hunk?: string; + commit_id?: string; + pull_request_review_id?: number; + pull_request_url?: string; + user?: User; + created_at?: string; + updated_at?: string; + html_url?: string; +} + export type CommitStatusState = 'pending' | 'success' | 'error' | 'failure' | 'warning' | 'skipped'; /** A single CI status (Gitea Actions or an external checker). */ diff --git a/src/features/issues/queries.ts b/src/features/issues/queries.ts index 40c586f..0c95221 100644 --- a/src/features/issues/queries.ts +++ b/src/features/issues/queries.ts @@ -35,7 +35,9 @@ import { listRepoIssues, listRepoLabels, listPulls, + listReviewComments, mergePull, + replyToReviewComment, searchIssues, updateIssue, updateIssueComment, @@ -56,6 +58,7 @@ import type { Milestone, PullRequest, PullReview, + PullReviewComment, User, } from '@/core/api/types'; import { useSession } from '@/features/accounts/use-session'; @@ -392,6 +395,38 @@ export function usePullReviews(owner: string, name: string, index: number) { }); } +export function useReviewComments( + owner: string, + name: string, + index: number, + reviewId: number, + enabled = true, +) { + const { client, account } = useSession(); + const accountId = account?.id ?? ''; + + return useQuery({ + queryKey: queryKeys.pullReviewComments(accountId, owner, name, index, reviewId), + enabled: Boolean(client) && Boolean(accountId) && enabled && reviewId > 0, + queryFn: ({ signal }) => listReviewComments(client!, owner, name, index, reviewId, { signal }), + staleTime: 60_000, + }); +} + +export function useReplyReviewComment(owner: string, name: string, index: number) { + const { client, account } = useSession(); + const queryClient = useQueryClient(); + const accountId = account?.id ?? ''; + + return useMutation({ + mutationFn: ({ commentId, body }: { commentId: number; body: string }) => + replyToReviewComment(client!, owner, name, index, commentId, body), + onSuccess: () => { + void queryClient.invalidateQueries({ queryKey: queryKeys.pull(accountId, owner, name, index) }); + }, + }); +} + export function useCreatePullReview(owner: string, name: string, index: number) { const { client, account } = useSession(); const queryClient = useQueryClient(); diff --git a/src/features/repository/screens/pull-detail-screen.tsx b/src/features/repository/screens/pull-detail-screen.tsx index f897d9b..48d82d4 100644 --- a/src/features/repository/screens/pull-detail-screen.tsx +++ b/src/features/repository/screens/pull-detail-screen.tsx @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'; import { CommentItem } from '@/components/git/comment'; import { CommentComposer } from '@/components/git/comment-composer'; import { Markdown } from '@/components/git/markdown'; +import { ReviewComments } from '@/components/git/review-comments'; import { StatusChecks } from '@/components/git/status-checks'; import { Screen } from '@/components/layout/screen'; import { AppText } from '@/components/ui/app-text'; @@ -272,6 +273,15 @@ export function PullDetailScreen({ navigation, route }: Props) { {review.body && review.body.trim().length > 0 ? ( ) : null} + {review.id && (review.comments_count ?? 0) > 0 ? ( + + ) : null} ))}