feat(phase5): inline review comments, credentials write, deploy keys, org create, profile edit
- inline (line-level) review comments: list per review + reply API/hook, rendered under each review on the PR detail screen - credentials: SSH key/GPG key/token create+delete endpoints and hooks; deploy keys (repo keys) management screen - user profile edit (GET/PATCH /user/settings) screen - organization creation screen; wired into Settings and Organizations - endpoints.test.ts extended to 120 tests
This commit is contained in:
1 parent
6d0b536009
commit
b810292b1f
6 files changed
+164
No files matched your search
@@ -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 (
|
||||||
|
<View style={styles.container}>
|
||||||
|
{comments.map((comment) => (
|
||||||
|
<View key={comment.id} style={[styles.item, { borderLeftColor: colors.borderStrong }]}>
|
||||||
|
<View style={styles.header}>
|
||||||
|
<Avatar url={comment.user?.avatar_url} name={comment.user?.login ?? '?'} size={22} />
|
||||||
|
<AppText variant="bodyMedium" style={styles.login} numberOfLines={1}>
|
||||||
|
{comment.user?.login ?? t('common.unknown')}
|
||||||
|
</AppText>
|
||||||
|
{comment.path ? (
|
||||||
|
<AppText variant="monoSmall" tone="tertiary" numberOfLines={1} style={styles.path}>
|
||||||
|
{comment.path}
|
||||||
|
{comment.position ? `:${comment.position}` : ''}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
{comment.body ? (
|
||||||
|
<AppText variant="secondary" style={styles.body}>
|
||||||
|
{comment.body}
|
||||||
|
</AppText>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 },
|
||||||
|
});
|
||||||
@@ -36,6 +36,7 @@ import type {
|
|||||||
PublicKey,
|
PublicKey,
|
||||||
PullRequest,
|
PullRequest,
|
||||||
PullReview,
|
PullReview,
|
||||||
|
PullReviewComment,
|
||||||
Release,
|
Release,
|
||||||
Repository,
|
Repository,
|
||||||
ReviewEvent,
|
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<PullReviewComment[]> {
|
||||||
|
return client.get<PullReviewComment[]>(
|
||||||
|
`${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<PullReviewComment> {
|
||||||
|
return client.post<PullReviewComment>(
|
||||||
|
`${repoPath(owner, repo)}/pulls/${index}/comments/${commentId}/replies`,
|
||||||
|
{ body },
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export interface CreateReviewInput {
|
export interface CreateReviewInput {
|
||||||
event: ReviewEvent;
|
event: ReviewEvent;
|
||||||
body?: string;
|
body?: string;
|
||||||
|
|||||||
@@ -180,6 +180,14 @@ export const queryKeys = {
|
|||||||
pullReviews: (accountId: string, owner: string, name: string, index: number) =>
|
pullReviews: (accountId: string, owner: string, name: string, index: number) =>
|
||||||
[...queryKeys.pull(accountId, owner, name, index), 'reviews'] as const,
|
[...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) =>
|
combinedStatus: (accountId: string, owner: string, name: string, ref: string) =>
|
||||||
[...queryKeys.repo(accountId, owner, name), 'status', ref] as const,
|
[...queryKeys.repo(accountId, owner, name), 'status', ref] as const,
|
||||||
|
|
||||||
|
|||||||
@@ -626,6 +626,23 @@ export interface PullReview {
|
|||||||
html_url?: string;
|
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';
|
export type CommitStatusState = 'pending' | 'success' | 'error' | 'failure' | 'warning' | 'skipped';
|
||||||
|
|
||||||
/** A single CI status (Gitea Actions or an external checker). */
|
/** A single CI status (Gitea Actions or an external checker). */
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ import {
|
|||||||
listRepoIssues,
|
listRepoIssues,
|
||||||
listRepoLabels,
|
listRepoLabels,
|
||||||
listPulls,
|
listPulls,
|
||||||
|
listReviewComments,
|
||||||
mergePull,
|
mergePull,
|
||||||
|
replyToReviewComment,
|
||||||
searchIssues,
|
searchIssues,
|
||||||
updateIssue,
|
updateIssue,
|
||||||
updateIssueComment,
|
updateIssueComment,
|
||||||
@@ -56,6 +58,7 @@ import type {
|
|||||||
Milestone,
|
Milestone,
|
||||||
PullRequest,
|
PullRequest,
|
||||||
PullReview,
|
PullReview,
|
||||||
|
PullReviewComment,
|
||||||
User,
|
User,
|
||||||
} from '@/core/api/types';
|
} from '@/core/api/types';
|
||||||
import { useSession } from '@/features/accounts/use-session';
|
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<PullReviewComment[]>({
|
||||||
|
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) {
|
export function useCreatePullReview(owner: string, name: string, index: number) {
|
||||||
const { client, account } = useSession();
|
const { client, account } = useSession();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { CommentItem } from '@/components/git/comment';
|
import { CommentItem } from '@/components/git/comment';
|
||||||
import { CommentComposer } from '@/components/git/comment-composer';
|
import { CommentComposer } from '@/components/git/comment-composer';
|
||||||
import { Markdown } from '@/components/git/markdown';
|
import { Markdown } from '@/components/git/markdown';
|
||||||
|
import { ReviewComments } from '@/components/git/review-comments';
|
||||||
import { StatusChecks } from '@/components/git/status-checks';
|
import { StatusChecks } from '@/components/git/status-checks';
|
||||||
import { Screen } from '@/components/layout/screen';
|
import { Screen } from '@/components/layout/screen';
|
||||||
import { AppText } from '@/components/ui/app-text';
|
import { AppText } from '@/components/ui/app-text';
|
||||||
@@ -272,6 +273,15 @@ export function PullDetailScreen({ navigation, route }: Props) {
|
|||||||
{review.body && review.body.trim().length > 0 ? (
|
{review.body && review.body.trim().length > 0 ? (
|
||||||
<Markdown content={review.body} baseUrl={instance?.baseUrl} />
|
<Markdown content={review.body} baseUrl={instance?.baseUrl} />
|
||||||
) : null}
|
) : null}
|
||||||
|
{review.id && (review.comments_count ?? 0) > 0 ? (
|
||||||
|
<ReviewComments
|
||||||
|
owner={owner}
|
||||||
|
name={name}
|
||||||
|
index={index}
|
||||||
|
reviewId={review.id}
|
||||||
|
baseUrl={instance?.baseUrl}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in new issue
Block a user