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)
|
// Admin (read-only)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ export const queryKeys = {
|
|||||||
issueAttachments: (accountId: string, owner: string, name: string, index: number) =>
|
issueAttachments: (accountId: string, owner: string, name: string, index: number) =>
|
||||||
[...queryKeys.issue(accountId, owner, name, index), 'attachments'] as const,
|
[...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 -------------------------------------------------------------
|
// --- actions -------------------------------------------------------------
|
||||||
actionsRoot: (accountId: string, owner: string, name: string) =>
|
actionsRoot: (accountId: string, owner: string, name: string) =>
|
||||||
[...queryKeys.repo(accountId, owner, name), 'actions'] as const,
|
[...queryKeys.repo(accountId, owner, name), 'actions'] as const,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
import type { RawResponse } from '@/core/api/client';
|
import type { RawResponse } from '@/core/api/client';
|
||||||
import {
|
import {
|
||||||
cancelActionRun,
|
cancelActionRun,
|
||||||
|
dispatchWorkflow,
|
||||||
fetchActionJobLogs,
|
fetchActionJobLogs,
|
||||||
fetchActionRun,
|
fetchActionRun,
|
||||||
listActionRunJobs,
|
listActionRunJobs,
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
listRunArtifacts,
|
listRunArtifacts,
|
||||||
listWorkflows,
|
listWorkflows,
|
||||||
rerunActionRun,
|
rerunActionRun,
|
||||||
|
type DispatchWorkflowInput,
|
||||||
type ListActionRunsParams,
|
type ListActionRunsParams,
|
||||||
} from '@/core/api/endpoints';
|
} from '@/core/api/endpoints';
|
||||||
import { queryKeys } from '@/core/api/query-keys';
|
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(
|
export function useActionRuns(
|
||||||
owner: string,
|
owner: string,
|
||||||
name: string,
|
name: string,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
import type { RawResponse } from '@/core/api/client';
|
import type { RawResponse } from '@/core/api/client';
|
||||||
import {
|
import {
|
||||||
addIssueReaction,
|
addIssueReaction,
|
||||||
|
checkIssueSubscription,
|
||||||
createIssue,
|
createIssue,
|
||||||
createIssueComment,
|
createIssueComment,
|
||||||
createPull,
|
createPull,
|
||||||
@@ -43,6 +44,8 @@ import {
|
|||||||
removeIssueReaction,
|
removeIssueReaction,
|
||||||
replyToReviewComment,
|
replyToReviewComment,
|
||||||
searchIssues,
|
searchIssues,
|
||||||
|
subscribeIssue,
|
||||||
|
unsubscribeIssue,
|
||||||
updateIssue,
|
updateIssue,
|
||||||
updateIssueComment,
|
updateIssueComment,
|
||||||
type CreateIssueInput,
|
type CreateIssueInput,
|
||||||
@@ -546,3 +549,48 @@ export function useIssueAttachments(owner: string, name: string, index: number)
|
|||||||
staleTime: 60_000,
|
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 { AppText } from '@/components/ui/app-text';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Card } from '@/components/ui/card';
|
import { Card } from '@/components/ui/card';
|
||||||
|
import { ChipSelect } from '@/components/ui/chip-select';
|
||||||
import { Field } from '@/components/ui/field';
|
import { Field } from '@/components/ui/field';
|
||||||
import { IconButton } from '@/components/ui/icon-button';
|
import { IconButton } from '@/components/ui/icon-button';
|
||||||
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
import { ErrorState, LoadingView } from '@/components/ui/state-views';
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
useRepoSecrets,
|
useRepoSecrets,
|
||||||
useRepoVariables,
|
useRepoVariables,
|
||||||
} from '@/features/repositories/settings-queries';
|
} from '@/features/repositories/settings-queries';
|
||||||
|
import { useDispatchWorkflow, useWorkflows } from '@/features/actions/queries';
|
||||||
import { spacing } from '@/theme/tokens';
|
import { spacing } from '@/theme/tokens';
|
||||||
import type { RepositoryStackParamList } from '@/navigation/types';
|
import type { RepositoryStackParamList } from '@/navigation/types';
|
||||||
import type { ScreenProps } from '@/navigation/typing';
|
import type { ScreenProps } from '@/navigation/typing';
|
||||||
@@ -40,6 +42,10 @@ export function ActionsSettingsScreen({ route }: Props) {
|
|||||||
const [secretValue, setSecretValue] = useState('');
|
const [secretValue, setSecretValue] = useState('');
|
||||||
const [varName, setVarName] = useState('');
|
const [varName, setVarName] = useState('');
|
||||||
const [varValue, setVarValue] = 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.isPending || variables.isPending) return <LoadingView />;
|
||||||
if (secrets.isError || variables.isError) {
|
if (secrets.isError || variables.isError) {
|
||||||
@@ -118,6 +124,41 @@ export function ActionsSettingsScreen({ route }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen scroll padded>
|
<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>
|
<AppText variant="subheading">{t('repoSettings.secrets')}</AppText>
|
||||||
<Card>
|
<Card>
|
||||||
<Field
|
<Field
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ import {
|
|||||||
useIssueAttachments,
|
useIssueAttachments,
|
||||||
useIssueComments,
|
useIssueComments,
|
||||||
useIssueReactions,
|
useIssueReactions,
|
||||||
|
useIssueSubscription,
|
||||||
useToggleIssueReaction,
|
useToggleIssueReaction,
|
||||||
|
useToggleIssueSubscription,
|
||||||
useUpdateIssue,
|
useUpdateIssue,
|
||||||
useUpdateIssueComment,
|
useUpdateIssueComment,
|
||||||
} from '@/features/issues/queries';
|
} from '@/features/issues/queries';
|
||||||
@@ -66,6 +68,8 @@ export function IssueDetailScreen({ navigation, route }: Props) {
|
|||||||
const reactionsQuery = useIssueReactions(owner, name, index);
|
const reactionsQuery = useIssueReactions(owner, name, index);
|
||||||
const toggleReaction = useToggleIssueReaction(owner, name, index);
|
const toggleReaction = useToggleIssueReaction(owner, name, index);
|
||||||
const attachmentsQuery = useIssueAttachments(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.isPending) return <LoadingView />;
|
||||||
if (query.isError) {
|
if (query.isError) {
|
||||||
@@ -121,6 +125,16 @@ export function IssueDetailScreen({ navigation, route }: Props) {
|
|||||||
loading={updateIssue.isPending}
|
loading={updateIssue.isPending}
|
||||||
onPress={toggleState}
|
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>
|
||||||
|
|
||||||
<View style={styles.authorRow}>
|
<View style={styles.authorRow}>
|
||||||
|
|||||||
@@ -239,6 +239,8 @@
|
|||||||
"milestone": "Milestone",
|
"milestone": "Milestone",
|
||||||
"noDescription": "No description provided",
|
"noDescription": "No description provided",
|
||||||
"notFound": "This issue could not be found.",
|
"notFound": "This issue could not be found.",
|
||||||
|
"subscribe": "Subscribe",
|
||||||
|
"unsubscribe": "Unsubscribe",
|
||||||
"reopen": "Reopen",
|
"reopen": "Reopen",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"compose": {
|
"compose": {
|
||||||
@@ -450,7 +452,11 @@
|
|||||||
"newOwnerPlaceholder": "username or organization",
|
"newOwnerPlaceholder": "username or organization",
|
||||||
"transferAction": "Transfer",
|
"transferAction": "Transfer",
|
||||||
"transferTitle": "Transfer repository?",
|
"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": {
|
"createRepo": {
|
||||||
"title": "New repository",
|
"title": "New repository",
|
||||||
|
|||||||
@@ -239,6 +239,8 @@
|
|||||||
"milestone": "Mijlpaal",
|
"milestone": "Mijlpaal",
|
||||||
"noDescription": "Geen beschrijving opgegeven",
|
"noDescription": "Geen beschrijving opgegeven",
|
||||||
"notFound": "Deze issue kon niet worden gevonden.",
|
"notFound": "Deze issue kon niet worden gevonden.",
|
||||||
|
"subscribe": "Volgen",
|
||||||
|
"unsubscribe": "Niet meer volgen",
|
||||||
"reopen": "Heropenen",
|
"reopen": "Heropenen",
|
||||||
"close": "Sluiten",
|
"close": "Sluiten",
|
||||||
"compose": {
|
"compose": {
|
||||||
@@ -450,7 +452,11 @@
|
|||||||
"newOwnerPlaceholder": "gebruikersnaam of organisatie",
|
"newOwnerPlaceholder": "gebruikersnaam of organisatie",
|
||||||
"transferAction": "Overdragen",
|
"transferAction": "Overdragen",
|
||||||
"transferTitle": "Repository 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": {
|
"createRepo": {
|
||||||
"title": "Nieuwe repository",
|
"title": "Nieuwe repository",
|
||||||
|
|||||||
Reference in new issue
Block a user