1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
<script>
import { GlForm, GlButton } from '@gitlab/ui';
import RunnerFormFields from '~/ci/runner/components/runner_form_fields.vue';
import runnerCreateMutation from '~/ci/runner/graphql/new/runner_create.mutation.graphql';
import { modelToUpdateMutationVariables } from 'ee_else_ce/ci/runner/runner_update_form_utils';
import { captureException } from '../sentry_utils';
import { RUNNER_TYPES, DEFAULT_ACCESS_LEVEL, PROJECT_TYPE, GROUP_TYPE } from '../constants';
export default {
name: 'RunnerCreateForm',
components: {
GlForm,
GlButton,
RunnerFormFields,
},
props: {
runnerType: {
type: String,
required: true,
validator: (t) => RUNNER_TYPES.includes(t),
},
groupId: {
type: String,
required: false,
default: null,
},
projectId: {
type: String,
required: false,
default: null,
},
},
data() {
return {
saving: false,
runner: {
runnerType: this.runnerType,
description: '',
maintenanceNote: '',
paused: false,
accessLevel: DEFAULT_ACCESS_LEVEL,
runUntagged: false,
locked: false,
tagList: '',
maximumTimeout: '',
},
};
},
computed: {
mutationInput() {
const { input } = modelToUpdateMutationVariables(this.runner);
if (this.runnerType === GROUP_TYPE) {
return {
...input,
groupId: this.groupId,
};
}
if (this.runnerType === PROJECT_TYPE) {
return {
...input,
projectId: this.projectId,
};
}
return input;
},
},
methods: {
async onSubmit() {
this.saving = true;
try {
const {
data: {
runnerCreate: { errors, runner },
},
} = await this.$apollo.mutate({
mutation: runnerCreateMutation,
variables: {
input: this.mutationInput,
},
});
if (errors?.length) {
this.$emit('error', new Error(errors.join(' ')));
this.saving = false;
} else {
this.onSuccess(runner);
}
} catch (error) {
captureException({ error, component: this.$options.name });
this.$emit('error', error);
this.saving = false;
}
},
onSuccess(runner) {
this.$emit('saved', runner);
},
},
};
</script>
<template>
<gl-form @submit.prevent="onSubmit">
<runner-form-fields v-model="runner" />
<div class="gl-display-flex gl-mt-6">
<gl-button type="submit" variant="confirm" class="js-no-auto-disable" :loading="saving">
{{ s__('Runners|Create runner') }}
</gl-button>
</div>
</gl-form>
</template>
|