feat(phase5): Actions re-run/cancel, package deletion, inline-comment tests
- action run controls (re-run / cancel) with cache invalidation - package deletion from the Packages screen - endpoint tests for inline review comments + replies (121 tests)
This commit is contained in:
1 parent
b810292b1f
commit
cd448bdd52
9 files changed
+182
-22
No files matched your search
@@ -3,17 +3,21 @@
|
||||
import {
|
||||
keepPreviousData,
|
||||
useInfiniteQuery,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
type InfiniteData,
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
cancelActionRun,
|
||||
fetchActionJobLogs,
|
||||
fetchActionRun,
|
||||
listActionRunJobs,
|
||||
listActionRuns,
|
||||
listWorkflows,
|
||||
rerunActionRun,
|
||||
type ListActionRunsParams,
|
||||
} from '@/core/api/endpoints';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
@@ -85,6 +89,31 @@ export function useActionRunJobs(owner: string, name: string, run: number) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Re-run or cancel a workflow run. */
|
||||
export function useActionRunControl(owner: string, name: string, run: number) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
const invalidate = () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.actionRun(accountId, owner, name, run) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.actionJobs(accountId, owner, name, run) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.actionsRoot(accountId, owner, name) });
|
||||
};
|
||||
|
||||
const rerun = useMutation({
|
||||
mutationFn: () => rerunActionRun(client!, owner, name, run),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const cancel = useMutation({
|
||||
mutationFn: () => cancelActionRun(client!, owner, name, run),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { rerun, cancel };
|
||||
}
|
||||
|
||||
export function useActionJobLogs(owner: string, name: string, jobId: number, enabled = true) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteD
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
createOrg,
|
||||
deletePackage,
|
||||
fetchUserSettings,
|
||||
listOrgRepos,
|
||||
listPackages,
|
||||
@@ -138,3 +139,16 @@ export function useCreateOrg() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeletePackage() {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
return useMutation({
|
||||
mutationFn: ({ owner, type, name }: { owner: string; type: string; name: string }) =>
|
||||
deletePackage(client!, owner, type, name),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
import { Alert, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { IconButton } from '@/components/ui/icon-button';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import type { Package } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { formatRelativeTime } from '@/core/utils/format';
|
||||
import { usePackages } from '@/features/profile/queries';
|
||||
import { useDeletePackage, usePackages } from '@/features/profile/queries';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
|
||||
@@ -16,9 +18,26 @@ import { spacing } from '@/theme/tokens';
|
||||
export function PackagesScreen() {
|
||||
const { t } = useTranslation();
|
||||
const { account } = useSession();
|
||||
const query = usePackages(account?.login ?? '');
|
||||
const login = account?.login ?? '';
|
||||
const query = usePackages(login);
|
||||
const deletePackage = useDeletePackage();
|
||||
const packages: Package[] = flattenPages(query.data);
|
||||
|
||||
const confirmDelete = (pkg: Package) => {
|
||||
Alert.alert(t('packages.deleteTitle'), t('packages.deleteBody', { name: pkg.name ?? '' }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.delete'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
deletePackage.mutate(
|
||||
{ owner: login, type: pkg.type ?? '', name: pkg.name ?? '' },
|
||||
{ onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)) },
|
||||
),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryList<Package>
|
||||
query={query}
|
||||
@@ -44,6 +63,11 @@ export function PackagesScreen() {
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
<IconButton
|
||||
name="trash"
|
||||
onPress={() => confirmDelete(pkg)}
|
||||
accessibilityLabel={t('common.delete')}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
empty={<EmptyState icon="package" title={t('packages.empty')} />}
|
||||
@@ -52,7 +76,13 @@ export function PackagesScreen() {
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: { paddingHorizontal: spacing.lg, paddingVertical: spacing.md },
|
||||
body: { gap: spacing.xs },
|
||||
row: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
body: { flex: 1, gap: spacing.xs },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { Linking, ScrollView, StyleSheet, View } from 'react-native';
|
||||
import { Alert, Linking, ScrollView, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
@@ -15,10 +15,11 @@ import { formatDateTime } from '@/core/utils/format';
|
||||
import {
|
||||
useActionJobLogs,
|
||||
useActionRun,
|
||||
useActionRunControl,
|
||||
useActionRunJobs,
|
||||
} from '@/features/actions/queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { fontFamily, fontSize, spacing } from '@/theme/tokens';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
@@ -40,6 +41,7 @@ export function ActionRunDetailScreen({ route }: Props) {
|
||||
|
||||
const runQuery = useActionRun(owner, name, id);
|
||||
const jobsQuery = useActionRunJobs(owner, name, id);
|
||||
const control = useActionRunControl(owner, name, id);
|
||||
|
||||
if (runQuery.isPending) return <LoadingView />;
|
||||
if (runQuery.isError) {
|
||||
@@ -56,6 +58,10 @@ export function ActionRunDetailScreen({ route }: Props) {
|
||||
const run = runQuery.data;
|
||||
const jobs: ActionRunJob[] = jobsQuery.data ?? [];
|
||||
const state = run?.conclusion || run?.status || '';
|
||||
const running = run?.status === 'running' || run?.status === 'waiting';
|
||||
const canRerun = Boolean(run) && !running;
|
||||
|
||||
const reportError = (error: unknown) => Alert.alert(t('errors.title'), apiErrorMessage(error, t));
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
@@ -74,14 +80,37 @@ export function ActionRunDetailScreen({ route }: Props) {
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{run?.html_url ? (
|
||||
<Button
|
||||
label={t('actions.openRun')}
|
||||
variant="secondary"
|
||||
iconLeft="externalLink"
|
||||
onPress={() => void Linking.openURL(run.html_url as string).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
<View style={styles.actions}>
|
||||
{run?.html_url ? (
|
||||
<Button
|
||||
label={t('actions.openRun')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft="externalLink"
|
||||
onPress={() => void Linking.openURL(run.html_url as string).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
{canRerun ? (
|
||||
<Button
|
||||
label={t('actions.rerun')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft="refresh"
|
||||
loading={control.rerun.isPending}
|
||||
onPress={() => control.rerun.mutate(undefined, { onError: reportError })}
|
||||
/>
|
||||
) : null}
|
||||
{running ? (
|
||||
<Button
|
||||
label={t('actions.cancel')}
|
||||
variant="danger"
|
||||
size="md"
|
||||
iconLeft="close"
|
||||
loading={control.cancel.isPending}
|
||||
onPress={() => control.cancel.mutate(undefined, { onError: reportError })}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
<AppText variant="subheading">{t('actions.jobs')}</AppText>
|
||||
|
||||
@@ -143,10 +172,10 @@ function JobRow({ owner, name, job }: { owner: string; name: string; job: Action
|
||||
const styles = StyleSheet.create({
|
||||
titleBlock: { gap: spacing.sm },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
actions: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
|
||||
logs: {
|
||||
paddingHorizontal: spacing.md,
|
||||
paddingBottom: spacing.md,
|
||||
maxHeight: 320,
|
||||
},
|
||||
logText: { fontFamily: fontFamily.mono, fontSize: fontSize.xs },
|
||||
});
|
||||
Reference in new issue
Block a user