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
113
114
115
116
117
118
119
120
|
<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,
INSTANCE_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: {
description: '',
maintenanceNote: '',
paused: false,
accessLevel: DEFAULT_ACCESS_LEVEL,
runUntagged: false,
tagList: '',
maximumTimeout: '',
},
};
},
computed: {
mutationInput() {
const { input } = modelToUpdateMutationVariables(this.runner);
if (this.runnerType === GROUP_TYPE) {
return {
...input,
runnerType: GROUP_TYPE,
groupId: this.groupId,
};
}
if (this.runnerType === PROJECT_TYPE) {
return {
...input,
runnerType: PROJECT_TYPE,
projectId: this.projectId,
};
}
return {
...input,
runnerType: INSTANCE_TYPE,
};
},
},
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(' ')));
} else {
this.onSuccess(runner);
}
} catch (error) {
captureException({ error, component: this.$options.name });
this.$emit('error', error);
} finally {
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-button type="submit" variant="confirm" class="js-no-auto-disable" :loading="saving">
{{ __('Submit') }}
</gl-button>
</div>
</gl-form>
</template>
|