feat(phase5): actions, repo settings, collaborators, webhooks, protections, orgs, packages, credentials, release management
- API: Actions (workflows/runs/jobs/logs getText), repo create/edit/delete, collaborators, webhooks, branch protections, orgs, packages, user keys/GPG keys/tokens, release create/edit/delete - hooks: features/actions, repositories/settings-queries, features/profile - screens: Actions + run detail (expandable job logs), RepoSettings, Collaborators, Webhooks, Protections, CreateRepo, Organizations, OrgRepos, Packages, Credentials, ReleaseCompose; releases list/detail management - navigation + i18n (en/nl) wired for all new screens
This commit is contained in:
1 parent
5e8c9492b3
commit
fa1ebc9184
30 files changed
+3001
-9
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/** Gitea Actions query hooks (workflows, runs, jobs, logs). */
|
||||
|
||||
import {
|
||||
keepPreviousData,
|
||||
useInfiniteQuery,
|
||||
useQuery,
|
||||
type InfiniteData,
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
fetchActionJobLogs,
|
||||
fetchActionRun,
|
||||
listActionRunJobs,
|
||||
listActionRuns,
|
||||
listWorkflows,
|
||||
type ListActionRunsParams,
|
||||
} from '@/core/api/endpoints';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
import type { ActionRun, ActionRunJob, ActionWorkflow } from '@/core/api/types';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
|
||||
export function useWorkflows(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<ActionWorkflow[]>({
|
||||
queryKey: queryKeys.actionsWorkflows(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
queryFn: ({ signal }) =>
|
||||
listWorkflows(client!, owner, name, { limit: 50 }, { signal }).then((r) => r.data),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useActionRuns(
|
||||
owner: string,
|
||||
name: string,
|
||||
filters: Pick<ListActionRunsParams, 'status' | 'branch' | 'event'> = {},
|
||||
limit = 20,
|
||||
) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
const params = { ...filters, limit };
|
||||
|
||||
return useInfiniteQuery<
|
||||
RawResponse<ActionRun[]>,
|
||||
Error,
|
||||
InfiniteData<RawResponse<ActionRun[]>>,
|
||||
readonly unknown[],
|
||||
number
|
||||
>({
|
||||
queryKey: queryKeys.actionsRuns(accountId, owner, name, params),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) =>
|
||||
listActionRuns(client!, owner, name, { ...params, page: pageParam }, { signal }),
|
||||
getNextPageParam: (last, all) => (last.hasMore ? all.length + 1 : undefined),
|
||||
placeholderData: keepPreviousData,
|
||||
});
|
||||
}
|
||||
|
||||
export function useActionRun(owner: string, name: string, id: number) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<ActionRun>({
|
||||
queryKey: queryKeys.actionRun(accountId, owner, name, id),
|
||||
enabled: Boolean(client) && Boolean(accountId) && id > 0,
|
||||
queryFn: ({ signal }) => fetchActionRun(client!, owner, name, id, { signal }),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useActionRunJobs(owner: string, name: string, run: number) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<ActionRunJob[]>({
|
||||
queryKey: queryKeys.actionJobs(accountId, owner, name, run),
|
||||
enabled: Boolean(client) && Boolean(accountId) && run > 0,
|
||||
queryFn: ({ signal }) =>
|
||||
listActionRunJobs(client!, owner, name, run, { limit: 50 }, { signal }).then((r) => r.data),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useActionJobLogs(owner: string, name: string, jobId: number, enabled = true) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<string>({
|
||||
queryKey: queryKeys.actionJobLogs(accountId, owner, name, jobId),
|
||||
enabled: Boolean(client) && Boolean(accountId) && jobId > 0 && enabled,
|
||||
queryFn: ({ signal }) => fetchActionJobLogs(client!, owner, name, jobId, { signal }),
|
||||
staleTime: 60_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/** Account-level data: organizations, packages and credential listings. */
|
||||
|
||||
import { useInfiniteQuery, type InfiniteData } from '@tanstack/react-query';
|
||||
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
listOrgRepos,
|
||||
listPackages,
|
||||
listUserGpgKeys,
|
||||
listUserKeys,
|
||||
listUserOrgs,
|
||||
listUserTokens,
|
||||
} from '@/core/api/endpoints';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
import type { AccessToken, GpgKey, Organization, Package, PublicKey, Repository } from '@/core/api/types';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
|
||||
function useAccountList<T>(
|
||||
key: readonly unknown[],
|
||||
load: (
|
||||
page: number,
|
||||
signal: AbortSignal,
|
||||
) => Promise<RawResponse<T[]>>,
|
||||
) {
|
||||
return useInfiniteQuery<
|
||||
RawResponse<T[]>,
|
||||
Error,
|
||||
InfiniteData<RawResponse<T[]>>,
|
||||
readonly unknown[],
|
||||
number
|
||||
>({
|
||||
queryKey: key,
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => load(pageParam, signal),
|
||||
getNextPageParam: (last, all) => (last.hasMore ? all.length + 1 : undefined),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUserOrgs(limit = 30) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<Organization>(
|
||||
[...queryKeys.orgs(accountId), { limit }],
|
||||
(page, signal) => listUserOrgs(client!, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
|
||||
export function useOrgRepos(org: string, limit = 20) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<Repository>(
|
||||
queryKeys.orgRepos(accountId, org, { limit }),
|
||||
(page, signal) => listOrgRepos(client!, org, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
|
||||
export function usePackages(owner: string, limit = 20) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<Package>(
|
||||
queryKeys.packages(accountId, owner, { limit }),
|
||||
(page, signal) => listPackages(client!, owner, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
|
||||
export function useUserKeys(limit = 50) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<PublicKey>(
|
||||
[...queryKeys.userKeys(accountId), { limit }],
|
||||
(page, signal) => listUserKeys(client!, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
|
||||
export function useUserGpgKeys(limit = 50) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<GpgKey>(
|
||||
[...queryKeys.userGpgKeys(accountId), { limit }],
|
||||
(page, signal) => listUserGpgKeys(client!, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
|
||||
export function useUserTokens(username: string, limit = 50) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
return useAccountList<AccessToken>(
|
||||
queryKeys.userTokens(accountId, username),
|
||||
(page, signal) => listUserTokens(client!, username, { page, limit }, { signal }),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { EmptyState, ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { formatRelativeTime } from '@/core/utils/format';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import { useUserGpgKeys, useUserKeys, useUserTokens } from '@/features/profile/queries';
|
||||
import { fontFamily, spacing } from '@/theme/tokens';
|
||||
|
||||
/** Read-only listings of the account's SSH keys, GPG keys and access tokens. */
|
||||
export function CredentialsScreen() {
|
||||
const { t } = useTranslation();
|
||||
const { account, client } = useSession();
|
||||
const keys = useUserKeys();
|
||||
const gpgKeys = useUserGpgKeys();
|
||||
const tokens = useUserTokens(account?.login ?? '');
|
||||
|
||||
if (keys.isError || gpgKeys.isError || tokens.isError) {
|
||||
const error = keys.error ?? gpgKeys.error ?? tokens.error;
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => {
|
||||
void keys.refetch();
|
||||
void gpgKeys.refetch();
|
||||
void tokens.refetch();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!client || (keys.isPending && gpgKeys.isPending && tokens.isPending)) {
|
||||
return <LoadingView />;
|
||||
}
|
||||
|
||||
const keyItems = flattenPages(keys.data);
|
||||
const gpgItems = flattenPages(gpgKeys.data);
|
||||
const tokenItems = flattenPages(tokens.data);
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Section title={t('credentials.sshKeys')}>
|
||||
{keyItems.length === 0 ? (
|
||||
<EmptyState icon="lock" title={t('credentials.noSshKeys')} />
|
||||
) : (
|
||||
keyItems.map((key) => (
|
||||
<Card key={key.id ?? key.title}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{key.title}
|
||||
</AppText>
|
||||
<AppText variant="monoSmall" tone="tertiary" numberOfLines={1}>
|
||||
{key.fingerprint ?? key.key}
|
||||
</AppText>
|
||||
{key.read_only ? <Badge tone="neutral">{t('credentials.readOnly')}</Badge> : null}
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={t('credentials.gpgKeys')}>
|
||||
{gpgItems.length === 0 ? (
|
||||
<EmptyState icon="verified" title={t('credentials.noGpgKeys')} />
|
||||
) : (
|
||||
gpgItems.map((key) => (
|
||||
<Card key={key.id ?? key.key_id}>
|
||||
<View style={styles.row}>
|
||||
<AppText variant="monoSmall" numberOfLines={1} style={styles.keyId}>
|
||||
{key.key_id}
|
||||
</AppText>
|
||||
{key.verified ? <Badge tone="success" icon="verified">{t('commits.verified')}</Badge> : null}
|
||||
</View>
|
||||
{key.emails && key.emails.length > 0 ? (
|
||||
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||
{key.emails.map((email) => email.email).filter(Boolean).join(', ')}
|
||||
</AppText>
|
||||
) : null}
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<Section title={t('credentials.tokens')}>
|
||||
{tokenItems.length === 0 ? (
|
||||
<EmptyState icon="lock" title={t('credentials.noTokens')} />
|
||||
) : (
|
||||
tokenItems.map((token) => (
|
||||
<Card key={token.id ?? token.name}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{token.name}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
<AppText variant="monoSmall" tone="tertiary">
|
||||
••••{token.token_last_eight ?? ''}
|
||||
</AppText>
|
||||
{token.last_used_at ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatRelativeTime(token.last_used_at, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
</View>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</Section>
|
||||
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('credentials.notice')}
|
||||
</AppText>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
section: { gap: spacing.sm },
|
||||
row: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||
keyId: { flex: 1, fontFamily: fontFamily.mono },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
|
||||
function Section({ title, children }: { title: string; children: ReactNode }) {
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<AppText variant="subheading">{title}</AppText>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useRoute, type RouteProp } from '@react-navigation/native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { RepoListItem } from '@/components/git/repo-list-item';
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import type { Repository } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { useOrgRepos } from '@/features/profile/queries';
|
||||
import type { SettingsStackParamList } from '@/navigation/types';
|
||||
import { useRootNavigation } from '@/navigation/use-root-navigation';
|
||||
|
||||
/** Repositories belonging to one organization. */
|
||||
export function OrgReposScreen() {
|
||||
const { t } = useTranslation();
|
||||
const route = useRoute<RouteProp<SettingsStackParamList, 'OrgRepos'>>();
|
||||
const navigation = useRootNavigation();
|
||||
const { org } = route.params;
|
||||
const query = useOrgRepos(org);
|
||||
const repos: Repository[] = flattenPages(query.data);
|
||||
|
||||
return (
|
||||
<QueryList<Repository>
|
||||
query={query}
|
||||
items={repos}
|
||||
keyExtractor={(repo) => String(repo.id)}
|
||||
renderItem={(repo) => (
|
||||
<RepoListItem
|
||||
repo={repo}
|
||||
onPress={() =>
|
||||
navigation.navigate('Repository', {
|
||||
screen: 'RepoOverview',
|
||||
params: { owner: repo.owner?.login ?? org, name: repo.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
empty={<EmptyState icon="repo" title={t('repositories.empty')} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Avatar } from '@/components/ui/avatar';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import type { Organization } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { useUserOrgs } from '@/features/profile/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { SettingsStackParamList } from '@/navigation/types';
|
||||
|
||||
/** Organizations the signed-in user belongs to. */
|
||||
export function OrganizationsScreen() {
|
||||
const { t } = useTranslation();
|
||||
const navigation = useNavigation<NativeStackNavigationProp<SettingsStackParamList>>();
|
||||
const query = useUserOrgs();
|
||||
const orgs: Organization[] = flattenPages(query.data);
|
||||
|
||||
return (
|
||||
<QueryList<Organization>
|
||||
query={query}
|
||||
items={orgs}
|
||||
keyExtractor={(org) => String(org.id ?? org.username)}
|
||||
renderItem={(org) => {
|
||||
const login = org.username ?? org.name ?? '';
|
||||
return (
|
||||
<View style={styles.row}>
|
||||
<Avatar url={org.avatar_url} name={login} size={40} />
|
||||
<View style={styles.body}>
|
||||
<AppText
|
||||
variant="bodyMedium"
|
||||
numberOfLines={1}
|
||||
onPress={() => navigation.navigate('OrgRepos', { org: login })}
|
||||
accessibilityRole="button"
|
||||
>
|
||||
{login}
|
||||
</AppText>
|
||||
{org.description ? (
|
||||
<AppText variant="caption" tone="tertiary" numberOfLines={1}>
|
||||
{org.description}
|
||||
</AppText>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
empty={<EmptyState icon="people" title={t('organizations.empty')} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
body: { flex: 1, gap: 2 },
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { 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 { EmptyState } from '@/components/ui/state-views';
|
||||
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 { useSession } from '@/features/accounts/use-session';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
|
||||
/** Packages published by the authenticated user. */
|
||||
export function PackagesScreen() {
|
||||
const { t } = useTranslation();
|
||||
const { account } = useSession();
|
||||
const query = usePackages(account?.login ?? '');
|
||||
const packages: Package[] = flattenPages(query.data);
|
||||
|
||||
return (
|
||||
<QueryList<Package>
|
||||
query={query}
|
||||
items={packages}
|
||||
keyExtractor={(pkg) => `${pkg.type ?? ''}-${pkg.name ?? ''}-${pkg.version ?? ''}`}
|
||||
renderItem={(pkg) => (
|
||||
<View style={styles.row}>
|
||||
<View style={styles.body}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{pkg.name}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
{pkg.type ? <Badge tone="neutral">{pkg.type}</Badge> : null}
|
||||
{pkg.version ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{pkg.version}
|
||||
</AppText>
|
||||
) : null}
|
||||
{pkg.created_at ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatRelativeTime(pkg.created_at, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
empty={<EmptyState icon="package" title={t('packages.empty')} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: { paddingHorizontal: spacing.lg, paddingVertical: spacing.md },
|
||||
body: { gap: spacing.xs },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -29,8 +29,12 @@ import {
|
||||
unstarRepo,
|
||||
unwatchRepo,
|
||||
watchRepo,
|
||||
createRelease,
|
||||
updateRelease,
|
||||
deleteRelease,
|
||||
type ForkRepoInput,
|
||||
type ListMyReposParams,
|
||||
type ReleaseInput,
|
||||
type SearchReposParams,
|
||||
} from '@/core/api/endpoints';
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
@@ -236,3 +240,45 @@ export function useRelease(owner: string, name: string, id: number) {
|
||||
queryFn: ({ signal }) => fetchRelease(client!, owner, name, id, { signal }),
|
||||
});
|
||||
}
|
||||
|
||||
function invalidateReleases(
|
||||
queryClient: ReturnType<typeof useQueryClient>,
|
||||
accountId: string,
|
||||
owner: string,
|
||||
name: string,
|
||||
) {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repo(accountId, owner, name) });
|
||||
}
|
||||
|
||||
export function useCreateRelease(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: ReleaseInput) => createRelease(client!, owner, name, input),
|
||||
onSuccess: () => invalidateReleases(queryClient, accountId, owner, name),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateRelease(owner: string, name: string, id: number) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: Partial<ReleaseInput>) => updateRelease(client!, owner, name, id, input),
|
||||
onSuccess: () => invalidateReleases(queryClient, accountId, owner, name),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteRelease(owner: string, name: string, id: number) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => deleteRelease(client!, owner, name, id),
|
||||
onSuccess: () => invalidateReleases(queryClient, accountId, owner, name),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { useCreateRepo } from '@/features/repositories/settings-queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoriesStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoriesStackParamList, 'CreateRepo'>;
|
||||
|
||||
/** Create a repository under the authenticated user. */
|
||||
export function CreateRepoScreen({ navigation }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const create = useCreateRepo();
|
||||
|
||||
const [name, setName] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
const [isPrivate, setIsPrivate] = useState(false);
|
||||
const [autoInit, setAutoInit] = useState(true);
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
const nameError = submitted && name.trim().length === 0 ? t('createRepo.nameRequired') : undefined;
|
||||
|
||||
const submit = () => {
|
||||
setSubmitted(true);
|
||||
if (name.trim().length === 0) return;
|
||||
create.mutate(
|
||||
{
|
||||
name: name.trim(),
|
||||
description: description.trim() || undefined,
|
||||
private: isPrivate,
|
||||
auto_init: autoInit,
|
||||
},
|
||||
{
|
||||
onSuccess: () => navigation.goBack(),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Field
|
||||
label={t('createRepo.name')}
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
placeholder={t('createRepo.namePlaceholder')}
|
||||
showError={Boolean(nameError)}
|
||||
error={nameError}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
testID="repo-name"
|
||||
/>
|
||||
<Field
|
||||
label={t('repo.description')}
|
||||
value={description}
|
||||
onChangeText={setDescription}
|
||||
autoCapitalize="sentences"
|
||||
/>
|
||||
<Card>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('repositories.private')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={isPrivate}
|
||||
onValueChange={setIsPrivate}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.switchRow}>
|
||||
<View style={styles.switchLabel}>
|
||||
<AppText variant="bodyMedium">{t('createRepo.autoInit')}</AppText>
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('createRepo.autoInitHelp')}
|
||||
</AppText>
|
||||
</View>
|
||||
<Switch
|
||||
value={autoInit}
|
||||
onValueChange={setAutoInit}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
|
||||
{create.isError ? (
|
||||
<AppText variant="caption" tone="error">
|
||||
{apiErrorMessage(create.error, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
|
||||
<Button
|
||||
label={t('createRepo.submit')}
|
||||
onPress={submit}
|
||||
loading={create.isPending}
|
||||
disabled={name.trim().length === 0}
|
||||
fullWidth
|
||||
testID="repo-create-submit"
|
||||
/>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
switchRow: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: spacing.md,
|
||||
marginTop: spacing.sm,
|
||||
},
|
||||
switchLabel: { flex: 1 },
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { RepoListItem } from '@/components/git/repo-list-item';
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SearchBar } from '@/components/ui/search-bar';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
@@ -93,6 +94,15 @@ export function RepositoryListScreen({ navigation }: Props) {
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<View style={styles.newRepo}>
|
||||
<Button
|
||||
label={t('createRepo.title')}
|
||||
variant="secondary"
|
||||
iconLeft="plus"
|
||||
fullWidth
|
||||
onPress={() => navigation.navigate('CreateRepo')}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -130,4 +140,5 @@ export function RepositoryListScreen({ navigation }: Props) {
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
filters: { gap: spacing.sm, paddingHorizontal: spacing.lg, paddingBottom: spacing.sm },
|
||||
newRepo: { paddingHorizontal: spacing.lg, paddingBottom: spacing.sm },
|
||||
});
|
||||
@@ -0,0 +1,183 @@
|
||||
/** Repository settings: edit/delete, collaborators, webhooks, branch protections. */
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import {
|
||||
addCollaborator,
|
||||
createBranchProtection,
|
||||
createRepo,
|
||||
createWebhook,
|
||||
deleteBranchProtection,
|
||||
deleteRepo,
|
||||
deleteWebhook,
|
||||
listBranchProtections,
|
||||
listCollaborators,
|
||||
listWebhooks,
|
||||
removeCollaborator,
|
||||
updateRepo,
|
||||
type CollaboratorPermission,
|
||||
type CreateBranchProtectionInput,
|
||||
type CreateRepoInput,
|
||||
type CreateWebhookInput,
|
||||
type UpdateRepoInput,
|
||||
} from '@/core/api/endpoints';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
import type { BranchProtection, User, Webhook } from '@/core/api/types';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
|
||||
export function useCollaboratorsList(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<User[]>({
|
||||
queryKey: queryKeys.repoCollaborators(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
queryFn: ({ signal }) =>
|
||||
listCollaborators(client!, owner, name, { limit: 50 }, { signal }).then((r) => r.data),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAddCollaborator(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ username, permission }: { username: string; permission: CollaboratorPermission }) =>
|
||||
addCollaborator(client!, owner, name, username, permission),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoCollaborators(accountId, owner, name) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRemoveCollaborator(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (username: string) => removeCollaborator(client!, owner, name, username),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoCollaborators(accountId, owner, name) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useWebhooks(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<Webhook[]>({
|
||||
queryKey: queryKeys.repoWebhooks(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
queryFn: ({ signal }) =>
|
||||
listWebhooks(client!, owner, name, { limit: 50 }, { signal }).then((r) => r.data),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateWebhook(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: CreateWebhookInput) => createWebhook(client!, owner, name, input),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoWebhooks(accountId, owner, name) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteWebhook(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => deleteWebhook(client!, owner, name, id),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoWebhooks(accountId, owner, name) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useBranchProtections(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<BranchProtection[]>({
|
||||
queryKey: queryKeys.repoProtections(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
queryFn: ({ signal }) =>
|
||||
listBranchProtections(client!, owner, name, { limit: 50 }, { signal }).then((r) => r.data),
|
||||
staleTime: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateBranchProtection(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: CreateBranchProtectionInput) =>
|
||||
createBranchProtection(client!, owner, name, input),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.repoProtections(accountId, owner, name),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteBranchProtection(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (rule: string) => deleteBranchProtection(client!, owner, name, rule),
|
||||
onSuccess: () =>
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.repoProtections(accountId, owner, name),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateRepo(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: UpdateRepoInput) => updateRepo(client!, owner, name, input),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoDetail(accountId, owner, name) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteRepo(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => deleteRepo(client!, owner, name),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateRepo() {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: CreateRepoInput) => createRepo(client!, input),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import { useState } from 'react';
|
||||
import { Linking, ScrollView, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Badge, type BadgeTone } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { ListItem } from '@/components/ui/list-item';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import type { ActionRunJob } from '@/core/api/types';
|
||||
import { formatDateTime } from '@/core/utils/format';
|
||||
import {
|
||||
useActionJobLogs,
|
||||
useActionRun,
|
||||
useActionRunJobs,
|
||||
} from '@/features/actions/queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { fontFamily, fontSize, spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'ActionRunDetail'>;
|
||||
|
||||
const STATUS_TONE: Record<string, BadgeTone> = {
|
||||
success: 'success',
|
||||
failure: 'error',
|
||||
cancelled: 'warning',
|
||||
skipped: 'neutral',
|
||||
running: 'info',
|
||||
waiting: 'warning',
|
||||
};
|
||||
|
||||
/** A run's jobs; each job can expand to show its log (plain text). */
|
||||
export function ActionRunDetailScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name, id } = route.params;
|
||||
|
||||
const runQuery = useActionRun(owner, name, id);
|
||||
const jobsQuery = useActionRunJobs(owner, name, id);
|
||||
|
||||
if (runQuery.isPending) return <LoadingView />;
|
||||
if (runQuery.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(runQuery.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void runQuery.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const run = runQuery.data;
|
||||
const jobs: ActionRunJob[] = jobsQuery.data ?? [];
|
||||
const state = run?.conclusion || run?.status || '';
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<View style={styles.titleBlock}>
|
||||
<AppText variant="heading">{run?.display_title || run?.title || `#${id}`}</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
<Badge tone={STATUS_TONE[state] ?? 'neutral'}>
|
||||
{t(`actions.state_${state}`, state)}
|
||||
</Badge>
|
||||
{run?.head_branch ? <Badge tone="neutral" icon="branch">{run.head_branch}</Badge> : null}
|
||||
{run?.created_at ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatDateTime(run.created_at)}
|
||||
</AppText>
|
||||
) : null}
|
||||
</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}
|
||||
|
||||
<AppText variant="subheading">{t('actions.jobs')}</AppText>
|
||||
|
||||
{jobsQuery.isPending ? (
|
||||
<LoadingView label={t('actions.loadingJobs')} />
|
||||
) : jobs.length === 0 ? (
|
||||
<AppText variant="secondary" tone="tertiary">
|
||||
{t('actions.noJobs')}
|
||||
</AppText>
|
||||
) : (
|
||||
jobs.map((job) => <JobRow key={job.id} owner={owner} name={name} job={job} />)
|
||||
)}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
function JobRow({ owner, name, job }: { owner: string; name: string; job: ActionRunJob }) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const logsQuery = useActionJobLogs(owner, name, job.id ?? 0, expanded);
|
||||
const state = job.conclusion || job.status || '';
|
||||
|
||||
return (
|
||||
<Card padded={false}>
|
||||
<ListItem
|
||||
title={job.name ?? t('actions.unnamedJob')}
|
||||
subtitle={state ? t(`actions.state_${state}`, state) : undefined}
|
||||
leadingIcon="code"
|
||||
rightText={expanded ? t('actions.hideLogs') : t('actions.showLogs')}
|
||||
onPress={() => setExpanded((value) => !value)}
|
||||
divider={expanded}
|
||||
/>
|
||||
{expanded ? (
|
||||
<View style={styles.logs}>
|
||||
{logsQuery.isPending ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('actions.loadingLogs')}
|
||||
</AppText>
|
||||
) : logsQuery.isError ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('actions.logsUnavailable')}
|
||||
</AppText>
|
||||
) : (
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator>
|
||||
<AppText variant="monoSmall" selectable style={{ color: colors.text }}>
|
||||
{logsQuery.data && logsQuery.data.length > 0
|
||||
? logsQuery.data
|
||||
: t('actions.emptyLogs')}
|
||||
</AppText>
|
||||
</ScrollView>
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
titleBlock: { gap: spacing.sm },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
logs: {
|
||||
paddingHorizontal: spacing.md,
|
||||
paddingBottom: spacing.md,
|
||||
maxHeight: 320,
|
||||
},
|
||||
logText: { fontFamily: fontFamily.mono, fontSize: fontSize.xs },
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
import { useState } from 'react';
|
||||
import { 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, type BadgeTone } from '@/components/ui/badge';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import type { ActionRun } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { formatRelativeTime } from '@/core/utils/format';
|
||||
import { useActionRuns } from '@/features/actions/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'Actions'>;
|
||||
|
||||
type StatusKey = 'all' | 'success' | 'failure' | 'running';
|
||||
|
||||
const STATUS_TONE: Record<string, BadgeTone> = {
|
||||
success: 'success',
|
||||
failure: 'error',
|
||||
cancelled: 'warning',
|
||||
skipped: 'neutral',
|
||||
running: 'info',
|
||||
waiting: 'warning',
|
||||
};
|
||||
|
||||
/** Gitea Actions runs for a repository, filterable by status. */
|
||||
export function ActionsScreen({ navigation, route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name } = route.params;
|
||||
const [status, setStatus] = useState<StatusKey>('all');
|
||||
|
||||
const query = useActionRuns(owner, name, status === 'all' ? {} : { status });
|
||||
const runs: ActionRun[] = flattenPages(query.data);
|
||||
|
||||
return (
|
||||
<QueryList<ActionRun>
|
||||
query={query}
|
||||
items={runs}
|
||||
keyExtractor={(run) => String(run.id)}
|
||||
header={
|
||||
<View style={styles.filters}>
|
||||
<SegmentedControl<StatusKey>
|
||||
value={status}
|
||||
onChange={setStatus}
|
||||
accessibilityLabel={t('actions.title')}
|
||||
options={[
|
||||
{ value: 'all', label: t('actions.filterAll') },
|
||||
{ value: 'success', label: t('actions.filterSuccess') },
|
||||
{ value: 'failure', label: t('actions.filterFailure') },
|
||||
{ value: 'running', label: t('actions.filterRunning') },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
}
|
||||
renderItem={(run) => {
|
||||
const state = run.conclusion || run.status || '';
|
||||
return (
|
||||
<View style={styles.row}>
|
||||
<AppText
|
||||
variant="bodyMedium"
|
||||
numberOfLines={2}
|
||||
onPress={() => run.id && navigation.navigate('ActionRunDetail', { owner, name, id: run.id })}
|
||||
accessibilityRole="button"
|
||||
>
|
||||
{run.display_title || run.title || `#${run.run_number ?? run.id}`}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
<Badge tone={STATUS_TONE[state] ?? 'neutral'}>{t(`actions.state_${state}`, state)}</Badge>
|
||||
{run.head_branch ? <Badge tone="neutral" icon="branch">{run.head_branch}</Badge> : null}
|
||||
{run.event ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{run.event}
|
||||
</AppText>
|
||||
) : null}
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatRelativeTime(run.created_at ?? run.started_at, t)}
|
||||
</AppText>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
empty={<EmptyState icon="autoRenew" title={t('actions.empty')} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
filters: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
|
||||
row: { paddingHorizontal: spacing.lg, paddingVertical: spacing.md, gap: spacing.xs },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Avatar } from '@/components/ui/avatar';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { IconButton } from '@/components/ui/icon-button';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
import { EmptyState, ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import type { CollaboratorPermission } from '@/core/api/endpoints';
|
||||
import {
|
||||
useAddCollaborator,
|
||||
useCollaboratorsList,
|
||||
useRemoveCollaborator,
|
||||
} from '@/features/repositories/settings-queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'Collaborators'>;
|
||||
|
||||
/** Repository collaborators: list, add by username, remove. */
|
||||
export function CollaboratorsScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name } = route.params;
|
||||
|
||||
const query = useCollaboratorsList(owner, name);
|
||||
const add = useAddCollaborator(owner, name);
|
||||
const remove = useRemoveCollaborator(owner, name);
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [permission, setPermission] = useState<CollaboratorPermission>('write');
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
if (query.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(query.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void query.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const collaborators = query.data ?? [];
|
||||
|
||||
const submit = () => {
|
||||
const login = username.trim();
|
||||
if (login.length === 0) return;
|
||||
add.mutate(
|
||||
{ username: login, permission },
|
||||
{
|
||||
onSuccess: () => setUsername(''),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const confirmRemove = (login: string) => {
|
||||
Alert.alert(t('repoSettings.removeCollaboratorTitle'), t('repoSettings.removeCollaboratorBody', { name: login }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.remove'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
remove.mutate(login, {
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
}),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Card>
|
||||
<Field
|
||||
label={t('repoSettings.addCollaborator')}
|
||||
value={username}
|
||||
onChangeText={setUsername}
|
||||
placeholder={t('repoSettings.usernamePlaceholder')}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
/>
|
||||
<View style={styles.permission}>
|
||||
<SegmentedControl<CollaboratorPermission>
|
||||
value={permission}
|
||||
onChange={setPermission}
|
||||
accessibilityLabel={t('repoSettings.permission')}
|
||||
options={[
|
||||
{ value: 'read', label: t('repoSettings.read') },
|
||||
{ value: 'write', label: t('repoSettings.write') },
|
||||
{ value: 'admin', label: t('repoSettings.admin') },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
<Button
|
||||
label={t('common.add')}
|
||||
onPress={submit}
|
||||
loading={add.isPending}
|
||||
disabled={username.trim().length === 0}
|
||||
fullWidth
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{collaborators.length === 0 ? (
|
||||
<EmptyState icon="people" title={t('repoSettings.noCollaborators')} />
|
||||
) : (
|
||||
collaborators.map((user) => (
|
||||
<Card key={user.id ?? user.login}>
|
||||
<View style={styles.row}>
|
||||
<Avatar url={user.avatar_url} name={user.login} size={32} />
|
||||
<AppText variant="bodyMedium" style={styles.login} numberOfLines={1}>
|
||||
{user.login}
|
||||
</AppText>
|
||||
{user.is_admin ? <Badge tone="warning">{t('repoSettings.admin')}</Badge> : null}
|
||||
<IconButton
|
||||
name="trash"
|
||||
onPress={() => confirmRemove(user.login)}
|
||||
accessibilityLabel={t('common.remove')}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
permission: { marginTop: spacing.md },
|
||||
row: { flexDirection: 'row', alignItems: 'center', gap: spacing.md },
|
||||
login: { flex: 1, fontWeight: '600' },
|
||||
});
|
||||
@@ -0,0 +1,188 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { IconButton } from '@/components/ui/icon-button';
|
||||
import { EmptyState, ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import {
|
||||
useBranchProtections,
|
||||
useCreateBranchProtection,
|
||||
useDeleteBranchProtection,
|
||||
} from '@/features/repositories/settings-queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'Protections'>;
|
||||
|
||||
/** Branch protection rules: list, create a basic rule, delete. */
|
||||
export function ProtectionsScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const { owner, name } = route.params;
|
||||
|
||||
const query = useBranchProtections(owner, name);
|
||||
const create = useCreateBranchProtection(owner, name);
|
||||
const remove = useDeleteBranchProtection(owner, name);
|
||||
|
||||
const [branchName, setBranchName] = useState('');
|
||||
const [requiredApprovals, setRequiredApprovals] = useState('1');
|
||||
const [signedCommits, setSignedCommits] = useState(false);
|
||||
const [statusCheck, setStatusCheck] = useState(false);
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
if (query.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(query.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void query.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const rules = query.data ?? [];
|
||||
|
||||
const submit = () => {
|
||||
const pattern = branchName.trim();
|
||||
if (pattern.length === 0) return;
|
||||
create.mutate(
|
||||
{
|
||||
branch_name: pattern,
|
||||
required_approvals: Number(requiredApprovals) || 0,
|
||||
enable_push: false,
|
||||
require_signed_commits: signedCommits,
|
||||
enable_status_check: statusCheck,
|
||||
},
|
||||
{
|
||||
onSuccess: () => setBranchName(''),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const confirmDelete = (rule: string) => {
|
||||
Alert.alert(t('repoSettings.deleteRuleTitle'), t('repoSettings.deleteRuleBody', { name: rule }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.delete'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
remove.mutate(rule, {
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
}),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Card>
|
||||
<Field
|
||||
label={t('repoSettings.branchName')}
|
||||
value={branchName}
|
||||
onChangeText={setBranchName}
|
||||
placeholder="main"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
mono
|
||||
/>
|
||||
<Field
|
||||
label={t('repoSettings.requiredApprovals')}
|
||||
value={requiredApprovals}
|
||||
onChangeText={setRequiredApprovals}
|
||||
keyboardType="number-pad"
|
||||
/>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('repoSettings.requireSignedCommits')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={signedCommits}
|
||||
onValueChange={setSignedCommits}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('repoSettings.requireStatusChecks')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={statusCheck}
|
||||
onValueChange={setStatusCheck}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
<Button
|
||||
label={t('common.add')}
|
||||
onPress={submit}
|
||||
loading={create.isPending}
|
||||
disabled={branchName.trim().length === 0}
|
||||
fullWidth
|
||||
style={styles.spaced}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{rules.length === 0 ? (
|
||||
<EmptyState icon="shield" title={t('repoSettings.noProtections')} />
|
||||
) : (
|
||||
rules.map((rule) => {
|
||||
const label = rule.rule_name || rule.branch_name || '';
|
||||
return (
|
||||
<Card key={rule.rule_name ?? rule.branch_name}>
|
||||
<View style={styles.row}>
|
||||
<View style={styles.body}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{label}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
{rule.enable_push === false ? (
|
||||
<Badge tone="warning">{t('repoSettings.pushRestricted')}</Badge>
|
||||
) : null}
|
||||
{rule.required_approvals ? (
|
||||
<Badge tone="info">
|
||||
{t('repoSettings.approvalsBadge', { count: rule.required_approvals })}
|
||||
</Badge>
|
||||
) : null}
|
||||
{rule.require_signed_commits ? (
|
||||
<Badge tone="success">{t('repoSettings.signedBadge')}</Badge>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
<IconButton
|
||||
name="trash"
|
||||
onPress={() => confirmDelete(label)}
|
||||
accessibilityLabel={t('common.delete')}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
switchRow: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: spacing.md,
|
||||
marginTop: spacing.md,
|
||||
},
|
||||
switchLabel: { flex: 1 },
|
||||
spaced: { marginTop: spacing.lg },
|
||||
row: { flexDirection: 'row', alignItems: 'center', gap: spacing.md },
|
||||
body: { flex: 1, gap: spacing.xs },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -0,0 +1,177 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { TextArea } from '@/components/ui/text-area';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import type { Release } from '@/core/api/types';
|
||||
import { useCreateRelease, useRelease, useUpdateRelease } from '@/features/repositories/queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'ReleaseCompose'>;
|
||||
|
||||
/** Create (no id) or edit (id) a release. */
|
||||
export function ReleaseComposeScreen({ navigation, route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name, id } = route.params;
|
||||
const editing = typeof id === 'number' && id > 0;
|
||||
|
||||
const releaseQuery = useRelease(owner, name, editing ? (id as number) : 0);
|
||||
|
||||
if (editing && releaseQuery.isPending) return <LoadingView />;
|
||||
if (editing && releaseQuery.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(releaseQuery.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void releaseQuery.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ReleaseForm
|
||||
key={editing ? `edit-${id}` : 'new'}
|
||||
owner={owner}
|
||||
name={name}
|
||||
release={editing ? releaseQuery.data : undefined}
|
||||
editing={editing}
|
||||
releaseId={editing ? (id as number) : 0}
|
||||
onDone={() => navigation.goBack()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
interface FormProps {
|
||||
owner: string;
|
||||
name: string;
|
||||
release?: Release;
|
||||
editing: boolean;
|
||||
releaseId: number;
|
||||
onDone: () => void;
|
||||
}
|
||||
|
||||
function ReleaseForm({ owner, name, release, editing, releaseId, onDone }: FormProps) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const createRelease = useCreateRelease(owner, name);
|
||||
const updateRelease = useUpdateRelease(owner, name, releaseId);
|
||||
const mutation = editing ? updateRelease : createRelease;
|
||||
|
||||
const [tag, setTag] = useState(release?.tag_name ?? '');
|
||||
const [title, setTitle] = useState(release?.name ?? '');
|
||||
const [body, setBody] = useState(release?.body ?? '');
|
||||
const [prerelease, setPrerelease] = useState(release?.prerelease ?? false);
|
||||
const [draft, setDraft] = useState(release?.draft ?? false);
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
|
||||
const tagError = submitted && !editing && tag.trim().length === 0 ? t('releases.tagRequired') : undefined;
|
||||
|
||||
const submit = () => {
|
||||
setSubmitted(true);
|
||||
if (!editing && tag.trim().length === 0) return;
|
||||
mutation.mutate(
|
||||
{
|
||||
tag_name: tag.trim(),
|
||||
name: title.trim() || undefined,
|
||||
body: body.trim() || undefined,
|
||||
prerelease,
|
||||
draft,
|
||||
},
|
||||
{
|
||||
onSuccess: onDone,
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Field
|
||||
label={t('releases.tag')}
|
||||
value={tag}
|
||||
onChangeText={setTag}
|
||||
placeholder="v1.0.0"
|
||||
showError={Boolean(tagError)}
|
||||
error={tagError}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
mono
|
||||
editable={!editing}
|
||||
testID="release-tag"
|
||||
/>
|
||||
<Field
|
||||
label={t('releases.name')}
|
||||
value={title}
|
||||
onChangeText={setTitle}
|
||||
autoCapitalize="sentences"
|
||||
/>
|
||||
<TextArea
|
||||
label={t('releases.notes')}
|
||||
value={body}
|
||||
onChangeText={setBody}
|
||||
autoCapitalize="sentences"
|
||||
autoCorrect
|
||||
minHeight={140}
|
||||
/>
|
||||
<Card>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('releases.prerelease')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={prerelease}
|
||||
onValueChange={setPrerelease}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('releases.draft')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={draft}
|
||||
onValueChange={setDraft}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
|
||||
{mutation.isError ? (
|
||||
<AppText variant="caption" tone="error">
|
||||
{apiErrorMessage(mutation.error, t)}
|
||||
</AppText>
|
||||
) : null}
|
||||
|
||||
<Button
|
||||
label={editing ? t('common.save') : t('releases.create')}
|
||||
onPress={submit}
|
||||
loading={mutation.isPending}
|
||||
disabled={!editing && tag.trim().length === 0}
|
||||
fullWidth
|
||||
testID="release-submit"
|
||||
/>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
switchRow: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: spacing.md,
|
||||
marginTop: spacing.sm,
|
||||
},
|
||||
switchLabel: { flex: 1 },
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Linking, Pressable, StyleSheet, View } from 'react-native';
|
||||
import { Alert, Linking, Pressable, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Markdown } from '@/components/git/markdown';
|
||||
@@ -12,7 +12,7 @@ import { Icon } from '@/components/ui/icon';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import { useRelease } from '@/features/repositories/queries';
|
||||
import { useDeleteRelease, useRelease } from '@/features/repositories/queries';
|
||||
import { formatBytes, formatDateTime } from '@/core/utils/format';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
@@ -22,13 +22,14 @@ import type { ScreenProps } from '@/navigation/typing';
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'ReleaseDetail'>;
|
||||
|
||||
/** One release: metadata, notes and downloadable assets. */
|
||||
export function ReleaseDetailScreen({ route }: Props) {
|
||||
export function ReleaseDetailScreen({ navigation, route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const { instance } = useSession();
|
||||
const { owner, name, id } = route.params;
|
||||
|
||||
const query = useRelease(owner, name, id);
|
||||
const deleteRelease = useDeleteRelease(owner, name, id);
|
||||
const release = query.data;
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
@@ -115,6 +116,35 @@ export function ReleaseDetailScreen({ route }: Props) {
|
||||
onPress={() => void Linking.openURL(release.html_url as string).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
label={t('common.edit')}
|
||||
variant="secondary"
|
||||
iconLeft="edit"
|
||||
onPress={() => navigation.navigate('ReleaseCompose', { owner, name, id })}
|
||||
/>
|
||||
<Button
|
||||
label={t('common.delete')}
|
||||
variant="danger"
|
||||
iconLeft="trash"
|
||||
loading={deleteRelease.isPending}
|
||||
onPress={() =>
|
||||
Alert.alert(t('releases.deleteTitle'), t('releases.deleteBody', { tag: release.tag_name ?? '' }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.delete'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
deleteRelease.mutate(undefined, {
|
||||
onSuccess: () => navigation.goBack(),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
}),
|
||||
},
|
||||
])
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
@@ -133,4 +163,5 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
divider: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: 'rgba(128,128,128,0.25)' },
|
||||
assetBody: { flex: 1, gap: 2 },
|
||||
actions: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
|
||||
});
|
||||
@@ -4,6 +4,7 @@ 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 { Button } from '@/components/ui/button';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import type { Release } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
@@ -28,6 +29,17 @@ export function ReleasesScreen({ navigation, route }: Props) {
|
||||
query={query}
|
||||
items={releases}
|
||||
keyExtractor={(release) => String(release.id ?? release.tag_name)}
|
||||
header={
|
||||
<View style={styles.header}>
|
||||
<Button
|
||||
label={t('releases.create')}
|
||||
variant="secondary"
|
||||
iconLeft="plus"
|
||||
fullWidth
|
||||
onPress={() => navigation.navigate('ReleaseCompose', { owner, name })}
|
||||
/>
|
||||
</View>
|
||||
}
|
||||
renderItem={(release) => (
|
||||
<View style={styles.row}>
|
||||
<AppText
|
||||
@@ -57,6 +69,7 @@ export function ReleasesScreen({ navigation, route }: Props) {
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
header: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
|
||||
row: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
|
||||
@@ -234,6 +234,13 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
||||
onPress={() => void Linking.openURL(`${repoUrl}/wiki`).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
{repo.has_actions !== false ? (
|
||||
<ListItem
|
||||
leadingIcon="autoRenew"
|
||||
title={t('actions.title')}
|
||||
onPress={() => navigation.navigate('Actions', { owner, name })}
|
||||
/>
|
||||
) : null}
|
||||
{repo.has_issues !== false ? (
|
||||
<ListItem
|
||||
leadingIcon="issue"
|
||||
@@ -254,6 +261,23 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
||||
</Card>
|
||||
</View>
|
||||
|
||||
{/* Manage */}
|
||||
{repo.permissions?.push || repo.permissions?.admin || repo.permissions?.pull ? (
|
||||
<View style={styles.section}>
|
||||
<AppText variant="subheading" style={styles.sectionTitle}>
|
||||
{t('repo.manage')}
|
||||
</AppText>
|
||||
<Card padded={false} variant="flat" style={styles.card}>
|
||||
<ListItem
|
||||
leadingIcon="gear"
|
||||
title={t('repoSettings.title')}
|
||||
onPress={() => navigation.navigate('RepoSettings', { owner, name })}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* Statistics */}
|
||||
<View style={styles.section}>
|
||||
<AppText variant="subheading" style={styles.sectionTitle}>
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { ListItem } from '@/components/ui/list-item';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { useRepository } from '@/features/repositories/queries';
|
||||
import {
|
||||
useDeleteRepo,
|
||||
useUpdateRepo,
|
||||
} from '@/features/repositories/settings-queries';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'RepoSettings'>;
|
||||
|
||||
type FeatureKey =
|
||||
| 'has_issues'
|
||||
| 'has_pull_requests'
|
||||
| 'has_wiki'
|
||||
| 'has_releases'
|
||||
| 'has_projects'
|
||||
| 'has_packages'
|
||||
| 'has_actions';
|
||||
|
||||
/** Repository settings: metadata, feature toggles, danger zone and sub-sections. */
|
||||
export function RepoSettingsScreen({ navigation, route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const { owner, name } = route.params;
|
||||
|
||||
const repoQuery = useRepository(owner, name);
|
||||
const repo = repoQuery.data;
|
||||
const updateRepo = useUpdateRepo(owner, name);
|
||||
const deleteRepo = useDeleteRepo(owner, name);
|
||||
|
||||
const [description, setDescription] = useState<string | null>(null);
|
||||
const [website, setWebsite] = useState<string | null>(null);
|
||||
const [isPrivate, setIsPrivate] = useState<boolean | null>(null);
|
||||
const [features, setFeatures] = useState<Partial<Record<FeatureKey, boolean>>>({});
|
||||
|
||||
if (repoQuery.isPending) return <LoadingView />;
|
||||
if (repoQuery.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(repoQuery.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void repoQuery.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (!repo) return null;
|
||||
|
||||
const descriptionValue = description ?? repo.description ?? '';
|
||||
const websiteValue = website ?? repo.website ?? '';
|
||||
const privateValue = isPrivate ?? repo.private ?? false;
|
||||
const featureValue = (key: FeatureKey) => features[key] ?? repo[key] ?? true;
|
||||
|
||||
const save = () => {
|
||||
updateRepo.mutate(
|
||||
{
|
||||
description: descriptionValue,
|
||||
website: websiteValue,
|
||||
private: privateValue,
|
||||
has_issues: featureValue('has_issues'),
|
||||
has_pull_requests: featureValue('has_pull_requests'),
|
||||
has_wiki: featureValue('has_wiki'),
|
||||
has_releases: featureValue('has_releases'),
|
||||
has_projects: featureValue('has_projects'),
|
||||
has_packages: featureValue('has_packages'),
|
||||
has_actions: featureValue('has_actions'),
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
Alert.alert(t('repoSettings.savedTitle'), t('repoSettings.savedBody'));
|
||||
},
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const confirmDelete = () => {
|
||||
Alert.alert(t('repoSettings.deleteTitle'), t('repoSettings.deleteBody', { name }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.delete'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
deleteRepo.mutate(undefined, {
|
||||
onSuccess: () => navigation.getParent()?.goBack(),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
}),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const featureRows: { key: FeatureKey; label: string }[] = [
|
||||
{ key: 'has_issues', label: t('repo.issuesTab') },
|
||||
{ key: 'has_pull_requests', label: t('repo.pullsTab') },
|
||||
{ key: 'has_wiki', label: t('repo.wiki') },
|
||||
{ key: 'has_releases', label: t('releases.title') },
|
||||
{ key: 'has_projects', label: t('repoSettings.projects') },
|
||||
{ key: 'has_packages', label: t('packages.title') },
|
||||
{ key: 'has_actions', label: t('actions.title') },
|
||||
];
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Field label={t('repo.description')} value={descriptionValue} onChangeText={setDescription} />
|
||||
<Field
|
||||
label={t('repoSettings.website')}
|
||||
value={websiteValue}
|
||||
onChangeText={setWebsite}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
/>
|
||||
|
||||
<Card>
|
||||
<View style={styles.switchRow}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{t('repositories.private')}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={privateValue}
|
||||
onValueChange={setIsPrivate}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
|
||||
<AppText variant="subheading">{t('repoSettings.features')}</AppText>
|
||||
<Card>
|
||||
{featureRows.map((row, index) => (
|
||||
<View key={row.key} style={[styles.switchRow, index > 0 && styles.spaced]}>
|
||||
<AppText variant="bodyMedium" style={styles.switchLabel}>
|
||||
{row.label}
|
||||
</AppText>
|
||||
<Switch
|
||||
value={featureValue(row.key)}
|
||||
onValueChange={(value) => setFeatures((prev) => ({ ...prev, [row.key]: value }))}
|
||||
trackColor={{ true: colors.primary, false: colors.border }}
|
||||
/>
|
||||
</View>
|
||||
))}
|
||||
</Card>
|
||||
|
||||
<Button
|
||||
label={t('common.save')}
|
||||
onPress={save}
|
||||
loading={updateRepo.isPending}
|
||||
fullWidth
|
||||
testID="repo-save"
|
||||
/>
|
||||
|
||||
<AppText variant="subheading">{t('repoSettings.sections')}</AppText>
|
||||
<Card padded={false} variant="flat">
|
||||
<ListItem
|
||||
leadingIcon="people"
|
||||
title={t('repoSettings.collaborators')}
|
||||
onPress={() => navigation.navigate('Collaborators', { owner, name })}
|
||||
/>
|
||||
<ListItem
|
||||
leadingIcon="globe"
|
||||
title={t('repoSettings.webhooks')}
|
||||
onPress={() => navigation.navigate('Webhooks', { owner, name })}
|
||||
/>
|
||||
<ListItem
|
||||
leadingIcon="shield"
|
||||
title={t('repoSettings.protections')}
|
||||
onPress={() => navigation.navigate('Protections', { owner, name })}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<AppText variant="subheading" tone="error">
|
||||
{t('repoSettings.dangerZone')}
|
||||
</AppText>
|
||||
<Button
|
||||
label={t('repoSettings.deleteRepo')}
|
||||
variant="danger"
|
||||
iconLeft="trash"
|
||||
loading={deleteRepo.isPending}
|
||||
onPress={confirmDelete}
|
||||
fullWidth
|
||||
/>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
switchRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: spacing.md },
|
||||
switchLabel: { flex: 1 },
|
||||
spaced: { marginTop: spacing.md },
|
||||
});
|
||||
@@ -0,0 +1,201 @@
|
||||
import { useState } from 'react';
|
||||
import { Alert, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { IconButton } from '@/components/ui/icon-button';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
import { EmptyState, ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { useCreateWebhook, useDeleteWebhook, useWebhooks } from '@/features/repositories/settings-queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'Webhooks'>;
|
||||
|
||||
type HookType = 'gitea' | 'slack' | 'discord';
|
||||
type ContentType = 'json' | 'form';
|
||||
|
||||
/** Repository webhooks: list, add a common type, delete. */
|
||||
export function WebhooksScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name } = route.params;
|
||||
|
||||
const query = useWebhooks(owner, name);
|
||||
const createWebhook = useCreateWebhook(owner, name);
|
||||
const deleteWebhook = useDeleteWebhook(owner, name);
|
||||
|
||||
const [type, setType] = useState<HookType>('gitea');
|
||||
const [url, setUrl] = useState('');
|
||||
const [contentType, setContentType] = useState<ContentType>('json');
|
||||
const [secret, setSecret] = useState('');
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
if (query.isError) {
|
||||
return (
|
||||
<ErrorState
|
||||
title={t('errors.title')}
|
||||
body={apiErrorMessage(query.error, t)}
|
||||
retryLabel={t('common.retry')}
|
||||
onRetry={() => void query.refetch()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const hooks = query.data ?? [];
|
||||
|
||||
const submit = () => {
|
||||
const target = url.trim();
|
||||
if (target.length === 0) return;
|
||||
createWebhook.mutate(
|
||||
{
|
||||
type,
|
||||
config: {
|
||||
url: target,
|
||||
content_type: contentType,
|
||||
...(secret.trim() ? { secret: secret.trim() } : {}),
|
||||
},
|
||||
events: ['push', 'issues', 'pull_request', 'release'],
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setUrl('');
|
||||
setSecret('');
|
||||
},
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const confirmDelete = (id: number) => {
|
||||
Alert.alert(t('repoSettings.deleteWebhookTitle'), t('repoSettings.deleteWebhookBody'), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.delete'),
|
||||
style: 'destructive',
|
||||
onPress: () =>
|
||||
deleteWebhook.mutate(id, {
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
}),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Card>
|
||||
<AppText variant="label" tone="secondary">
|
||||
{t('repoSettings.webhookType')}
|
||||
</AppText>
|
||||
<View style={styles.spaced}>
|
||||
<SegmentedControl<HookType>
|
||||
value={type}
|
||||
onChange={setType}
|
||||
accessibilityLabel={t('repoSettings.webhookType')}
|
||||
options={[
|
||||
{ value: 'gitea', label: 'Gitea' },
|
||||
{ value: 'slack', label: 'Slack' },
|
||||
{ value: 'discord', label: 'Discord' },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.field}>
|
||||
<Field
|
||||
label={t('repoSettings.webhookUrl')}
|
||||
value={url}
|
||||
onChangeText={setUrl}
|
||||
placeholder="https://example.com/hook"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
/>
|
||||
</View>
|
||||
{type === 'gitea' ? (
|
||||
<>
|
||||
<AppText variant="label" tone="secondary" style={styles.spaced}>
|
||||
{t('repoSettings.contentType')}
|
||||
</AppText>
|
||||
<View style={styles.spaced}>
|
||||
<SegmentedControl<ContentType>
|
||||
value={contentType}
|
||||
onChange={setContentType}
|
||||
accessibilityLabel={t('repoSettings.contentType')}
|
||||
options={[
|
||||
{ value: 'json', label: 'JSON' },
|
||||
{ value: 'form', label: 'form' },
|
||||
]}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.field}>
|
||||
<Field
|
||||
label={`${t('repoSettings.secret')} (${t('common.optional')})`}
|
||||
value={secret}
|
||||
onChangeText={setSecret}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
secureTextEntry
|
||||
/>
|
||||
</View>
|
||||
</>
|
||||
) : null}
|
||||
<Button
|
||||
label={t('common.add')}
|
||||
onPress={submit}
|
||||
loading={createWebhook.isPending}
|
||||
disabled={url.trim().length === 0}
|
||||
fullWidth
|
||||
style={styles.spaced}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{hooks.length === 0 ? (
|
||||
<EmptyState icon="globe" title={t('repoSettings.noWebhooks')} />
|
||||
) : (
|
||||
hooks.map((hook) => (
|
||||
<Card key={hook.id}>
|
||||
<View style={styles.row}>
|
||||
<View style={styles.body}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{hook.config?.url ?? hook.name ?? `#${hook.id}`}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
<Badge tone="neutral">{hook.type ?? 'gitea'}</Badge>
|
||||
{hook.active === false ? (
|
||||
<Badge tone="warning">{t('repoSettings.inactive')}</Badge>
|
||||
) : null}
|
||||
{hook.events?.length ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('repoSettings.events', { count: hook.events.length })}
|
||||
</AppText>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
{hook.id ? (
|
||||
<IconButton
|
||||
name="trash"
|
||||
onPress={() => confirmDelete(hook.id as number)}
|
||||
accessibilityLabel={t('common.delete')}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
</Card>
|
||||
))
|
||||
)}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
spaced: { marginTop: spacing.sm },
|
||||
field: { marginTop: spacing.md },
|
||||
row: { flexDirection: 'row', alignItems: 'center', gap: spacing.md },
|
||||
body: { flex: 1, gap: spacing.xs },
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import Constants from 'expo-constants';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Alert, Linking, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
@@ -29,6 +31,7 @@ const GITEA_HOME_URL = 'https://gitea.com';
|
||||
/** App settings: appearance, language, security, notifications, data, about. */
|
||||
export function SettingsScreen(_props: Props) {
|
||||
const navigation = useRootNavigation();
|
||||
const stackNavigation = useNavigation<NativeStackNavigationProp<SettingsStackParamList>>();
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
|
||||
@@ -190,6 +193,28 @@ export function SettingsScreen(_props: Props) {
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* Account data */}
|
||||
<Section title={t('settings.accountData')}>
|
||||
<Card padded={false} variant="flat">
|
||||
<ListItem
|
||||
leadingIcon="people"
|
||||
title={t('organizations.title')}
|
||||
onPress={() => stackNavigation.navigate('Organizations')}
|
||||
/>
|
||||
<ListItem
|
||||
leadingIcon="package"
|
||||
title={t('packages.title')}
|
||||
onPress={() => stackNavigation.navigate('Packages')}
|
||||
/>
|
||||
<ListItem
|
||||
leadingIcon="lock"
|
||||
title={t('credentials.title')}
|
||||
onPress={() => stackNavigation.navigate('Credentials')}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* About */}
|
||||
<Section title={t('settings.about')}>
|
||||
<Card padded={false} variant="flat">
|
||||
|
||||
Reference in new issue
Block a user