feat(phase5): star/watch/fork, releases, wiki fallback, capability probe
- endpoints: is-starred (404→false), star/unstar, subscription watch/unwatch, fork, releases list/detail - hooks: useIsStarred/useToggleStar, useSubscription/useToggleWatch, useForkRepository, useReleases/useRelease - repo overview: star/watch/fork actions, Releases + Wiki entries (wiki via explicit browser fallback gated by capability probe) - screens: Releases list, Release detail with downloadable assets - core/capabilities: version parsing + per-capability minimum versions + tests - i18n (en/nl); README/ROADMAP/FEATURE_PARITY updated for phases 3-5
This commit is contained in:
1 parent
c9dd49446a
commit
5e8c9492b3
16 files changed
+769
-24
No files matched your search
@@ -9,6 +9,7 @@
|
||||
* Gitea instances at `/swagger.v1.json`.
|
||||
*/
|
||||
|
||||
import { ApiError } from './errors';
|
||||
import type { GiteaClient, RequestOptions } from './client';
|
||||
import type {
|
||||
Activity,
|
||||
@@ -25,9 +26,11 @@ import type {
|
||||
NotificationThread,
|
||||
PullRequest,
|
||||
PullReview,
|
||||
Release,
|
||||
Repository,
|
||||
ReviewEvent,
|
||||
ServerVersion,
|
||||
Subscription,
|
||||
Tag,
|
||||
User,
|
||||
} from './types';
|
||||
@@ -145,6 +148,108 @@ export function fetchRepositoryLanguages(
|
||||
return client.get<Record<string, number>>(`${repoPath(owner, repo)}/languages`, options);
|
||||
}
|
||||
|
||||
// --- repository actions (star / watch / fork) ------------------------------
|
||||
|
||||
/** `true` when the authenticated user has starred the repository (404 → false). */
|
||||
export async function fetchIsStarred(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await client.get<void>(`/user/starred/${enc(owner)}/${enc(repo)}`, options);
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError && error.kind === 'not-found') return false;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function starRepo(client: GiteaClient, owner: string, repo: string, options?: RequestOptions) {
|
||||
return client.put<void>(`/user/starred/${enc(owner)}/${enc(repo)}`, undefined, options);
|
||||
}
|
||||
|
||||
export function unstarRepo(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
return client.delete<void>(`/user/starred/${enc(owner)}/${enc(repo)}`, options);
|
||||
}
|
||||
|
||||
export function fetchSubscription(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<Subscription> {
|
||||
return client.get<Subscription>(`${repoPath(owner, repo)}/subscription`, options);
|
||||
}
|
||||
|
||||
export function watchRepo(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<Subscription> {
|
||||
return client.put<Subscription>(
|
||||
`${repoPath(owner, repo)}/subscription`,
|
||||
{ subscribed: true, ignored: false },
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function unwatchRepo(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
return client.delete<void>(`${repoPath(owner, repo)}/subscription`, options);
|
||||
}
|
||||
|
||||
export interface ForkRepoInput {
|
||||
name?: string;
|
||||
organization?: string;
|
||||
}
|
||||
|
||||
export function forkRepository(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
input: ForkRepoInput = {},
|
||||
options?: RequestOptions,
|
||||
): Promise<Repository> {
|
||||
return client.post<Repository>(`${repoPath(owner, repo)}/forks`, input, options);
|
||||
}
|
||||
|
||||
// --- releases --------------------------------------------------------------
|
||||
|
||||
export function listReleases(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
params: PageParams = {},
|
||||
options?: RequestOptions,
|
||||
) {
|
||||
return client.raw<Release[]>(`${repoPath(owner, repo)}/releases`, {
|
||||
...options,
|
||||
query: { page: params.page ?? 1, limit: params.limit ?? 20 },
|
||||
});
|
||||
}
|
||||
|
||||
export function fetchRelease(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
id: number,
|
||||
options?: RequestOptions,
|
||||
): Promise<Release> {
|
||||
return client.get<Release>(`${repoPath(owner, repo)}/releases/${id}`, options);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Contents, README, branches, tags
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -44,6 +44,18 @@ export const queryKeys = {
|
||||
repoLanguages: (accountId: string, owner: string, name: string) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'languages'] as const,
|
||||
|
||||
repoStar: (accountId: string, owner: string, name: string) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'star'] as const,
|
||||
|
||||
repoSubscription: (accountId: string, owner: string, name: string) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'subscription'] as const,
|
||||
|
||||
releases: (accountId: string, owner: string, name: string, params: Record<string, unknown>) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'releases', params] as const,
|
||||
|
||||
release: (accountId: string, owner: string, name: string, id: number) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'release', id] as const,
|
||||
|
||||
contents: (accountId: string, owner: string, name: string, path: string, ref?: string) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'contents', { path, ref }] as const,
|
||||
|
||||
|
||||
@@ -349,6 +349,39 @@ export interface ServerVersion {
|
||||
version: string;
|
||||
}
|
||||
|
||||
/** A release asset (downloadable file). */
|
||||
export interface ReleaseAsset {
|
||||
id?: number;
|
||||
name?: string;
|
||||
size?: number;
|
||||
download_count?: number;
|
||||
browser_download_url?: string;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface Release {
|
||||
id?: number;
|
||||
tag_name?: string;
|
||||
target_commitish?: string;
|
||||
name?: string;
|
||||
body?: string;
|
||||
draft?: boolean;
|
||||
prerelease?: boolean;
|
||||
author?: User;
|
||||
created_at?: string;
|
||||
published_at?: string;
|
||||
html_url?: string;
|
||||
tarball_url?: string;
|
||||
zipball_url?: string;
|
||||
assets?: ReleaseAsset[];
|
||||
}
|
||||
|
||||
/** Repository watch subscription state. */
|
||||
export interface Subscription {
|
||||
subscribed?: boolean;
|
||||
ignored?: boolean;
|
||||
}
|
||||
|
||||
export interface Activity {
|
||||
id?: number;
|
||||
user_id?: number;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/** Instance capability detection (version parsing + feature gating). */
|
||||
|
||||
import { atLeast, parseGiteaVersion, supports } from './index';
|
||||
|
||||
describe('parseGiteaVersion', () => {
|
||||
it('parses plain versions', () => {
|
||||
expect(parseGiteaVersion('1.21.4')).toEqual({ major: 1, minor: 21, patch: 4, raw: '1.21.4' });
|
||||
});
|
||||
|
||||
it('tolerates suffixes and a leading v', () => {
|
||||
expect(parseGiteaVersion('v1.22.0+rc1')?.minor).toBe(22);
|
||||
expect(parseGiteaVersion('1.19.3-rc2')?.patch).toBe(3);
|
||||
});
|
||||
|
||||
it('defaults a missing patch to 0', () => {
|
||||
expect(parseGiteaVersion('1.21')?.patch).toBe(0);
|
||||
});
|
||||
|
||||
it('returns null for empty or invalid input', () => {
|
||||
expect(parseGiteaVersion(undefined)).toBeNull();
|
||||
expect(parseGiteaVersion('')).toBeNull();
|
||||
expect(parseGiteaVersion('development')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('atLeast', () => {
|
||||
const v = parseGiteaVersion('1.21.4');
|
||||
|
||||
it('compares major/minor/patch correctly', () => {
|
||||
expect(atLeast(v, 1, 21, 4)).toBe(true);
|
||||
expect(atLeast(v, 1, 21, 5)).toBe(false);
|
||||
expect(atLeast(v, 1, 22, 0)).toBe(false);
|
||||
expect(atLeast(v, 2, 0, 0)).toBe(false);
|
||||
expect(atLeast(v, 1, 20, 0)).toBe(true);
|
||||
});
|
||||
|
||||
it('treats an unknown version as too old', () => {
|
||||
expect(atLeast(null, 1, 0, 0)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('supports', () => {
|
||||
it('gates Actions on Gitea 1.19+', () => {
|
||||
expect(supports('actions', parseGiteaVersion('1.18.5'))).toBe(false);
|
||||
expect(supports('actions', parseGiteaVersion('1.19.0'))).toBe(true);
|
||||
expect(supports('actions', parseGiteaVersion('1.24.1'))).toBe(true);
|
||||
});
|
||||
|
||||
it('treats releases and wiki as widely available', () => {
|
||||
expect(supports('releases', parseGiteaVersion('1.9.0'))).toBe(true);
|
||||
expect(supports('wiki', parseGiteaVersion('1.0.0'))).toBe(true);
|
||||
});
|
||||
|
||||
it('is conservative for unknown instances', () => {
|
||||
expect(supports('packages', null)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Instance capability detection.
|
||||
*
|
||||
* Gitea feature availability varies by version and by instance config. Where an
|
||||
* API exposes a per-repository flag (e.g. `has_actions`) we prefer that; this
|
||||
* module fills the gaps for capabilities that have no flag by comparing the
|
||||
* server version reported at `/version`.
|
||||
*/
|
||||
|
||||
export interface GiteaVersion {
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
raw: string;
|
||||
}
|
||||
|
||||
/** Parses `1.21.0`, `1.22.0+rc1`, `1.19.3-rc1` … Returns null when unparseable. */
|
||||
export function parseGiteaVersion(raw: string | null | undefined): GiteaVersion | null {
|
||||
if (!raw) return null;
|
||||
const match = raw.match(/(\d+)\.(\d+)(?:\.(\d+))?/);
|
||||
if (!match) return null;
|
||||
return {
|
||||
major: Number(match[1]),
|
||||
minor: Number(match[2]),
|
||||
patch: Number(match[3] ?? 0),
|
||||
raw,
|
||||
};
|
||||
}
|
||||
|
||||
/** True when `version >= major.minor.patch`. Unknown versions are treated as unsupported. */
|
||||
export function atLeast(
|
||||
version: GiteaVersion | null,
|
||||
major: number,
|
||||
minor = 0,
|
||||
patch = 0,
|
||||
): boolean {
|
||||
if (!version) return false;
|
||||
if (version.major !== major) return version.major > major;
|
||||
if (version.minor !== minor) return version.minor > minor;
|
||||
return version.patch >= patch;
|
||||
}
|
||||
|
||||
export type Capability = 'releases' | 'wiki' | 'projects' | 'packages' | 'actions';
|
||||
|
||||
/** First Gitea release that shipped each capability. */
|
||||
export const CAPABILITY_SINCE: Record<Capability, [number, number, number]> = {
|
||||
wiki: [1, 0, 0],
|
||||
releases: [1, 9, 0],
|
||||
projects: [1, 12, 0],
|
||||
packages: [1, 14, 0],
|
||||
actions: [1, 19, 0],
|
||||
};
|
||||
|
||||
export function supports(capability: Capability, version: GiteaVersion | null): boolean {
|
||||
const [major, minor, patch] = CAPABILITY_SINCE[capability];
|
||||
return atLeast(version, major, minor, patch);
|
||||
}
|
||||
@@ -7,23 +7,35 @@
|
||||
import {
|
||||
keepPreviousData,
|
||||
useInfiniteQuery,
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
type InfiniteData,
|
||||
} from '@tanstack/react-query';
|
||||
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import {
|
||||
fetchIsStarred,
|
||||
fetchRelease,
|
||||
fetchRepository,
|
||||
fetchRepositoryLanguages,
|
||||
fetchSubscription,
|
||||
forkRepository,
|
||||
listMyRepos,
|
||||
listReleases,
|
||||
listStarredRepos,
|
||||
searchRepositories,
|
||||
starRepo,
|
||||
unstarRepo,
|
||||
unwatchRepo,
|
||||
watchRepo,
|
||||
type ForkRepoInput,
|
||||
type ListMyReposParams,
|
||||
type SearchReposParams,
|
||||
} from '@/core/api/endpoints';
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
import type { Repository } from '@/core/api/types';
|
||||
import type { Release, Repository, Subscription } from '@/core/api/types';
|
||||
|
||||
type RepoPage = RawResponse<Repository[]>;
|
||||
|
||||
@@ -107,3 +119,120 @@ export function useRepositoryLanguages(owner: string, name: string) {
|
||||
queryFn: ({ signal }) => fetchRepositoryLanguages(client!, owner, name, { signal }),
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Star / watch / fork
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function useIsStarred(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<boolean>({
|
||||
queryKey: queryKeys.repoStar(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId) && owner.length > 0,
|
||||
queryFn: ({ signal }) => fetchIsStarred(client!, owner, name, { signal }),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useToggleStar(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
const key = queryKeys.repoStar(accountId, owner, name);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (starred: boolean) =>
|
||||
starred ? unstarRepo(client!, owner, name) : starRepo(client!, owner, name),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: key });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repos.starred(accountId, { limit: 20 }) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.repoDetail(accountId, owner, name) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useSubscription(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<Subscription>({
|
||||
queryKey: queryKeys.repoSubscription(accountId, owner, name),
|
||||
enabled: Boolean(client) && Boolean(accountId) && owner.length > 0,
|
||||
queryFn: ({ signal }) => fetchSubscription(client!, owner, name, { signal }),
|
||||
staleTime: 60_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useToggleWatch(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
const key = queryKeys.repoSubscription(accountId, owner, name);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (watching: boolean): Promise<void> => {
|
||||
if (watching) {
|
||||
await unwatchRepo(client!, owner, name);
|
||||
} else {
|
||||
await watchRepo(client!, owner, name);
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: key });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useForkRepository(owner: string, name: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: ForkRepoInput) => forkRepository(client!, owner, name, input),
|
||||
onSuccess: () => {
|
||||
// A fork can appear in many repo lists; refresh the account's repo data.
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Releases
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export function useReleases(owner: string, name: string, limit = 20) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
const params = { limit };
|
||||
|
||||
return useInfiniteQuery<
|
||||
RawResponse<Release[]>,
|
||||
Error,
|
||||
InfiniteData<RawResponse<Release[]>>,
|
||||
readonly unknown[],
|
||||
number
|
||||
>({
|
||||
queryKey: queryKeys.releases(accountId, owner, name, params),
|
||||
enabled: Boolean(client) && Boolean(accountId),
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) =>
|
||||
listReleases(client!, owner, name, { ...params, page: pageParam }, { signal }),
|
||||
getNextPageParam: (last, all) => (last.hasMore ? all.length + 1 : undefined),
|
||||
placeholderData: keepPreviousData,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRelease(owner: string, name: string, id: number) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery({
|
||||
queryKey: queryKeys.release(accountId, owner, name, id),
|
||||
enabled: Boolean(client) && Boolean(accountId) && id > 0,
|
||||
queryFn: ({ signal }) => fetchRelease(client!, owner, name, id, { signal }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { Linking, Pressable, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Markdown } from '@/components/git/markdown';
|
||||
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 { 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 { formatBytes, formatDateTime } from '@/core/utils/format';
|
||||
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, 'ReleaseDetail'>;
|
||||
|
||||
/** One release: metadata, notes and downloadable assets. */
|
||||
export function ReleaseDetailScreen({ route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
const { instance } = useSession();
|
||||
const { owner, name, id } = route.params;
|
||||
|
||||
const query = useRelease(owner, name, id);
|
||||
const release = query.data;
|
||||
|
||||
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()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (!release) return null;
|
||||
|
||||
const assets = release.assets ?? [];
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<View style={styles.titleBlock}>
|
||||
<AppText variant="heading">{release.name || release.tag_name}</AppText>
|
||||
<View style={styles.badges}>
|
||||
{release.tag_name ? <Badge tone="primary" icon="tag">{release.tag_name}</Badge> : null}
|
||||
{release.prerelease ? <Badge tone="warning">{t('releases.prerelease')}</Badge> : null}
|
||||
{release.draft ? <Badge tone="neutral">{t('releases.draft')}</Badge> : null}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={styles.authorRow}>
|
||||
<Avatar url={release.author?.avatar_url} name={release.author?.login ?? '?'} size={28} />
|
||||
<AppText variant="bodyMedium" style={styles.authorName}>
|
||||
{release.author?.login ?? t('common.unknown')}
|
||||
</AppText>
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatDateTime(release.published_at ?? release.created_at)}
|
||||
</AppText>
|
||||
</View>
|
||||
|
||||
{release.body && release.body.trim().length > 0 ? (
|
||||
<Card>
|
||||
<Markdown content={release.body} baseUrl={instance?.baseUrl} />
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{assets.length > 0 ? (
|
||||
<>
|
||||
<AppText variant="subheading">{t('releases.assets')}</AppText>
|
||||
<Card padded={false} variant="flat">
|
||||
{assets.map((asset, index) => (
|
||||
<Pressable
|
||||
key={asset.id ?? asset.name ?? index}
|
||||
onPress={() =>
|
||||
asset.browser_download_url
|
||||
? void Linking.openURL(asset.browser_download_url).catch(() => undefined)
|
||||
: undefined
|
||||
}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={asset.name}
|
||||
style={[styles.assetRow, index < assets.length - 1 && styles.divider]}
|
||||
>
|
||||
<Icon name="download" size={18} color={colors.textTertiary} />
|
||||
<View style={styles.assetBody}>
|
||||
<AppText variant="bodyMedium" numberOfLines={1}>
|
||||
{asset.name}
|
||||
</AppText>
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{t('releases.downloads', {
|
||||
size: formatBytes(asset.size ?? 0),
|
||||
count: asset.download_count ?? 0,
|
||||
})}
|
||||
</AppText>
|
||||
</View>
|
||||
</Pressable>
|
||||
))}
|
||||
</Card>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
{release.html_url ? (
|
||||
<Button
|
||||
label={t('repo.viewOnInstance')}
|
||||
variant="secondary"
|
||||
iconLeft="externalLink"
|
||||
onPress={() => void Linking.openURL(release.html_url as string).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
titleBlock: { gap: spacing.sm },
|
||||
badges: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm, alignItems: 'center' },
|
||||
authorRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||
authorName: { flex: 1 },
|
||||
assetRow: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
divider: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: 'rgba(128,128,128,0.25)' },
|
||||
assetBody: { flex: 1, gap: 2 },
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
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 { Release } from '@/core/api/types';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import { formatDateTime } from '@/core/utils/format';
|
||||
import { useReleases } from '@/features/repositories/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoryStackParamList, 'Releases'>;
|
||||
|
||||
/** Repository releases (newest first). */
|
||||
export function ReleasesScreen({ navigation, route }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { owner, name } = route.params;
|
||||
|
||||
const query = useReleases(owner, name);
|
||||
const releases: Release[] = flattenPages(query.data);
|
||||
|
||||
return (
|
||||
<QueryList<Release>
|
||||
query={query}
|
||||
items={releases}
|
||||
keyExtractor={(release) => String(release.id ?? release.tag_name)}
|
||||
renderItem={(release) => (
|
||||
<View style={styles.row}>
|
||||
<AppText
|
||||
variant="bodyMedium"
|
||||
onPress={() =>
|
||||
release.id ? navigation.navigate('ReleaseDetail', { owner, name, id: release.id }) : undefined
|
||||
}
|
||||
accessibilityRole="button"
|
||||
>
|
||||
{release.name || release.tag_name}
|
||||
</AppText>
|
||||
<View style={styles.metaRow}>
|
||||
<Badge tone="neutral">{release.tag_name ?? ''}</Badge>
|
||||
{release.prerelease ? <Badge tone="warning">{t('releases.prerelease')}</Badge> : null}
|
||||
{release.draft ? <Badge tone="neutral">{t('releases.draft')}</Badge> : null}
|
||||
{release.published_at ? (
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{formatDateTime(release.published_at)}
|
||||
</AppText>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
empty={<EmptyState icon="tag" title={t('releases.empty')} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
gap: spacing.xs,
|
||||
},
|
||||
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Linking, StyleSheet, View } from 'react-native';
|
||||
import { Alert, Linking, StyleSheet, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Markdown } from '@/components/git/markdown';
|
||||
@@ -13,8 +13,17 @@ import { LabelChip } from '@/components/ui/label-chip';
|
||||
import { ListItem } from '@/components/ui/list-item';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
import { apiErrorMessage } from '@/core/api/error-text';
|
||||
import { parseGiteaVersion, supports } from '@/core/capabilities';
|
||||
import { buildEditorUrl } from '@/core/utils/editor-url';
|
||||
import { useRepository, useRepositoryLanguages } from '@/features/repositories/queries';
|
||||
import {
|
||||
useForkRepository,
|
||||
useIsStarred,
|
||||
useRepository,
|
||||
useRepositoryLanguages,
|
||||
useSubscription,
|
||||
useToggleStar,
|
||||
useToggleWatch,
|
||||
} from '@/features/repositories/queries';
|
||||
import { decodeBase64, useReadme } from '@/features/repository/queries';
|
||||
import { useSession } from '@/features/accounts/use-session';
|
||||
import { useSettingsStore } from '@/features/settings/settings-store';
|
||||
@@ -38,6 +47,35 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
||||
const readmeRef = ref ?? repo?.default_branch;
|
||||
const readmeQuery = useReadme(owner, name, readmeRef);
|
||||
const languagesQuery = useRepositoryLanguages(owner, name);
|
||||
const isStarred = useIsStarred(owner, name);
|
||||
const toggleStar = useToggleStar(owner, name);
|
||||
const subscription = useSubscription(owner, name);
|
||||
const toggleWatch = useToggleWatch(owner, name);
|
||||
const forkRepo = useForkRepository(owner, name);
|
||||
|
||||
const version = parseGiteaVersion(instance?.version);
|
||||
const repoUrl = instance ? `${instance.baseUrl}/${owner}/${name}` : null;
|
||||
|
||||
const confirmFork = () => {
|
||||
Alert.alert(t('repo.forkTitle'), t('repo.forkBody', { name }), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('repo.fork'),
|
||||
onPress: () =>
|
||||
forkRepo.mutate(
|
||||
{},
|
||||
{
|
||||
onSuccess: (forked) =>
|
||||
Alert.alert(
|
||||
t('repo.forkedTitle'),
|
||||
t('repo.forkedBody', { name: forked.full_name ?? name }),
|
||||
),
|
||||
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
|
||||
},
|
||||
),
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const languages = useMemo(() => {
|
||||
const entries = Object.entries(languagesQuery.data ?? {});
|
||||
@@ -127,6 +165,33 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<View style={styles.actionRow}>
|
||||
<Button
|
||||
label={isStarred.data ? t('repo.unstar') : t('repo.star')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft={isStarred.data ? 'star' : 'starOutline'}
|
||||
loading={toggleStar.isPending}
|
||||
onPress={() => toggleStar.mutate(isStarred.data ?? false)}
|
||||
/>
|
||||
<Button
|
||||
label={subscription.data?.subscribed ? t('repo.unwatch') : t('repo.watch')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft="bell"
|
||||
loading={toggleWatch.isPending}
|
||||
onPress={() => toggleWatch.mutate(subscription.data?.subscribed ?? false)}
|
||||
/>
|
||||
<Button
|
||||
label={t('repo.fork')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft="fork"
|
||||
loading={forkRepo.isPending}
|
||||
onPress={confirmFork}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Quick navigation */}
|
||||
@@ -155,6 +220,20 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
|
||||
title={t('repo.tags')}
|
||||
onPress={() => navigation.navigate('Tags', { owner, name })}
|
||||
/>
|
||||
{repo.has_releases !== false ? (
|
||||
<ListItem
|
||||
leadingIcon="download"
|
||||
title={t('releases.title')}
|
||||
onPress={() => navigation.navigate('Releases', { owner, name })}
|
||||
/>
|
||||
) : null}
|
||||
{repo.has_wiki && supports('wiki', version) && repoUrl ? (
|
||||
<ListItem
|
||||
leadingIcon="globe"
|
||||
title={t('repo.wiki')}
|
||||
onPress={() => void Linking.openURL(`${repoUrl}/wiki`).catch(() => undefined)}
|
||||
/>
|
||||
) : null}
|
||||
{repo.has_issues !== false ? (
|
||||
<ListItem
|
||||
leadingIcon="issue"
|
||||
@@ -299,6 +378,7 @@ const styles = StyleSheet.create({
|
||||
titleRow: { flexDirection: 'row', alignItems: 'baseline', flexWrap: 'wrap' },
|
||||
name: { flexShrink: 1 },
|
||||
badges: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm, alignItems: 'center' },
|
||||
actionRow: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
|
||||
section: { marginTop: spacing.xl, gap: spacing.sm },
|
||||
sectionTitle: { paddingHorizontal: spacing.lg },
|
||||
card: { marginHorizontal: spacing.lg },
|
||||
|
||||
@@ -154,6 +154,16 @@
|
||||
"noPermission": "You don't have permission to view this repository.",
|
||||
"viewOnInstance": "Open in browser",
|
||||
"openInEditor": "Open in editor",
|
||||
"star": "Star",
|
||||
"unstar": "Starred",
|
||||
"watch": "Watch",
|
||||
"unwatch": "Watching",
|
||||
"fork": "Fork",
|
||||
"forkTitle": "Fork this repository?",
|
||||
"forkBody": "A fork of {{name}} will be created under your account.",
|
||||
"forkedTitle": "Forked",
|
||||
"forkedBody": "Created {{name}}.",
|
||||
"wiki": "Wiki",
|
||||
"browse": "Browse",
|
||||
"empty": "This repository is empty",
|
||||
"noReadme": "No README file",
|
||||
@@ -315,6 +325,15 @@
|
||||
"deleteTitle": "Delete comment?",
|
||||
"deleteBody": "This comment will be permanently deleted."
|
||||
},
|
||||
"releases": {
|
||||
"title": "Releases",
|
||||
"detailTitle": "Release",
|
||||
"empty": "No releases yet",
|
||||
"prerelease": "Pre-release",
|
||||
"draft": "Draft",
|
||||
"assets": "Assets",
|
||||
"downloads": "{{size}} · {{count}} downloads"
|
||||
},
|
||||
"checks": {
|
||||
"success": "Checks passed",
|
||||
"pending": "Checks pending",
|
||||
|
||||
@@ -154,6 +154,16 @@
|
||||
"noPermission": "Je hebt geen rechten om deze repository te bekijken.",
|
||||
"viewOnInstance": "Openen in browser",
|
||||
"openInEditor": "Openen in editor",
|
||||
"star": "Ster",
|
||||
"unstar": "Gesterd",
|
||||
"watch": "Volgen",
|
||||
"unwatch": "Gevolgd",
|
||||
"fork": "Forken",
|
||||
"forkTitle": "Deze repository forken?",
|
||||
"forkBody": "Er wordt een fork van {{name}} onder jouw account aangemaakt.",
|
||||
"forkedTitle": "Geforkt",
|
||||
"forkedBody": "{{name}} is aangemaakt.",
|
||||
"wiki": "Wiki",
|
||||
"browse": "Bladeren",
|
||||
"empty": "Deze repository is leeg",
|
||||
"noReadme": "Geen README-bestand",
|
||||
@@ -315,6 +325,15 @@
|
||||
"deleteTitle": "Reactie verwijderen?",
|
||||
"deleteBody": "Deze reactie wordt permanent verwijderd."
|
||||
},
|
||||
"releases": {
|
||||
"title": "Releases",
|
||||
"detailTitle": "Release",
|
||||
"empty": "Nog geen releases",
|
||||
"prerelease": "Pre-release",
|
||||
"draft": "Concept",
|
||||
"assets": "Bestanden",
|
||||
"downloads": "{{size}} · {{count}} downloads"
|
||||
},
|
||||
"checks": {
|
||||
"success": "Checks geslaagd",
|
||||
"pending": "Checks in behandeling",
|
||||
|
||||
@@ -22,6 +22,8 @@ import { PullReviewScreen } from '@/features/repository/screens/pull-review-scre
|
||||
import { RepoIssuesScreen } from '@/features/repository/screens/repo-issues-screen';
|
||||
import { RepoOverviewScreen } from '@/features/repository/screens/repo-overview-screen';
|
||||
import { RepoPullsScreen } from '@/features/repository/screens/repo-pulls-screen';
|
||||
import { ReleaseDetailScreen } from '@/features/repository/screens/release-detail-screen';
|
||||
import { ReleasesScreen } from '@/features/repository/screens/releases-screen';
|
||||
import { TagsScreen } from '@/features/repository/screens/tags-screen';
|
||||
import { shortSha } from '@/core/utils/format';
|
||||
import { useStackScreenOptions } from '@/navigation/header-options';
|
||||
@@ -85,6 +87,16 @@ export function RepositoryNavigator() {
|
||||
options={{ title: t('repo.branches') }}
|
||||
/>
|
||||
<Stack.Screen name="Tags" component={TagsScreen} options={{ title: t('repo.tags') }} />
|
||||
<Stack.Screen
|
||||
name="Releases"
|
||||
component={ReleasesScreen}
|
||||
options={{ title: t('releases.title') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="ReleaseDetail"
|
||||
component={ReleaseDetailScreen}
|
||||
options={{ title: t('releases.detailTitle') }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="RepoIssues"
|
||||
component={RepoIssuesScreen}
|
||||
|
||||
@@ -49,6 +49,8 @@ export type RepositoryStackParamList = {
|
||||
CommitDetail: { owner: string; name: string; sha: string };
|
||||
Branches: { owner: string; name: string };
|
||||
Tags: { owner: string; name: string };
|
||||
Releases: { owner: string; name: string };
|
||||
ReleaseDetail: { owner: string; name: string; id: number };
|
||||
RepoIssues: { owner: string; name: string };
|
||||
IssueDetail: { owner: string; name: string; index: number };
|
||||
IssueCompose: { owner: string; name: string; index?: number };
|
||||
|
||||
Reference in new issue
Block a user