summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/security_configuration/components/manage_sast.vue
blob: 8a8827b41cd420837bde83673faeaefed07626cc (plain)
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
<script>
import { GlButton } from '@gitlab/ui';
import { redirectTo } from '~/lib/utils/url_utility';
import { s__ } from '~/locale';
import configureSastMutation from '~/security_configuration/graphql/configure_sast.mutation.graphql';

export default {
  components: {
    GlButton,
  },
  inject: {
    projectPath: {
      from: 'projectPath',
      default: '',
    },
  },
  data() {
    return {
      isLoading: false,
    };
  },
  methods: {
    async mutate() {
      this.isLoading = true;
      try {
        const { data } = await this.$apollo.mutate({
          mutation: configureSastMutation,
          variables: {
            input: {
              projectPath: this.projectPath,
              configuration: { global: [], pipeline: [], analyzers: [] },
            },
          },
        });
        const { errors, successPath } = data.configureSast;

        if (errors.length > 0) {
          throw new Error(errors[0]);
        }

        if (!successPath) {
          throw new Error(s__('SecurityConfiguration|SAST merge request creation mutation failed'));
        }

        redirectTo(successPath);
      } catch (e) {
        this.$emit('error', e.message);
        this.isLoading = false;
      }
    },
  },
};
</script>

<template>
  <gl-button :loading="isLoading" variant="success" category="secondary" @click="mutate">{{
    s__('SecurityConfiguration|Configure via merge request')
  }}</gl-button>
</template>