feat(phase3): comments, issue compose, PR diff viewer, reviews, merge, checks

- API: comments CRUD, create/edit issue, milestones, collaborators, pull files,
  raw unified diff (getText), reviews, merge, combined commit status
- hooks: comment thread + composer mutations, issue compose mutations,
  pull files/diff/reviews, create review, merge, combined status
- UI: TextArea, ChipSelect, CommentItem, CommentComposer, native DiffView
  (parseDiff), StatusChecks
- screens: IssueCompose (create/edit), PullFiles, PullDiff, PullReview; issue
  detail gains thread + close/reopen; PR detail gains reviews, merge, files,
  checks; commit detail shows checks
- navigation/types + i18n (en/nl) updated; centralized safeHost helper
- tests: diff parser, endpoint body shapes (merge capitalisation), client getText
This commit is contained in:
JustZoe101 committed 2026-10-09 17:02:08 +02:00
1 parent f641238b6f
commit ddd834b7ac
32 files changed
+2546 -68

No files matched your search

@@ -1,17 +1,33 @@
import { StyleSheet, View } from 'react-native';
import { Alert, StyleSheet, View } from 'react-native';
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 { StatusChecks } from '@/components/git/status-checks';
import { Screen } from '@/components/layout/screen';
import { AppText } from '@/components/ui/app-text';
import { Avatar } from '@/components/ui/avatar';
import { Badge, StatusBadge } from '@/components/ui/badge';
import { Badge, type BadgeTone, StatusBadge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card } from '@/components/ui/card';
import { LabelChip } from '@/components/ui/label-chip';
import { ErrorState, LoadingView } from '@/components/ui/state-views';
import { apiErrorMessage } from '@/core/api/error-text';
import { safeHost } from '@/core/api/instance-url';
import type { Comment, PullReview } from '@/core/api/types';
import { flattenPages } from '@/core/utils/infinite';
import { useSession } from '@/features/accounts/use-session';
import { usePull } from '@/features/issues/queries';
import {
useCombinedStatus,
useCreateIssueComment,
useDeleteIssueComment,
useIssueComments,
useMergePull,
usePull,
usePullReviews,
useUpdateIssueComment,
} from '@/features/issues/queries';
import { formatRelativeTime } from '@/core/utils/format';
import { spacing } from '@/theme/tokens';
import type { RepositoryStackParamList } from '@/navigation/types';
@@ -19,14 +35,41 @@ import type { ScreenProps } from '@/navigation/typing';
type Props = ScreenProps<RepositoryStackParamList, 'PullDetail'>;
/** Full pull request view: state, branches, reviewers, stats and body. */
export function PullDetailScreen({ route }: Props) {
const REVIEW_TONE: Record<string, BadgeTone> = {
APPROVED: 'success',
REQUEST_CHANGES: 'error',
COMMENT: 'neutral',
PENDING: 'warning',
};
function reviewKey(state: string | undefined): string {
switch (state) {
case 'APPROVED':
return 'pulls.reviewStateApproved';
case 'REQUEST_CHANGES':
return 'pulls.reviewStateChanges';
case 'COMMENT':
return 'pulls.reviewStateComment';
default:
return 'pulls.reviewStatePending';
}
}
/** Full pull request view: state, branches, checks, reviews, comments, review/merge actions. */
export function PullDetailScreen({ navigation, route }: Props) {
const { t } = useTranslation();
const { instance } = useSession();
const { instance, account, token } = useSession();
const { owner, name, index } = route.params;
const query = usePull(owner, name, index);
const pull = query.data;
const checks = useCombinedStatus(owner, name, pull?.head?.sha);
const reviewsQuery = usePullReviews(owner, name, index);
const commentsQuery = useIssueComments(owner, name, index);
const createComment = useCreateIssueComment(owner, name, index);
const updateComment = useUpdateIssueComment(owner, name, index);
const deleteComment = useDeleteIssueComment(owner, name, index);
const merge = useMergePull(owner, name, index);
if (query.isPending) return <LoadingView />;
if (query.isError) {
@@ -56,6 +99,30 @@ export function PullDetailScreen({ route }: Props) {
draft: t('pulls.draft'),
}[state];
const host = instance ? safeHost(instance.baseUrl) : null;
const comments: Comment[] = flattenPages(commentsQuery.data);
const reviews: PullReview[] = reviewsQuery.data ?? [];
const canAct = state === 'open';
const mergeDisabled = merge.isPending || pull.mergeable === false;
const doMerge = (style: 'merge' | 'squash' | 'rebase') => {
merge.mutate(
{ style, deleteBranchAfterMerge: false },
{
onSuccess: () => Alert.alert(t('pulls.mergeSuccessTitle'), t('pulls.mergeSuccessBody')),
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
},
);
};
const confirmMerge = () => {
Alert.alert(t('pulls.mergeConfirmTitle'), t('pulls.mergeConfirmBody'), [
{ text: t('common.cancel'), style: 'cancel' },
{ text: t('pulls.mergeSquash'), onPress: () => doMerge('squash') },
{ text: t('pulls.mergeCreate'), onPress: () => doMerge('merge') },
]);
};
return (
<Screen scroll padded>
<View style={styles.titleBlock}>
@@ -76,10 +143,72 @@ export function PullDetailScreen({ route }: Props) {
</AppText>
</View>
{/* Checks */}
{checks.data ? <StatusChecks status={checks.data} /> : null}
{/* Actions */}
<View style={styles.actionRow}>
<Button
label={t('pulls.files', { count: pull.changed_files ?? 0 })}
variant="secondary"
size="md"
iconLeft="file"
onPress={() => navigation.navigate('PullFiles', { owner, name, index })}
/>
{canAct ? (
<>
<Button
label={t('pulls.approve')}
variant="secondary"
size="md"
iconLeft="check"
onPress={() =>
navigation.navigate('PullReview', { owner, name, index, event: 'APPROVE' })
}
/>
<Button
label={t('pulls.requestChanges')}
variant="secondary"
size="md"
iconLeft="close"
onPress={() =>
navigation.navigate('PullReview', { owner, name, index, event: 'REQUEST_CHANGES' })
}
/>
<Button
label={t('pulls.comment')}
variant="secondary"
size="md"
iconLeft="mail"
onPress={() =>
navigation.navigate('PullReview', { owner, name, index, event: 'COMMENT' })
}
/>
<Button
label={t('pulls.merge')}
size="md"
iconLeft="pullRequest"
loading={merge.isPending}
disabled={mergeDisabled}
onPress={confirmMerge}
/>
</>
) : null}
</View>
{pull.mergeable === false && canAct ? (
<AppText variant="caption" tone="warning">
{t('pulls.notMergeable')}
</AppText>
) : null}
{pull.labels && pull.labels.length > 0 ? (
<View style={styles.labels}>
{pull.labels.map((label, labelIndex) => (
<LabelChip key={label.id ?? `${label.name}-${labelIndex}`} name={label.name} color={label.color} />
<LabelChip
key={label.id ?? `${label.name}-${labelIndex}`}
name={label.name}
color={label.color}
/>
))}
</View>
) : null}
@@ -101,7 +230,7 @@ export function PullDetailScreen({ route }: Props) {
{t('pulls.changedFiles', { count: pull.changed_files ?? 0 })}
</AppText>
<AppText variant="caption" tone="tertiary">
{t('issues.comments', { count: pull.comments ?? 0 })}
{t('issues.comments', { count: pull.comments ?? comments.length })}
</AppText>
</View>
@@ -122,6 +251,71 @@ export function PullDetailScreen({ route }: Props) {
</View>
</View>
) : null}
{/* Reviews */}
{reviews.length > 0 ? (
<>
<AppText variant="subheading" style={styles.sectionTitle}>
{t('pulls.reviews')}
</AppText>
{reviews.map((review, reviewIndex) => (
<Card key={review.id ?? reviewIndex}>
<View style={styles.reviewHeader}>
<Avatar url={review.user?.avatar_url} name={review.user?.login ?? '?'} size={24} />
<AppText variant="bodyMedium" style={styles.reviewerName} numberOfLines={1}>
{review.user?.login ?? t('common.unknown')}
</AppText>
<Badge tone={REVIEW_TONE[review.state ?? 'PENDING'] ?? 'neutral'}>
{t(reviewKey(review.state))}
</Badge>
</View>
{review.body && review.body.trim().length > 0 ? (
<Markdown content={review.body} baseUrl={instance?.baseUrl} />
) : null}
</Card>
))}
</>
) : null}
{/* Comments */}
<AppText variant="subheading" style={styles.sectionTitle}>
{t('comments.title')}
</AppText>
{commentsQuery.isPending ? (
<LoadingView label={t('comments.loading')} />
) : comments.length === 0 ? (
<AppText variant="secondary" tone="tertiary">
{t('comments.empty')}
</AppText>
) : (
comments.map((comment) => {
const isOwn = Boolean(account?.login && comment.user?.login === account.login);
const commentId = comment.id;
return (
<CommentItem
key={commentId}
comment={comment}
baseUrl={instance?.baseUrl}
token={token}
host={host}
isOwn={isOwn}
updating={updateComment.isPending}
onUpdate={
commentId
? (body) => updateComment.mutateAsync({ id: commentId, body })
: undefined
}
onDelete={commentId ? () => deleteComment.mutateAsync(commentId) : undefined}
/>
);
})
)}
<CommentComposer
onSubmit={(body) => createComment.mutateAsync(body)}
pending={createComment.isPending}
errorMessage={createComment.isError ? apiErrorMessage(createComment.error, t) : null}
/>
</Screen>
);
}
@@ -129,10 +323,14 @@ export function PullDetailScreen({ route }: Props) {
const styles = StyleSheet.create({
titleBlock: { gap: spacing.sm },
stateRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
actionRow: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
labels: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
bodyCard: { minHeight: 80 },
stats: { flexDirection: 'row', alignItems: 'center', gap: spacing.md, flexWrap: 'wrap' },
reviewers: { gap: spacing.sm },
reviewerRow: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.lg },
reviewer: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
reviewHeader: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
reviewerName: { flexShrink: 1, flex: 1, fontWeight: '600' },
sectionTitle: { marginTop: spacing.md },
});