feat: issue subscriptions and Actions workflow dispatch
- subscribe/unsubscribe to an issue from the detail screen - dispatch a workflow_dispatch run (workflow + ref) from Actions settings - i18n (en/nl)
This commit is contained in:
1 parent
eed9c91274
commit
207ac723af
8 files changed
+178
-2
No files matched your search
@@ -1686,6 +1686,47 @@ export function listIssueAttachments(
|
||||
);
|
||||
}
|
||||
|
||||
// --- issue subscriptions ---------------------------------------------------
|
||||
|
||||
export function checkIssueSubscription(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
index: number,
|
||||
options?: RequestOptions,
|
||||
): Promise<{ subscribed?: boolean }> {
|
||||
return client.get(`${repoPath(owner, repo)}/issues/${index}/subscriptions/check`, options);
|
||||
}
|
||||
|
||||
export function subscribeIssue(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
index: number,
|
||||
user: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<void> {
|
||||
return client.put<void>(
|
||||
`${repoPath(owner, repo)}/issues/${index}/subscriptions/${enc(user)}`,
|
||||
undefined,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function unsubscribeIssue(
|
||||
client: GiteaClient,
|
||||
owner: string,
|
||||
repo: string,
|
||||
index: number,
|
||||
user: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<void> {
|
||||
return client.delete<void>(
|
||||
`${repoPath(owner, repo)}/issues/${index}/subscriptions/${enc(user)}`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Admin (read-only)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -87,6 +87,9 @@ export const queryKeys = {
|
||||
issueAttachments: (accountId: string, owner: string, name: string, index: number) =>
|
||||
[...queryKeys.issue(accountId, owner, name, index), 'attachments'] as const,
|
||||
|
||||
issueSubscription: (accountId: string, owner: string, name: string, index: number, user: string) =>
|
||||
[...queryKeys.issue(accountId, owner, name, index), 'subscription', user] as const,
|
||||
|
||||
// --- actions -------------------------------------------------------------
|
||||
actionsRoot: (accountId: string, owner: string, name: string) =>
|
||||
[...queryKeys.repo(accountId, owner, name), 'actions'] as const,
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
cancelActionRun,
|
||||
dispatchWorkflow,
|
||||
fetchActionJobLogs,
|
||||
fetchActionRun,
|
||||
listActionRunJobs,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
listRunArtifacts,
|
||||
listWorkflows,
|
||||
rerunActionRun,
|
||||
type DispatchWorkflowInput,
|
||||
type ListActionRunsParams,
|
||||
} from '@/core/api/endpoints';
|
||||
import { queryKeys } from '@/core/api/query-keys';
|
||||
@@ -38,6 +40,21 @@ export function useWorkflows(owner: string, name: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Dispatch a workflow run (`workflow_dispatch`). */
|
||||
export function useDispatchWorkflow(owner: string, name: string, workflowId: string) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (input: DispatchWorkflowInput) =>
|
||||
dispatchWorkflow(client!, owner, name, workflowId, input),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.actionsRoot(accountId, owner, name) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useActionRuns(
|
||||
owner: string,
|
||||
name: string,
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import type { RawResponse } from '@/core/api/client';
|
||||
import {
|
||||
addIssueReaction,
|
||||
checkIssueSubscription,
|
||||
createIssue,
|
||||
createIssueComment,
|
||||
createPull,
|
||||
@@ -43,6 +44,8 @@ import {
|
||||
removeIssueReaction,
|
||||
replyToReviewComment,
|
||||
searchIssues,
|
||||
subscribeIssue,
|
||||
unsubscribeIssue,
|
||||
updateIssue,
|
||||
updateIssueComment,
|
||||
type CreateIssueInput,
|
||||
@@ -546,3 +549,48 @@ export function useIssueAttachments(owner: string, name: string, index: number)
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useIssueSubscription(
|
||||
owner: string,
|
||||
name: string,
|
||||
index: number,
|
||||
user: string | undefined,
|
||||
) {
|
||||
const { client, account } = useSession();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useQuery<{ subscribed?: boolean }>({
|
||||
queryKey: queryKeys.issueSubscription(accountId, owner, name, index, user ?? ''),
|
||||
enabled: Boolean(client) && Boolean(accountId) && index > 0 && Boolean(user),
|
||||
queryFn: ({ signal }) => checkIssueSubscription(client!, owner, name, index, { signal }),
|
||||
staleTime: 60_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useToggleIssueSubscription(
|
||||
owner: string,
|
||||
name: string,
|
||||
index: number,
|
||||
user: string | undefined,
|
||||
) {
|
||||
const { client, account } = useSession();
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = account?.id ?? '';
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (subscribed: boolean): Promise<void> => {
|
||||
if (!user) return;
|
||||
if (subscribed) {
|
||||
await unsubscribeIssue(client!, owner, name, index, user);
|
||||
} else {
|
||||
await subscribeIssue(client!, owner, name, index, user);
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.issueSubscription(accountId, owner, name, index, user ?? ''),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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 { ChipSelect } from '@/components/ui/chip-select';
|
||||
import { Field } from '@/components/ui/field';
|
||||
import { IconButton } from '@/components/ui/icon-button';
|
||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
useRepoSecrets,
|
||||
useRepoVariables,
|
||||
} from '@/features/repositories/settings-queries';
|
||||
import { useDispatchWorkflow, useWorkflows } from '@/features/actions/queries';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
@@ -40,6 +42,10 @@ export function ActionsSettingsScreen({ route }: Props) {
|
||||
const [secretValue, setSecretValue] = useState('');
|
||||
const [varName, setVarName] = useState('');
|
||||
const [varValue, setVarValue] = useState('');
|
||||
const workflows = useWorkflows(owner, name);
|
||||
const [selectedWorkflow, setSelectedWorkflow] = useState<string | null>(null);
|
||||
const [dispatchRefName, setDispatchRefName] = useState('');
|
||||
const dispatch = useDispatchWorkflow(owner, name, selectedWorkflow ?? '');
|
||||
|
||||
if (secrets.isPending || variables.isPending) return <LoadingView />;
|
||||
if (secrets.isError || variables.isError) {
|
||||
@@ -118,6 +124,41 @@ export function ActionsSettingsScreen({ route }: Props) {
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<AppText variant="subheading">{t('repoSettings.runWorkflow')}</AppText>
|
||||
<Card>
|
||||
<ChipSelect
|
||||
options={(workflows.data ?? []).map((workflow) => ({
|
||||
id: String(workflow.id),
|
||||
label: workflow.name ?? workflow.path ?? '',
|
||||
}))}
|
||||
selectedIds={selectedWorkflow ? [selectedWorkflow] : []}
|
||||
onToggle={(id) => setSelectedWorkflow(id)}
|
||||
emptyLabel={t('repoSettings.noWorkflows')}
|
||||
single
|
||||
/>
|
||||
<Field
|
||||
label={t('repoSettings.ref')}
|
||||
value={dispatchRefName}
|
||||
onChangeText={setDispatchRefName}
|
||||
placeholder="main"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
/>
|
||||
<Button
|
||||
label={t('repoSettings.dispatch')}
|
||||
onPress={() =>
|
||||
dispatch.mutate(
|
||||
{ ref: dispatchRefName.trim() },
|
||||
{ onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)) },
|
||||
)
|
||||
}
|
||||
loading={dispatch.isPending}
|
||||
disabled={!selectedWorkflow || dispatchRefName.trim().length === 0}
|
||||
fullWidth
|
||||
style={styles.spaced}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<AppText variant="subheading">{t('repoSettings.secrets')}</AppText>
|
||||
<Card>
|
||||
<Field
|
||||
|
||||
@@ -26,7 +26,9 @@ import {
|
||||
useIssueAttachments,
|
||||
useIssueComments,
|
||||
useIssueReactions,
|
||||
useIssueSubscription,
|
||||
useToggleIssueReaction,
|
||||
useToggleIssueSubscription,
|
||||
useUpdateIssue,
|
||||
useUpdateIssueComment,
|
||||
} from '@/features/issues/queries';
|
||||
@@ -66,6 +68,8 @@ export function IssueDetailScreen({ navigation, route }: Props) {
|
||||
const reactionsQuery = useIssueReactions(owner, name, index);
|
||||
const toggleReaction = useToggleIssueReaction(owner, name, index);
|
||||
const attachmentsQuery = useIssueAttachments(owner, name, index);
|
||||
const subscription = useIssueSubscription(owner, name, index, account?.login);
|
||||
const toggleSubscription = useToggleIssueSubscription(owner, name, index, account?.login);
|
||||
|
||||
if (query.isPending) return <LoadingView />;
|
||||
if (query.isError) {
|
||||
@@ -121,6 +125,16 @@ export function IssueDetailScreen({ navigation, route }: Props) {
|
||||
loading={updateIssue.isPending}
|
||||
onPress={toggleState}
|
||||
/>
|
||||
{account?.login ? (
|
||||
<Button
|
||||
label={subscription.data?.subscribed ? t('issues.unsubscribe') : t('issues.subscribe')}
|
||||
variant="secondary"
|
||||
size="md"
|
||||
iconLeft="bell"
|
||||
loading={toggleSubscription.isPending}
|
||||
onPress={() => toggleSubscription.mutate(subscription.data?.subscribed ?? false)}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
<View style={styles.authorRow}>
|
||||
|
||||
@@ -239,6 +239,8 @@
|
||||
"milestone": "Milestone",
|
||||
"noDescription": "No description provided",
|
||||
"notFound": "This issue could not be found.",
|
||||
"subscribe": "Subscribe",
|
||||
"unsubscribe": "Unsubscribe",
|
||||
"reopen": "Reopen",
|
||||
"close": "Close",
|
||||
"compose": {
|
||||
@@ -450,7 +452,11 @@
|
||||
"newOwnerPlaceholder": "username or organization",
|
||||
"transferAction": "Transfer",
|
||||
"transferTitle": "Transfer repository?",
|
||||
"transferBody": "{{name}} will be transferred to {{owner}}."
|
||||
"transferBody": "{{name}} will be transferred to {{owner}}.",
|
||||
"runWorkflow": "Run workflow",
|
||||
"noWorkflows": "No dispatchable workflows",
|
||||
"ref": "Ref (branch or tag)",
|
||||
"dispatch": "Dispatch"
|
||||
},
|
||||
"createRepo": {
|
||||
"title": "New repository",
|
||||
|
||||
@@ -239,6 +239,8 @@
|
||||
"milestone": "Mijlpaal",
|
||||
"noDescription": "Geen beschrijving opgegeven",
|
||||
"notFound": "Deze issue kon niet worden gevonden.",
|
||||
"subscribe": "Volgen",
|
||||
"unsubscribe": "Niet meer volgen",
|
||||
"reopen": "Heropenen",
|
||||
"close": "Sluiten",
|
||||
"compose": {
|
||||
@@ -450,7 +452,11 @@
|
||||
"newOwnerPlaceholder": "gebruikersnaam of organisatie",
|
||||
"transferAction": "Overdragen",
|
||||
"transferTitle": "Repository overdragen?",
|
||||
"transferBody": "{{name}} wordt overgedragen aan {{owner}}."
|
||||
"transferBody": "{{name}} wordt overgedragen aan {{owner}}.",
|
||||
"runWorkflow": "Workflow uitvoeren",
|
||||
"noWorkflows": "Geen uitvoerbare workflows",
|
||||
"ref": "Ref (branch of tag)",
|
||||
"dispatch": "Starten"
|
||||
},
|
||||
"createRepo": {
|
||||
"title": "Nieuwe repository",
|
||||
|
||||
Reference in new issue
Block a user