Allow to run cron manually (#1338)

Closes #1154
This commit is contained in:
qwerty287
2022-10-26 01:23:28 +02:00
committed by GitHub
parent ed44c3b50f
commit de4e62cfcf
11 changed files with 76 additions and 16 deletions
+1
View File
@@ -154,6 +154,7 @@
"deleted": "Cron deleted",
"next_exec": "Next execution",
"not_executed_yet": "Not executed yet",
"run": "Run now",
"branch": {
"title": "Branch",
"placeholder": "Branch (uses default branch if empty)"
+3 -1
View File
@@ -41,6 +41,7 @@
<i-icon-park-outline-alarm-clock v-else-if="name === 'stopwatch'" class="h-6 w-6" />
<i-ic-baseline-file-download v-else-if="name === 'auto-scroll'" class="h-6 w-6" />
<i-ic-baseline-file-download-off v-else-if="name === 'auto-scroll-off'" class="h-6 w-6" />
<i-ic-baseline-play-arrow v-else-if="name === 'play'" class="h-6 w-6" />
<div v-else-if="name === 'blank'" class="h-6 w-6" />
</template>
@@ -90,7 +91,8 @@ export type IconNames =
| 'stopwatch'
| 'download'
| 'auto-scroll'
| 'auto-scroll-off';
| 'auto-scroll-off'
| 'play';
export default defineComponent({
name: 'Icon',
+19 -6
View File
@@ -31,12 +31,8 @@
{{ $t('repo.settings.crons.next_exec') }}: {{ date.toLocaleString(new Date(cron.next_exec * 1000)) }}</span
>
<span v-else class="ml-auto">{{ $t('repo.settings.crons.not_executed_yet') }}</span>
<IconButton
icon="edit"
class="ml-auto w-8 h-8"
:title="$t('repo.settings.crons.edit')"
@click="selectedCron = cron"
/>
<IconButton icon="play" class="ml-auto w-8 h-8" :title="$t('repo.settings.crons.run')" @click="runCron(cron)" />
<IconButton icon="edit" class="w-8 h-8" :title="$t('repo.settings.crons.edit')" @click="selectedCron = cron" />
<IconButton
icon="trash"
class="w-8 h-8 hover:text-red-400 hover:dark:text-red-500"
@@ -105,6 +101,7 @@ import { useAsyncAction } from '~/compositions/useAsyncAction';
import { useDate } from '~/compositions/useDate';
import useNotifications from '~/compositions/useNotifications';
import { Cron, Repo } from '~/lib/api/types';
import router from '~/router';
const apiClient = useApiClient();
const notifications = useNotifications();
@@ -156,6 +153,22 @@ const { doSubmit: deleteCron, isLoading: isDeleting } = useAsyncAction(async (_c
await loadCrons();
});
const { doSubmit: runCron } = useAsyncAction(async (_cron: Cron) => {
if (!repo?.value) {
throw new Error("Unexpected: Can't load repo");
}
const pipeline = await apiClient.runCron(repo.value.owner, repo.value.name, _cron.id);
await router.push({
name: 'repo-pipeline',
params: {
repoOwner: repo.value.owner,
repoName: repo.value.name,
pipelineId: pipeline.number,
},
});
});
onMounted(async () => {
await loadCrons();
});
@@ -166,16 +166,16 @@ export default defineComponent({
text: i18n.t('repo.settings.general.visibility.public.public'),
description: i18n.t('repo.settings.general.visibility.public.desc'),
},
{
value: RepoVisibility.Private,
text: i18n.t('repo.settings.general.visibility.private.private'),
description: i18n.t('repo.settings.general.visibility.private.desc'),
},
{
value: RepoVisibility.Internal,
text: i18n.t('repo.settings.general.visibility.internal.internal'),
description: i18n.t('repo.settings.general.visibility.internal.desc'),
},
{
value: RepoVisibility.Private,
text: i18n.t('repo.settings.general.visibility.private.private'),
description: i18n.t('repo.settings.general.visibility.private.desc'),
},
];
const cancelPreviousPipelineEventsOptions: CheckboxOption[] = [
+4
View File
@@ -162,6 +162,10 @@ export default class WoodpeckerClient extends ApiClient {
return this._delete(`/api/repos/${owner}/${repo}/cron/${cronId}`);
}
runCron(owner: string, repo: string, cronId: number): Promise<Pipeline> {
return this._post(`/api/repos/${owner}/${repo}/cron/${cronId}`) as Promise<Pipeline>;
}
getOrgPermissions(owner: string): Promise<OrgPermissions> {
return this._get(`/api/orgs/${owner}/permissions`) as Promise<OrgPermissions>;
}