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
+174
-14
No files matched your search
@@ -12,7 +12,9 @@ import {
|
|||||||
createRelease,
|
createRelease,
|
||||||
createPullReview,
|
createPullReview,
|
||||||
listActionRuns,
|
listActionRuns,
|
||||||
|
listReviewComments,
|
||||||
mergePull,
|
mergePull,
|
||||||
|
replyToReviewComment,
|
||||||
updateRepo,
|
updateRepo,
|
||||||
updateUserSettings,
|
updateUserSettings,
|
||||||
} from './endpoints';
|
} from './endpoints';
|
||||||
@@ -105,4 +107,19 @@ describe('endpoint request bodies', () => {
|
|||||||
expect(url).toContain('status=success');
|
expect(url).toContain('status=success');
|
||||||
expect(url).toContain('branch=main');
|
expect(url).toContain('branch=main');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('lists inline review comments and posts replies', async () => {
|
||||||
|
const { fetchImpl, client } = capture();
|
||||||
|
await listReviewComments(client, 'octo', 'repo', 7, 42);
|
||||||
|
expect(fetchImpl.mock.calls[0][0]).toBe(
|
||||||
|
'https://codeberg.org/api/v1/repos/octo/repo/pulls/7/reviews/42/comments',
|
||||||
|
);
|
||||||
|
|
||||||
|
fetchImpl.mockClear();
|
||||||
|
await replyToReviewComment(client, 'octo', 'repo', 7, 99, 'thanks');
|
||||||
|
expect(fetchImpl.mock.calls[0][0]).toBe(
|
||||||
|
'https://codeberg.org/api/v1/repos/octo/repo/pulls/7/comments/99/replies',
|
||||||
|
);
|
||||||
|
expect(postedBody(fetchImpl)).toMatchObject({ body: 'thanks' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -550,6 +550,36 @@ export function fetchActionJobLogs(
|
|||||||
return client.getText(`${repoPath(owner, repo)}/actions/jobs/${jobId}/logs`, options);
|
return client.getText(`${repoPath(owner, repo)}/actions/jobs/${jobId}/logs`, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rerunActionRun(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
run: number,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<void> {
|
||||||
|
return client.post<void>(`${repoPath(owner, repo)}/actions/runs/${run}/rerun`, undefined, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cancelActionRun(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
run: number,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<void> {
|
||||||
|
return client.post<void>(`${repoPath(owner, repo)}/actions/runs/${run}/cancel`, undefined, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deletePackage(
|
||||||
|
client: GiteaClient,
|
||||||
|
owner: string,
|
||||||
|
type: string,
|
||||||
|
name: string,
|
||||||
|
options?: RequestOptions,
|
||||||
|
): Promise<void> {
|
||||||
|
return client.delete<void>(`/packages/${enc(owner)}/${enc(type)}/${enc(name)}`, options);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Organizations, packages, user credentials
|
// Organizations, packages, user credentials
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -67,11 +67,14 @@ export const queryKeys = {
|
|||||||
[...queryKeys.repo(accountId, owner, name), 'keys'] as const,
|
[...queryKeys.repo(accountId, owner, name), 'keys'] as const,
|
||||||
|
|
||||||
// --- actions -------------------------------------------------------------
|
// --- actions -------------------------------------------------------------
|
||||||
|
actionsRoot: (accountId: string, owner: string, name: string) =>
|
||||||
|
[...queryKeys.repo(accountId, owner, name), 'actions'] as const,
|
||||||
|
|
||||||
actionsWorkflows: (accountId: string, owner: string, name: string) =>
|
actionsWorkflows: (accountId: string, owner: string, name: string) =>
|
||||||
[...queryKeys.repo(accountId, owner, name), 'actions', 'workflows'] as const,
|
[...queryKeys.actionsRoot(accountId, owner, name), 'workflows'] as const,
|
||||||
|
|
||||||
actionsRuns: (accountId: string, owner: string, name: string, params: Record<string, unknown>) =>
|
actionsRuns: (accountId: string, owner: string, name: string, params: Record<string, unknown>) =>
|
||||||
[...queryKeys.repo(accountId, owner, name), 'actions', 'runs', params] as const,
|
[...queryKeys.actionsRoot(accountId, owner, name), 'runs', params] as const,
|
||||||
|
|
||||||
actionRun: (accountId: string, owner: string, name: string, id: number) =>
|
actionRun: (accountId: string, owner: string, name: string, id: number) =>
|
||||||
[...queryKeys.repo(accountId, owner, name), 'actions', 'run', id] as const,
|
[...queryKeys.repo(accountId, owner, name), 'actions', 'run', id] as const,
|
||||||
|
|||||||
@@ -3,17 +3,21 @@
|
|||||||
import {
|
import {
|
||||||
keepPreviousData,
|
keepPreviousData,
|
||||||
useInfiniteQuery,
|
useInfiniteQuery,
|
||||||
|
useMutation,
|
||||||
useQuery,
|
useQuery,
|
||||||
|
useQueryClient,
|
||||||
type InfiniteData,
|
type InfiniteData,
|
||||||
} from '@tanstack/react-query';
|
} from '@tanstack/react-query';
|
||||||
|
|
||||||
import type { RawResponse } from '@/core/api/client';
|
import type { RawResponse } from '@/core/api/client';
|
||||||
import {
|
import {
|
||||||
|
cancelActionRun,
|
||||||
fetchActionJobLogs,
|
fetchActionJobLogs,
|
||||||
fetchActionRun,
|
fetchActionRun,
|
||||||
listActionRunJobs,
|
listActionRunJobs,
|
||||||
listActionRuns,
|
listActionRuns,
|
||||||
listWorkflows,
|
listWorkflows,
|
||||||
|
rerunActionRun,
|
||||||
type ListActionRunsParams,
|
type ListActionRunsParams,
|
||||||
} from '@/core/api/endpoints';
|
} from '@/core/api/endpoints';
|
||||||
import { queryKeys } from '@/core/api/query-keys';
|
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) {
|
export function useActionJobLogs(owner: string, name: string, jobId: number, enabled = true) {
|
||||||
const { client, account } = useSession();
|
const { client, account } = useSession();
|
||||||
const accountId = account?.id ?? '';
|
const accountId = account?.id ?? '';
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteD
|
|||||||
import type { RawResponse } from '@/core/api/client';
|
import type { RawResponse } from '@/core/api/client';
|
||||||
import {
|
import {
|
||||||
createOrg,
|
createOrg,
|
||||||
|
deletePackage,
|
||||||
fetchUserSettings,
|
fetchUserSettings,
|
||||||
listOrgRepos,
|
listOrgRepos,
|
||||||
listPackages,
|
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 { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { QueryList } from '@/components/layout/query-list';
|
import { QueryList } from '@/components/layout/query-list';
|
||||||
import { AppText } from '@/components/ui/app-text';
|
import { AppText } from '@/components/ui/app-text';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { IconButton } from '@/components/ui/icon-button';
|
||||||
import { EmptyState } from '@/components/ui/state-views';
|
import { EmptyState } from '@/components/ui/state-views';
|
||||||
|
import { apiErrorMessage } from '@/core/api/error-text';
|
||||||
import type { Package } from '@/core/api/types';
|
import type { Package } from '@/core/api/types';
|
||||||
import { flattenPages } from '@/core/utils/infinite';
|
import { flattenPages } from '@/core/utils/infinite';
|
||||||
import { formatRelativeTime } from '@/core/utils/format';
|
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 { useSession } from '@/features/accounts/use-session';
|
||||||
import { spacing } from '@/theme/tokens';
|
import { spacing } from '@/theme/tokens';
|
||||||
|
|
||||||
@@ -16,9 +18,26 @@ import { spacing } from '@/theme/tokens';
|
|||||||
export function PackagesScreen() {
|
export function PackagesScreen() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { account } = useSession();
|
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 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 (
|
return (
|
||||||
<QueryList<Package>
|
<QueryList<Package>
|
||||||
query={query}
|
query={query}
|
||||||
@@ -44,6 +63,11 @@ export function PackagesScreen() {
|
|||||||
) : null}
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
<IconButton
|
||||||
|
name="trash"
|
||||||
|
onPress={() => confirmDelete(pkg)}
|
||||||
|
accessibilityLabel={t('common.delete')}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
empty={<EmptyState icon="package" title={t('packages.empty')} />}
|
empty={<EmptyState icon="package" title={t('packages.empty')} />}
|
||||||
@@ -52,7 +76,13 @@ export function PackagesScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
row: { paddingHorizontal: spacing.lg, paddingVertical: spacing.md },
|
row: {
|
||||||
body: { gap: spacing.xs },
|
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' },
|
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
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 { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Screen } from '@/components/layout/screen';
|
import { Screen } from '@/components/layout/screen';
|
||||||
@@ -15,10 +15,11 @@ import { formatDateTime } from '@/core/utils/format';
|
|||||||
import {
|
import {
|
||||||
useActionJobLogs,
|
useActionJobLogs,
|
||||||
useActionRun,
|
useActionRun,
|
||||||
|
useActionRunControl,
|
||||||
useActionRunJobs,
|
useActionRunJobs,
|
||||||
} from '@/features/actions/queries';
|
} from '@/features/actions/queries';
|
||||||
import { useTheme } from '@/theme/theme-provider';
|
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 { RepositoryStackParamList } from '@/navigation/types';
|
||||||
import type { ScreenProps } from '@/navigation/typing';
|
import type { ScreenProps } from '@/navigation/typing';
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ export function ActionRunDetailScreen({ route }: Props) {
|
|||||||
|
|
||||||
const runQuery = useActionRun(owner, name, id);
|
const runQuery = useActionRun(owner, name, id);
|
||||||
const jobsQuery = useActionRunJobs(owner, name, id);
|
const jobsQuery = useActionRunJobs(owner, name, id);
|
||||||
|
const control = useActionRunControl(owner, name, id);
|
||||||
|
|
||||||
if (runQuery.isPending) return <LoadingView />;
|
if (runQuery.isPending) return <LoadingView />;
|
||||||
if (runQuery.isError) {
|
if (runQuery.isError) {
|
||||||
@@ -56,6 +58,10 @@ export function ActionRunDetailScreen({ route }: Props) {
|
|||||||
const run = runQuery.data;
|
const run = runQuery.data;
|
||||||
const jobs: ActionRunJob[] = jobsQuery.data ?? [];
|
const jobs: ActionRunJob[] = jobsQuery.data ?? [];
|
||||||
const state = run?.conclusion || run?.status || '';
|
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 (
|
return (
|
||||||
<Screen scroll padded>
|
<Screen scroll padded>
|
||||||
@@ -74,14 +80,37 @@ export function ActionRunDetailScreen({ route }: Props) {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.actions}>
|
||||||
{run?.html_url ? (
|
{run?.html_url ? (
|
||||||
<Button
|
<Button
|
||||||
label={t('actions.openRun')}
|
label={t('actions.openRun')}
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
size="md"
|
||||||
iconLeft="externalLink"
|
iconLeft="externalLink"
|
||||||
onPress={() => void Linking.openURL(run.html_url as string).catch(() => undefined)}
|
onPress={() => void Linking.openURL(run.html_url as string).catch(() => undefined)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : 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>
|
<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({
|
const styles = StyleSheet.create({
|
||||||
titleBlock: { gap: spacing.sm },
|
titleBlock: { gap: spacing.sm },
|
||||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||||
|
actions: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
|
||||||
logs: {
|
logs: {
|
||||||
paddingHorizontal: spacing.md,
|
paddingHorizontal: spacing.md,
|
||||||
paddingBottom: spacing.md,
|
paddingBottom: spacing.md,
|
||||||
maxHeight: 320,
|
maxHeight: 320,
|
||||||
},
|
},
|
||||||
logText: { fontFamily: fontFamily.mono, fontSize: fontSize.xs },
|
|
||||||
});
|
});
|
||||||
@@ -366,7 +366,9 @@
|
|||||||
"hideLogs": "Hide",
|
"hideLogs": "Hide",
|
||||||
"loadingLogs": "Loading logs…",
|
"loadingLogs": "Loading logs…",
|
||||||
"logsUnavailable": "Logs are not available here — open the run in the browser.",
|
"logsUnavailable": "Logs are not available here — open the run in the browser.",
|
||||||
"emptyLogs": "No log output."
|
"emptyLogs": "No log output.",
|
||||||
|
"rerun": "Re-run",
|
||||||
|
"cancel": "Cancel run"
|
||||||
},
|
},
|
||||||
"repoSettings": {
|
"repoSettings": {
|
||||||
"title": "Repository settings",
|
"title": "Repository settings",
|
||||||
@@ -452,7 +454,9 @@
|
|||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"title": "Packages",
|
"title": "Packages",
|
||||||
"empty": "No packages"
|
"empty": "No packages",
|
||||||
|
"deleteTitle": "Delete package?",
|
||||||
|
"deleteBody": "All versions of {{name}} will be deleted."
|
||||||
},
|
},
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"title": "Credentials",
|
"title": "Credentials",
|
||||||
|
|||||||
@@ -366,7 +366,9 @@
|
|||||||
"hideLogs": "Verbergen",
|
"hideLogs": "Verbergen",
|
||||||
"loadingLogs": "Logs laden…",
|
"loadingLogs": "Logs laden…",
|
||||||
"logsUnavailable": "Logs zijn hier niet beschikbaar — open de run in de browser.",
|
"logsUnavailable": "Logs zijn hier niet beschikbaar — open de run in de browser.",
|
||||||
"emptyLogs": "Geen logregels."
|
"emptyLogs": "Geen logregels.",
|
||||||
|
"rerun": "Opnieuw uitvoeren",
|
||||||
|
"cancel": "Run annuleren"
|
||||||
},
|
},
|
||||||
"repoSettings": {
|
"repoSettings": {
|
||||||
"title": "Repository-instellingen",
|
"title": "Repository-instellingen",
|
||||||
@@ -452,7 +454,9 @@
|
|||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"title": "Packages",
|
"title": "Packages",
|
||||||
"empty": "Geen packages"
|
"empty": "Geen packages",
|
||||||
|
"deleteTitle": "Package verwijderen?",
|
||||||
|
"deleteBody": "Alle versies van {{name}} worden verwijderd."
|
||||||
},
|
},
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"title": "Inloggegevens",
|
"title": "Inloggegevens",
|
||||||
|
|||||||
Reference in new issue
Block a user