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:
JustZoe101 committed 2026-10-09 18:19:14 +02:00
1 parent b810292b1f
commit cd448bdd52
9 files changed
+182 -22

No files matched your search

+17
View File
@@ -12,7 +12,9 @@ import {
createRelease,
createPullReview,
listActionRuns,
listReviewComments,
mergePull,
replyToReviewComment,
updateRepo,
updateUserSettings,
} from './endpoints';
@@ -105,4 +107,19 @@ describe('endpoint request bodies', () => {
expect(url).toContain('status=success');
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' });
});
});
+30
View File
@@ -550,6 +550,36 @@ export function fetchActionJobLogs(
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
// ---------------------------------------------------------------------------
+5 -2
View File
@@ -67,11 +67,14 @@ export const queryKeys = {
[...queryKeys.repo(accountId, owner, name), 'keys'] as const,
// --- actions -------------------------------------------------------------
actionsRoot: (accountId: string, owner: string, name: string) =>
[...queryKeys.repo(accountId, owner, name), 'actions'] as const,
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>) =>
[...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) =>
[...queryKeys.repo(accountId, owner, name), 'actions', 'run', id] as const,
+29
View File
@@ -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 ?? '';
+14
View File
@@ -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 },
});
+6 -2
View File
@@ -366,7 +366,9 @@
"hideLogs": "Hide",
"loadingLogs": "Loading logs…",
"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": {
"title": "Repository settings",
@@ -452,7 +454,9 @@
},
"packages": {
"title": "Packages",
"empty": "No packages"
"empty": "No packages",
"deleteTitle": "Delete package?",
"deleteBody": "All versions of {{name}} will be deleted."
},
"credentials": {
"title": "Credentials",
+6 -2
View File
@@ -366,7 +366,9 @@
"hideLogs": "Verbergen",
"loadingLogs": "Logs laden…",
"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": {
"title": "Repository-instellingen",
@@ -452,7 +454,9 @@
},
"packages": {
"title": "Packages",
"empty": "Geen packages"
"empty": "Geen packages",
"deleteTitle": "Package verwijderen?",
"deleteBody": "Alle versies van {{name}} worden verwijderd."
},
"credentials": {
"title": "Inloggegevens",