feat(phase5): deploy keys, profile editing, organization creation

- API: repo deploy keys (list/add/delete), user settings GET/PATCH, org create
- hooks: useRepoKeys/useAddRepoKey/useDeleteRepoKey; useUserSettings,
  useUpdateUserSettings, useCreateOrg
- screens: DeployKeys, Profile (edit), CreateOrg; wired into RepoSettings,
  Settings and Organizations
- endpoint body-shape tests for repo update, release, deploy key, user settings,
  org create and Action run filters (120 tests total)
This commit is contained in:
JustZoe101 committed 2026-10-09 18:13:54 +02:00
1 parent fa1ebc9184
commit 6d0b536009
17 files changed
+738 -8

No files matched your search

+51 -2
View File
@@ -1,18 +1,30 @@
/** Account-level data: organizations, packages and credential listings. */
import { useInfiniteQuery, type InfiniteData } from '@tanstack/react-query';
import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query';
import type { RawResponse } from '@/core/api/client';
import {
createOrg,
fetchUserSettings,
listOrgRepos,
listPackages,
listUserGpgKeys,
listUserKeys,
listUserOrgs,
listUserTokens,
updateUserSettings,
type CreateOrgInput,
} from '@/core/api/endpoints';
import { queryKeys } from '@/core/api/query-keys';
import type { AccessToken, GpgKey, Organization, Package, PublicKey, Repository } from '@/core/api/types';
import type {
AccessToken,
GpgKey,
Organization,
Package,
PublicKey,
Repository,
UserSettings,
} from '@/core/api/types';
import { useSession } from '@/features/accounts/use-session';
function useAccountList<T>(
@@ -89,3 +101,40 @@ export function useUserTokens(username: string, limit = 50) {
(page, signal) => listUserTokens(client!, username, { page, limit }, { signal }),
);
}
/** Editable profile settings for the signed-in user. */
export function useUserSettings() {
const { client, account } = useSession();
const accountId = account?.id ?? '';
return useQuery<UserSettings>({
queryKey: [...queryKeys.account(accountId), 'settings'],
enabled: Boolean(client) && Boolean(accountId),
queryFn: ({ signal }) => fetchUserSettings(client!, { signal }),
staleTime: 5 * 60_000,
});
}
export function useUpdateUserSettings() {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
return useMutation({
mutationFn: (input: Partial<UserSettings>) => updateUserSettings(client!, input),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: [...queryKeys.account(accountId), 'settings'] });
void queryClient.invalidateQueries({ queryKey: queryKeys.me(accountId) });
},
});
}
export function useCreateOrg() {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
return useMutation({
mutationFn: (input: CreateOrgInput) => createOrg(client!, input),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
},
});
}
@@ -0,0 +1,118 @@
import { useState } from 'react';
import { Alert, 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 { Screen } from '@/components/layout/screen';
import { AppText } from '@/components/ui/app-text';
import { Button } from '@/components/ui/button';
import { Field } from '@/components/ui/field';
import { SegmentedControl } from '@/components/ui/segmented';
import { apiErrorMessage } from '@/core/api/error-text';
import { useCreateOrg } from '@/features/profile/queries';
import { spacing } from '@/theme/tokens';
import type { SettingsStackParamList } from '@/navigation/types';
type Visibility = 'public' | 'limited' | 'private';
/** Create an organization. */
export function CreateOrgScreen() {
const { t } = useTranslation();
const navigation = useNavigation<NativeStackNavigationProp<SettingsStackParamList>>();
const create = useCreateOrg();
const [username, setUsername] = useState('');
const [fullName, setFullName] = useState('');
const [location, setLocation] = useState('');
const [visibility, setVisibility] = useState<Visibility>('public');
const [submitted, setSubmitted] = useState(false);
const usernameError =
submitted && username.trim().length === 0 ? t('organizations.usernameRequired') : undefined;
const submit = () => {
setSubmitted(true);
if (username.trim().length === 0) return;
create.mutate(
{
username: username.trim(),
full_name: fullName.trim() || undefined,
location: location.trim() || undefined,
visibility,
},
{
onSuccess: () => {
Alert.alert(t('organizations.createdTitle'), t('organizations.createdBody'));
navigation.goBack();
},
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
},
);
};
return (
<Screen scroll padded>
<Field
label={t('organizations.username')}
value={username}
onChangeText={setUsername}
placeholder={t('organizations.usernamePlaceholder')}
showError={Boolean(usernameError)}
error={usernameError}
autoCapitalize="none"
autoCorrect={false}
testID="org-username"
/>
<Field
label={t('profile.fullName')}
value={fullName}
onChangeText={setFullName}
autoCapitalize="words"
/>
<Field
label={t('profile.location')}
value={location}
onChangeText={setLocation}
autoCapitalize="words"
/>
<View style={styles.visibility}>
<AppText variant="label" tone="secondary">
{t('organizations.visibility')}
</AppText>
<View style={styles.visibilityControl}>
<SegmentedControl<Visibility>
value={visibility}
onChange={setVisibility}
accessibilityLabel={t('organizations.visibility')}
options={[
{ value: 'public', label: t('organizations.visPublic') },
{ value: 'limited', label: t('organizations.visLimited') },
{ value: 'private', label: t('organizations.visPrivate') },
]}
/>
</View>
</View>
{create.isError ? (
<AppText variant="caption" tone="error">
{apiErrorMessage(create.error, t)}
</AppText>
) : null}
<Button
label={t('organizations.create')}
onPress={submit}
loading={create.isPending}
disabled={username.trim().length === 0}
fullWidth
testID="org-submit"
/>
</Screen>
);
}
const styles = StyleSheet.create({
visibility: { gap: spacing.xs },
visibilityControl: { marginTop: spacing.xs },
});
@@ -6,6 +6,7 @@ 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 { Button } from '@/components/ui/button';
import { EmptyState } from '@/components/ui/state-views';
import type { Organization } from '@/core/api/types';
import { flattenPages } from '@/core/utils/infinite';
@@ -25,6 +26,17 @@ export function OrganizationsScreen() {
query={query}
items={orgs}
keyExtractor={(org) => String(org.id ?? org.username)}
header={
<View style={styles.header}>
<Button
label={t('organizations.create')}
variant="secondary"
iconLeft="plus"
fullWidth
onPress={() => navigation.navigate('CreateOrg')}
/>
</View>
}
renderItem={(org) => {
const login = org.username ?? org.name ?? '';
return (
@@ -54,6 +66,7 @@ export function OrganizationsScreen() {
}
const styles = StyleSheet.create({
header: { paddingHorizontal: spacing.lg, paddingVertical: spacing.sm },
row: {
flexDirection: 'row',
alignItems: 'center',
@@ -0,0 +1,101 @@
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 { Button } from '@/components/ui/button';
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 { UserSettings } from '@/core/api/types';
import { useUpdateUserSettings, useUserSettings } from '@/features/profile/queries';
import { spacing } from '@/theme/tokens';
/** Edit the signed-in user's public profile. */
export function ProfileScreen() {
const { t } = useTranslation();
const query = useUserSettings();
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()}
/>
);
}
return <ProfileForm key={query.dataUpdatedAt} settings={query.data ?? {}} />;
}
function ProfileForm({ settings }: { settings: UserSettings }) {
const { t } = useTranslation();
const update = useUpdateUserSettings();
const [fullName, setFullName] = useState(settings.full_name ?? '');
const [bio, setBio] = useState(settings.description ?? '');
const [website, setWebsite] = useState(settings.website ?? '');
const [location, setLocation] = useState(settings.location ?? '');
const save = () => {
update.mutate(
{
full_name: fullName.trim(),
description: bio.trim(),
website: website.trim(),
location: location.trim(),
},
{
onSuccess: () => Alert.alert(t('repoSettings.savedTitle'), t('profile.savedBody')),
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
},
);
};
return (
<Screen scroll padded>
<Field label={t('profile.fullName')} value={fullName} onChangeText={setFullName} autoCapitalize="words" />
<TextArea
label={t('profile.bio')}
value={bio}
onChangeText={setBio}
autoCapitalize="sentences"
autoCorrect
minHeight={100}
/>
<Field
label={t('repoSettings.website')}
value={website}
onChangeText={setWebsite}
autoCapitalize="none"
autoCorrect={false}
keyboardType="url"
/>
<Field label={t('profile.location')} value={location} onChangeText={setLocation} autoCapitalize="words" />
{update.isError ? (
<AppText variant="caption" tone="error">
{apiErrorMessage(update.error, t)}
</AppText>
) : null}
<Button
label={t('common.save')}
onPress={save}
loading={update.isPending}
fullWidth
testID="profile-save"
/>
<View style={styles.spacer} />
</Screen>
);
}
const styles = StyleSheet.create({
spacer: { height: spacing.xl },
});
+46 -1
View File
@@ -4,17 +4,21 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import {
addCollaborator,
addRepoKey,
createBranchProtection,
createRepo,
createWebhook,
deleteBranchProtection,
deleteRepo,
deleteRepoKey,
deleteWebhook,
listBranchProtections,
listCollaborators,
listRepoKeys,
listWebhooks,
removeCollaborator,
updateRepo,
type AddRepoKeyInput,
type CollaboratorPermission,
type CreateBranchProtectionInput,
type CreateRepoInput,
@@ -22,7 +26,7 @@ import {
type UpdateRepoInput,
} from '@/core/api/endpoints';
import { queryKeys } from '@/core/api/query-keys';
import type { BranchProtection, User, Webhook } from '@/core/api/types';
import type { BranchProtection, DeployKey, User, Webhook } from '@/core/api/types';
import { useSession } from '@/features/accounts/use-session';
export function useCollaboratorsList(owner: string, name: string) {
@@ -181,3 +185,44 @@ export function useCreateRepo() {
},
});
}
// ---------------------------------------------------------------------------
// Deploy keys
// ---------------------------------------------------------------------------
export function useRepoKeys(owner: string, name: string) {
const { client, account } = useSession();
const accountId = account?.id ?? '';
return useQuery<DeployKey[]>({
queryKey: queryKeys.repoKeys(accountId, owner, name),
enabled: Boolean(client) && Boolean(accountId),
queryFn: ({ signal }) =>
listRepoKeys(client!, owner, name, { limit: 50 }, { signal }).then((r) => r.data),
staleTime: 30_000,
});
}
export function useAddRepoKey(owner: string, name: string) {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
return useMutation({
mutationFn: (input: AddRepoKeyInput) => addRepoKey(client!, owner, name, input),
onSuccess: () =>
void queryClient.invalidateQueries({ queryKey: queryKeys.repoKeys(accountId, owner, name) }),
});
}
export function useDeleteRepoKey(owner: string, name: string) {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
return useMutation({
mutationFn: (id: number) => deleteRepoKey(client!, owner, name, id),
onSuccess: () =>
void queryClient.invalidateQueries({ queryKey: queryKeys.repoKeys(accountId, owner, name) }),
});
}
@@ -0,0 +1,171 @@
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 { TextArea } from '@/components/ui/text-area';
import { EmptyState, ErrorState, LoadingView } from '@/components/ui/state-views';
import { apiErrorMessage } from '@/core/api/error-text';
import {
useAddRepoKey,
useDeleteRepoKey,
useRepoKeys,
} 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, 'DeployKeys'>;
/** Repository deploy keys: list, add, delete. */
export function DeployKeysScreen({ route }: Props) {
const { t } = useTranslation();
const { colors } = useTheme();
const { owner, name } = route.params;
const query = useRepoKeys(owner, name);
const add = useAddRepoKey(owner, name);
const remove = useDeleteRepoKey(owner, name);
const [title, setTitle] = useState('');
const [key, setKey] = useState('');
const [readOnly, setReadOnly] = useState(true);
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 keys = query.data ?? [];
const submit = () => {
if (title.trim().length === 0 || key.trim().length === 0) return;
add.mutate(
{ title: title.trim(), key: key.trim(), read_only: readOnly },
{
onSuccess: () => {
setTitle('');
setKey('');
},
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
},
);
};
const confirmRemove = (id: number) => {
Alert.alert(t('repoSettings.deleteKeyTitle'), t('repoSettings.deleteKeyBody'), [
{ text: t('common.cancel'), style: 'cancel' },
{
text: t('common.delete'),
style: 'destructive',
onPress: () =>
remove.mutate(id, {
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
}),
},
]);
};
return (
<Screen scroll padded>
<Card>
<Field
label={t('repoSettings.keyTitle')}
value={title}
onChangeText={setTitle}
placeholder={t('repoSettings.keyTitlePlaceholder')}
/>
<View style={styles.keyField}>
<TextArea
label={t('repoSettings.keyValue')}
value={key}
onChangeText={setKey}
placeholder="ssh-ed25519 AAAA…"
mono
autoCapitalize="none"
autoCorrect={false}
minHeight={90}
/>
</View>
<View style={styles.switchRow}>
<AppText variant="bodyMedium" style={styles.switchLabel}>
{t('credentials.readOnly')}
</AppText>
<Switch
value={readOnly}
onValueChange={setReadOnly}
trackColor={{ true: colors.primary, false: colors.border }}
/>
</View>
<Button
label={t('common.add')}
onPress={submit}
loading={add.isPending}
disabled={title.trim().length === 0 || key.trim().length === 0}
fullWidth
style={styles.spaced}
/>
</Card>
{keys.length === 0 ? (
<EmptyState icon="lock" title={t('repoSettings.noDeployKeys')} />
) : (
keys.map((deployKey) => (
<Card key={deployKey.id ?? deployKey.title}>
<View style={styles.row}>
<View style={styles.body}>
<AppText variant="bodyMedium" numberOfLines={1}>
{deployKey.title}
</AppText>
<AppText variant="monoSmall" tone="tertiary" numberOfLines={1}>
{deployKey.fingerprint ?? ''}
</AppText>
</View>
{deployKey.read_only ? (
<Badge tone="neutral">{t('credentials.readOnly')}</Badge>
) : (
<Badge tone="warning">{t('repoSettings.writeAccess')}</Badge>
)}
{deployKey.id ? (
<IconButton
name="trash"
onPress={() => confirmRemove(deployKey.id as number)}
accessibilityLabel={t('common.delete')}
/>
) : null}
</View>
</Card>
))
)}
</Screen>
);
}
const styles = StyleSheet.create({
keyField: { marginTop: spacing.md },
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.sm },
body: { flex: 1, gap: 2 },
});
@@ -177,6 +177,11 @@ export function RepoSettingsScreen({ navigation, route }: Props) {
leadingIcon="shield"
title={t('repoSettings.protections')}
onPress={() => navigation.navigate('Protections', { owner, name })}
/>
<ListItem
leadingIcon="lock"
title={t('repoSettings.deployKeys')}
onPress={() => navigation.navigate('DeployKeys', { owner, name })}
divider={false}
/>
</Card>
@@ -196,6 +196,11 @@ export function SettingsScreen(_props: Props) {
{/* Account data */}
<Section title={t('settings.accountData')}>
<Card padded={false} variant="flat">
<ListItem
leadingIcon="person"
title={t('profile.title')}
onPress={() => stackNavigation.navigate('Profile')}
/>
<ListItem
leadingIcon="people"
title={t('organizations.title')}