Welcome to mirror list, hosted at ThFree Co, Russian Federation.

added_commit_message.vue « components « vue_merge_request_widget « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f377a1858799476efa8534f1a9ae60b7c94471c4 (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
<script>
import { GlSprintf, GlLink } from '@gitlab/ui';
import { escape } from 'lodash';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { n__, s__, sprintf } from '~/locale';

const mergeCommitCount = s__('mrWidgetCommitsAdded|%{strongStart}1%{strongEnd} merge commit');

export default {
  components: {
    GlSprintf,
    GlLink,
  },
  mixins: [glFeatureFlagMixin()],
  props: {
    state: {
      type: String,
      required: false,
      default: '',
    },
    isSquashEnabled: {
      type: Boolean,
      required: false,
      default: false,
    },
    isFastForwardEnabled: {
      type: Boolean,
      required: true,
    },
    commitsCount: {
      type: Number,
      required: false,
      default: 0,
    },
    targetBranch: {
      type: String,
      required: true,
    },
    mergeCommitSha: {
      type: String,
      required: false,
      default: '',
    },
    mergeCommitPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    isMerged() {
      return this.state === 'merged';
    },
    targetBranchEscaped() {
      return escape(this.targetBranch);
    },
    commitsCountMessage() {
      const count = this.isSquashEnabled ? 1 : this.commitsCount;

      return sprintf(
        n__(
          '%{strongStart}%{count}%{strongEnd} commit',
          '%{strongStart}%{count}%{strongEnd} commits',
          count,
        ),
        { count },
      );
    },
    message() {
      if (this.state === 'closed') {
        return s__('mrWidgetCommitsAdded|The changes were not merged into %{targetBranch}.');
      } else if (this.isMerged) {
        return s__(
          'mrWidgetCommitsAdded|Changes merged into %{targetBranch} with %{mergeCommitSha}%{squashedCommits}.',
        );
      }

      return this.isFastForwardEnabled
        ? s__('mrWidgetCommitsAdded|%{commitCount} will be added to %{targetBranch}.')
        : s__(
            'mrWidgetCommitsAdded|%{commitCount} and %{mergeCommitCount} will be added to %{targetBranch}%{squashedCommits}.',
          );
    },
    squashCommitMessage() {
      if (this.isMerged) {
        return s__('mergedCommitsAdded| (commits were squashed)');
      }

      return sprintf(
        n__(
          ' (squashes %{strongStart}%{count}%{strongEnd} commit)',
          ' (squashes %{strongStart}%{count}%{strongEnd} commits)',
          this.commitsCount,
        ),
        { count: this.commitsCount },
      );
    },
  },
  mergeCommitCount,
};
</script>

<template>
  <span>
    <gl-sprintf :message="message">
      <template #commitCount>
        <gl-sprintf :message="commitsCountMessage">
          <template #strong="{ content }">
            <span class="gl-font-weight-bold">{{ content }}</span>
          </template>
        </gl-sprintf>
      </template>
      <template #mergeCommitCount>
        <gl-sprintf :message="$options.mergeCommitCount">
          <template #strong="{ content }">
            <span class="gl-font-weight-bold">{{ content }}</span>
          </template>
        </gl-sprintf>
      </template>
      <template #targetBranch>
        <span class="label-branch gl-font-weight-bold">{{ targetBranchEscaped }}</span>
      </template>
      <template #squashedCommits>
        <template v-if="isSquashEnabled">
          <gl-sprintf :message="squashCommitMessage">
            <template #strong="{ content }">
              <span class="gl-font-weight-bold">{{ content }}</span>
            </template>
          </gl-sprintf>
        </template>
      </template>
      <template #mergeCommitSha>
        <gl-link :href="mergeCommitPath" class="label-branch" data-testid="merge-commit-sha">{{
          mergeCommitSha
        }}</gl-link>
      </template>
    </gl-sprintf>
  </span>
</template>