mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-02-13 21:00:00 +00:00
Custom vars for crons (#5897)
This commit is contained in:
@@ -4725,6 +4725,12 @@ const docTemplate = `{
|
||||
"schedule": {
|
||||
"description": "@weekly,\t3min, ...",
|
||||
"type": "string"
|
||||
},
|
||||
"variables": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -4742,6 +4748,12 @@ const docTemplate = `{
|
||||
},
|
||||
"schedule": {
|
||||
"type": "string"
|
||||
},
|
||||
"variables": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -128,6 +128,7 @@ func PostCron(c *gin.Context) {
|
||||
CreatorID: user.ID,
|
||||
Schedule: in.Schedule,
|
||||
Branch: in.Branch,
|
||||
Variables: in.Variables,
|
||||
Enabled: in.Enabled,
|
||||
}
|
||||
if err := cron.Validate(); err != nil {
|
||||
@@ -231,6 +232,9 @@ func PatchCron(c *gin.Context) {
|
||||
cron.NextExec = nextExec.Unix()
|
||||
}
|
||||
}
|
||||
if in.Variables != nil {
|
||||
cron.Variables = in.Variables
|
||||
}
|
||||
cron.CreatorID = user.ID
|
||||
|
||||
if err := cron.Validate(); err != nil {
|
||||
|
||||
@@ -137,13 +137,14 @@ func CreatePipeline(ctx context.Context, store store.Store, cron *model.Cron) (*
|
||||
}
|
||||
|
||||
return repo, &model.Pipeline{
|
||||
Event: model.EventCron,
|
||||
Commit: commit.SHA,
|
||||
Ref: "refs/heads/" + cron.Branch,
|
||||
Branch: cron.Branch,
|
||||
Message: cron.Name,
|
||||
Timestamp: cron.NextExec,
|
||||
Sender: cron.Name,
|
||||
ForgeURL: commit.ForgeURL,
|
||||
Event: model.EventCron,
|
||||
Commit: commit.SHA,
|
||||
Ref: "refs/heads/" + cron.Branch,
|
||||
Branch: cron.Branch,
|
||||
Message: cron.Name,
|
||||
Timestamp: cron.NextExec,
|
||||
Sender: cron.Name,
|
||||
ForgeURL: commit.ForgeURL,
|
||||
AdditionalVariables: cron.Variables,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -21,15 +21,16 @@ import (
|
||||
)
|
||||
|
||||
type Cron struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
Name string `json:"name" xorm:"name UNIQUE(s) INDEX"`
|
||||
RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"`
|
||||
CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"`
|
||||
NextExec int64 `json:"next_exec" xorm:"next_exec"`
|
||||
Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ...
|
||||
Created int64 `json:"created" xorm:"created NOT NULL DEFAULT 0"`
|
||||
Branch string `json:"branch" xorm:"branch"`
|
||||
Enabled bool `json:"enabled" xorm:"enabled NOT NULL DEFAULT TRUE"`
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
|
||||
Name string `json:"name" xorm:"name UNIQUE(s) INDEX"`
|
||||
RepoID int64 `json:"repo_id" xorm:"repo_id UNIQUE(s) INDEX"`
|
||||
CreatorID int64 `json:"creator_id" xorm:"creator_id INDEX"`
|
||||
NextExec int64 `json:"next_exec" xorm:"next_exec"`
|
||||
Schedule string `json:"schedule" xorm:"schedule NOT NULL"` // @weekly, 3min, ...
|
||||
Created int64 `json:"created" xorm:"created NOT NULL DEFAULT 0"`
|
||||
Branch string `json:"branch" xorm:"branch"`
|
||||
Enabled bool `json:"enabled" xorm:"enabled NOT NULL DEFAULT TRUE"`
|
||||
Variables map[string]string `json:"variables" xorm:"json 'variables'"`
|
||||
} // @name Cron
|
||||
|
||||
// TableName returns the database table name for xorm.
|
||||
@@ -56,8 +57,9 @@ func (c *Cron) Validate() error {
|
||||
}
|
||||
|
||||
type CronPatch struct {
|
||||
Name *string `json:"name"`
|
||||
Schedule *string `json:"schedule"`
|
||||
Branch *string `json:"branch"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Name *string `json:"name"`
|
||||
Schedule *string `json:"schedule"`
|
||||
Branch *string `json:"branch"`
|
||||
Enabled *bool `json:"enabled"`
|
||||
Variables map[string]string `json:"variables"`
|
||||
} // @name CronPatch
|
||||
|
||||
@@ -5,4 +5,5 @@ export interface Cron {
|
||||
schedule: string;
|
||||
enabled: boolean;
|
||||
next_exec: number;
|
||||
variables: Record<string, string>;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,18 @@
|
||||
<span v-else class="text-wp-text-100">{{ $t('repo.settings.crons.not_executed_yet') }}</span>
|
||||
</div>
|
||||
|
||||
<InputField v-slot="{ id }" :label="$t('repo.manual_pipeline.variables.title')">
|
||||
<span class="text-wp-text-alt-100 mb-2 text-sm">{{ $t('repo.manual_pipeline.variables.desc') }}</span>
|
||||
<KeyValueEditor
|
||||
:id="id"
|
||||
v-model="selectedCronVariables"
|
||||
:key-placeholder="$t('repo.manual_pipeline.variables.name')"
|
||||
:value-placeholder="$t('repo.manual_pipeline.variables.value')"
|
||||
:delete-title="$t('repo.manual_pipeline.variables.delete')"
|
||||
@update:is-valid="isVariablesValid = $event"
|
||||
/>
|
||||
</InputField>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<Button type="button" color="gray" :text="$t('cancel')" @click="selectedCron = undefined" />
|
||||
<Button
|
||||
@@ -109,6 +121,7 @@
|
||||
color="green"
|
||||
:is-loading="isSaving"
|
||||
:text="isEditingCron ? $t('repo.settings.crons.save') : $t('repo.settings.crons.add')"
|
||||
:disabled="!isFormValid"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
@@ -126,6 +139,7 @@ import IconButton from '~/components/atomic/IconButton.vue';
|
||||
import ListItem from '~/components/atomic/ListItem.vue';
|
||||
import Checkbox from '~/components/form/Checkbox.vue';
|
||||
import InputField from '~/components/form/InputField.vue';
|
||||
import KeyValueEditor from '~/components/form/KeyValueEditor.vue';
|
||||
import TextField from '~/components/form/TextField.vue';
|
||||
import Settings from '~/components/layout/Settings.vue';
|
||||
import useApiClient from '~/compositions/useApiClient';
|
||||
@@ -147,6 +161,15 @@ const selectedCron = ref<Partial<Cron>>();
|
||||
const isEditingCron = computed(() => !!selectedCron.value?.id);
|
||||
const date = useDate();
|
||||
|
||||
const selectedCronVariables = computed<Record<string, string>>({
|
||||
async set(_vars) {
|
||||
selectedCron.value!.variables = _vars;
|
||||
},
|
||||
get() {
|
||||
return selectedCron.value!.variables !== undefined ? selectedCron.value!.variables : {};
|
||||
},
|
||||
});
|
||||
|
||||
const selectedCronEnabled = computed<boolean>({
|
||||
async set(_enabled) {
|
||||
selectedCron.value!.enabled = _enabled;
|
||||
@@ -160,6 +183,12 @@ async function loadCrons(page: number): Promise<Cron[] | null> {
|
||||
return apiClient.getCronList(repo.value.id, { page });
|
||||
}
|
||||
|
||||
const isVariablesValid = ref(true);
|
||||
|
||||
const isFormValid = computed(() => {
|
||||
return isVariablesValid.value;
|
||||
});
|
||||
|
||||
const { resetPage, data: crons, loading } = usePagination(loadCrons, () => !selectedCron.value);
|
||||
|
||||
const { doSubmit: createCron, isLoading: isSaving } = useAsyncAction(async () => {
|
||||
|
||||
Reference in New Issue
Block a user