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
|
<script>
import { GlBadge, GlButton } from '@gitlab/ui';
import { s__, sprintf, n__ } from '~/locale';
export const i18n = {
defaultLabel: s__('BranchRules|default'),
detailsButtonLabel: s__('BranchRules|Details'),
allowForcePush: s__('BranchRules|Allowed to force push'),
codeOwnerApprovalRequired: s__('BranchRules|Requires CODEOWNERS approval'),
statusChecks: s__('BranchRules|%{total} status %{subject}'),
approvalRules: s__('BranchRules|%{total} approval %{subject}'),
};
export default {
name: 'BranchRule',
i18n,
components: {
GlBadge,
GlButton,
},
inject: {
branchRulesPath: {
default: '',
},
},
props: {
name: {
type: String,
required: true,
},
isDefault: {
type: Boolean,
required: false,
default: false,
},
branchProtection: {
type: Object,
required: false,
default: () => {},
},
statusChecksTotal: {
type: Number,
required: false,
default: 0,
},
approvalRulesTotal: {
type: Number,
required: false,
default: 0,
},
},
computed: {
hasApprovalDetails() {
return this.approvalDetails.length;
},
detailsPath() {
return `${this.branchRulesPath}?branch=${this.name}`;
},
statusChecksText() {
return sprintf(this.$options.i18n.statusChecks, {
total: this.statusChecksTotal,
subject: n__('check', 'checks', this.statusChecksTotal),
});
},
approvalRulesText() {
return sprintf(this.$options.i18n.approvalRules, {
total: this.approvalRulesTotal,
subject: n__('rule', 'rules', this.approvalRulesTotal),
});
},
approvalDetails() {
const approvalDetails = [];
if (this.branchProtection.allowForcePush) {
approvalDetails.push(this.$options.i18n.allowForcePush);
}
if (this.branchProtection.codeOwnerApprovalRequired) {
approvalDetails.push(this.$options.i18n.codeOwnerApprovalRequired);
}
if (this.statusChecksTotal) {
approvalDetails.push(this.statusChecksText);
}
if (this.approvalRulesTotal) {
approvalDetails.push(this.approvalRulesText);
}
return approvalDetails;
},
},
};
</script>
<template>
<div class="gl-border-b gl-pt-5 gl-pb-5 gl-display-flex gl-justify-content-space-between">
<div>
<strong class="gl-font-monospace">{{ name }}</strong>
<gl-badge v-if="isDefault" variant="info" size="sm" class="gl-ml-2">{{
$options.i18n.defaultLabel
}}</gl-badge>
<ul v-if="hasApprovalDetails" class="gl-pl-6 gl-mt-2 gl-mb-0 gl-text-gray-500">
<li v-for="(detail, index) in approvalDetails" :key="index">{{ detail }}</li>
</ul>
</div>
<gl-button class="gl-align-self-start" :href="detailsPath">
{{ $options.i18n.detailsButtonLabel }}</gl-button
>
</div>
</template>
|