From cd448bdd52751da72d618227f205f52ecc4405e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Kooijmans?= Date: Fri, 9 Oct 2026 18:19:14 +0200 Subject: [PATCH] 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) --- src/core/api/endpoints.test.ts | 17 +++++++ src/core/api/endpoints.ts | 30 +++++++++++ src/core/api/query-keys.ts | 7 ++- src/features/actions/queries.ts | 29 +++++++++++ src/features/profile/queries.ts | 14 +++++ .../profile/screens/packages-screen.tsx | 40 +++++++++++++-- .../screens/action-run-detail-screen.tsx | 51 +++++++++++++++---- src/i18n/locales/en.json | 8 ++- src/i18n/locales/nl.json | 8 ++- 9 files changed, 182 insertions(+), 22 deletions(-) diff --git a/src/core/api/endpoints.test.ts b/src/core/api/endpoints.test.ts index a74b42d..00ea3f6 100644 --- a/src/core/api/endpoints.test.ts +++ b/src/core/api/endpoints.test.ts @@ -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' }); + }); }); diff --git a/src/core/api/endpoints.ts b/src/core/api/endpoints.ts index b937b19..b90783b 100644 --- a/src/core/api/endpoints.ts +++ b/src/core/api/endpoints.ts @@ -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 { + return client.post(`${repoPath(owner, repo)}/actions/runs/${run}/rerun`, undefined, options); +} + +export function cancelActionRun( + client: GiteaClient, + owner: string, + repo: string, + run: number, + options?: RequestOptions, +): Promise { + return client.post(`${repoPath(owner, repo)}/actions/runs/${run}/cancel`, undefined, options); +} + +export function deletePackage( + client: GiteaClient, + owner: string, + type: string, + name: string, + options?: RequestOptions, +): Promise { + return client.delete(`/packages/${enc(owner)}/${enc(type)}/${enc(name)}`, options); +} + // --------------------------------------------------------------------------- // Organizations, packages, user credentials // --------------------------------------------------------------------------- diff --git a/src/core/api/query-keys.ts b/src/core/api/query-keys.ts index 0e5cbef..2d5109c 100644 --- a/src/core/api/query-keys.ts +++ b/src/core/api/query-keys.ts @@ -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) => - [...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, diff --git a/src/features/actions/queries.ts b/src/features/actions/queries.ts index ecd89cf..7d4f1c2 100644 --- a/src/features/actions/queries.ts +++ b/src/features/actions/queries.ts @@ -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 ?? ''; diff --git a/src/features/profile/queries.ts b/src/features/profile/queries.ts index 2a7e399..c31317f 100644 --- a/src/features/profile/queries.ts +++ b/src/features/profile/queries.ts @@ -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) }); + }, + }); +} diff --git a/src/features/profile/screens/packages-screen.tsx b/src/features/profile/screens/packages-screen.tsx index 26fc7bb..6103f59 100644 --- a/src/features/profile/screens/packages-screen.tsx +++ b/src/features/profile/screens/packages-screen.tsx @@ -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 ( query={query} @@ -44,6 +63,11 @@ export function PackagesScreen() { ) : null} + confirmDelete(pkg)} + accessibilityLabel={t('common.delete')} + /> )} 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' }, }); diff --git a/src/features/repository/screens/action-run-detail-screen.tsx b/src/features/repository/screens/action-run-detail-screen.tsx index 60adef3..1c7a431 100644 --- a/src/features/repository/screens/action-run-detail-screen.tsx +++ b/src/features/repository/screens/action-run-detail-screen.tsx @@ -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 ; 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 ( @@ -74,14 +80,37 @@ export function ActionRunDetailScreen({ route }: Props) { - {run?.html_url ? ( -