summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/states/mr_widget_merged.vue
blob: 8184ef3302236dd6d5e5e297e8dfb1f8f7e532c3 (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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<script>
  import Flash from '~/flash';
  import tooltip from '~/vue_shared/directives/tooltip';
  import { s__, __ } from '~/locale';
  import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
  import MrWidgetAuthorTime from '../../components/mr_widget_author_time.vue';
  import statusIcon from '../mr_widget_status_icon.vue';
  import eventHub from '../../event_hub';

  export default {
    name: 'MRWidgetMerged',
    directives: {
      tooltip,
    },
    components: {
      MrWidgetAuthorTime,
      statusIcon,
      ClipboardButton,
    },
    props: {
      mr: {
        type: Object,
        required: true,
        default: () => ({}),
      },
      service: {
        type: Object,
        required: true,
        default: () => ({}),
      },
    },
    data() {
      return {
        isMakingRequest: false,
      };
    },
    computed: {
      shouldShowRemoveSourceBranch() {
        const {
          sourceBranchRemoved,
          isRemovingSourceBranch,
          canRemoveSourceBranch,
        } = this.mr;

        return !sourceBranchRemoved &&
          canRemoveSourceBranch &&
          !this.isMakingRequest &&
          !isRemovingSourceBranch;
      },
      shouldShowSourceBranchRemoving() {
        const {
          sourceBranchRemoved,
          isRemovingSourceBranch,
        } = this.mr;
        return !sourceBranchRemoved &&
          (isRemovingSourceBranch || this.isMakingRequest);
      },
      shouldShowMergedButtons() {
        const {
          canRevertInCurrentMR,
          canCherryPickInCurrentMR,
          revertInForkPath,
          cherryPickInForkPath,
        } = this.mr;

        return canRevertInCurrentMR ||
          canCherryPickInCurrentMR ||
          revertInForkPath ||
          cherryPickInForkPath;
      },
      revertTitle() {
        return s__('mrWidget|Revert this merge request in a new merge request');
      },
      cherryPickTitle() {
        return s__('mrWidget|Cherry-pick this merge request in a new merge request');
      },
      revertLabel() {
        return s__('mrWidget|Revert');
      },
      cherryPickLabel() {
        return s__('mrWidget|Cherry-pick');
      },
    },
    methods: {
      removeSourceBranch() {
        this.isMakingRequest = true;

        this.service.removeSourceBranch()
          .then(res => res.data)
          .then((data) => {
            if (data.message === 'Branch was removed') {
              eventHub.$emit('MRWidgetUpdateRequested', () => {
                this.isMakingRequest = false;
              });
            }
          })
          .catch(() => {
            this.isMakingRequest = false;
            Flash(__('Something went wrong. Please try again.'));
          });
      },
    },
  };
</script>
<template>
  <div class="mr-widget-body media">
    <status-icon status="success" />
    <div class="media-body">
      <div class="space-children">
        <mr-widget-author-time
          :action-text="s__('mrWidget|Merged by')"
          :author="mr.metrics.mergedBy"
          :date-title="mr.metrics.mergedAt"
          :date-readable="mr.metrics.readableMergedAt"
        />
        <a
          v-if="mr.canRevertInCurrentMR"
          v-tooltip
          :title="revertTitle"
          class="btn btn-close btn-sm"
          href="#modal-revert-commit"
          data-toggle="modal"
          data-container="body"
        >
          {{ revertLabel }}
        </a>
        <a
          v-else-if="mr.revertInForkPath"
          v-tooltip
          :href="mr.revertInForkPath"
          :title="revertTitle"
          class="btn btn-close btn-sm"
          data-method="post"
        >
          {{ revertLabel }}
        </a>
        <a
          v-if="mr.canCherryPickInCurrentMR"
          v-tooltip
          :title="cherryPickTitle"
          class="btn btn-default btn-sm"
          href="#modal-cherry-pick-commit"
          data-toggle="modal"
          data-container="body"
        >
          {{ cherryPickLabel }}
        </a>
        <a
          v-else-if="mr.cherryPickInForkPath"
          v-tooltip
          :href="mr.cherryPickInForkPath"
          :title="cherryPickTitle"
          class="btn btn-default btn-sm"
          data-method="post"
        >
          {{ cherryPickLabel }}
        </a>
      </div>
      <section class="mr-info-list">
        <p>
          {{ s__("mrWidget|The changes were merged into") }}
          <span class="label-branch">
            <a :href="mr.targetBranchPath">{{ mr.targetBranch }}</a>
          </span>
          with
          <a
            :href="mr.mergeCommitPath"
            class="commit-sha js-mr-merged-commit-sha"
            v-text="mr.shortMergeCommitSha"
          >
          </a>
          <clipboard-button
            :title="__('Copy commit SHA to clipboard')"
            :text="mr.mergeCommitSha"
            css-class="btn-default btn-transparent btn-clipboard js-mr-merged-copy-sha"
          />
        </p>
        <p v-if="mr.sourceBranchRemoved">
          {{ s__("mrWidget|The source branch has been removed") }}
        </p>
        <p
          v-if="shouldShowRemoveSourceBranch"
          class="space-children"
        >
          <span>{{ s__("mrWidget|You can remove source branch now") }}</span>
          <button
            :disabled="isMakingRequest"
            type="button"
            class="btn btn-sm btn-default js-remove-branch-button"
            @click="removeSourceBranch"
          >
            {{ s__("mrWidget|Remove Source Branch") }}
          </button>
        </p>
        <p v-if="shouldShowSourceBranchRemoving">
          <gl-loading-icon :inline="true" />
          <span>
            {{ s__("mrWidget|The source branch is being removed") }}
          </span>
        </p>
      </section>
    </div>
  </div>
</template>