Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add branch protection rule source (#10691)

Liu Ji4eb72cb404e4
diff --git a/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue b/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue
index 2eae133360..3b0f1a03a6 100644
--- a/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue
+++ b/frontend/src/components/Project/CreateProjectBranchProtectionRulePanel.vue
@@ -26,6 +26,18 @@
</p>
<NInput v-model:value="state.protectionRule.nameFilter" />
</div>
+ <div class="mt-2">
+ <NCheckbox
+ :checked="state.protectionRule.branchSource === BranchSource.DATABASE"
+ @update:checked="toggleApplyToMainBranches"
+ >
+ {{
+ $t(
+ "project.settings.branch-protection-rules.only-apply-to-main-branches"
+ )
+ }}
+ </NCheckbox>
+ </div>
<div class="mt-2">
<p class="text-sm">
{{
@@ -106,6 +118,7 @@ import {
import { ComposedProject, PresetRoleType } from "@/types";
import {
ProtectionRule,
+ ProtectionRule_BranchSource as BranchSource,
ProtectionRule_Target,
} from "@/types/proto/v1/project_service";
import { displayRoleTitle } from "@/utils";
@@ -154,7 +167,14 @@ const branches = computed(() => {
});
const matchedBranchList = computed(() => {
- return branches.value.filter((branch) => {
+ const branchList =
+ state.protectionRule.branchSource === BranchSource.DATABASE
+ ? branches.value.filter((br) => !br.parentBranch)
+ : branches.value;
+ if (state.protectionRule.nameFilter === "") {
+ return branchList;
+ }
+ return branchList.filter((branch) => {
return wildcardToRegex(state.protectionRule.nameFilter).test(
branch.branchId
);
@@ -166,9 +186,6 @@ const isCreating = computed(() => {
});
const allowConfirm = computed(() => {
- if (!state.protectionRule.nameFilter) {
- return false;
- }
return hasProjectPermissionV2(
props.project,
useCurrentUserV1().value,
@@ -204,6 +221,12 @@ watch(
}
);
+const toggleApplyToMainBranches = (on: boolean) => {
+ state.protectionRule.branchSource = on
+ ? BranchSource.DATABASE
+ : BranchSource.BRANCH_SOURCE_UNSPECIFIED;
+};
+
const handleConfirm = async () => {
if (!allowConfirm.value) {
return;
diff --git a/frontend/src/components/Project/ProjectBranchProtectionRulesSettingPanel.vue b/frontend/src/components/Project/ProjectBranchProtectionRulesSettingPanel.vue
index 2876e91363..7dc1c59fec 100644
--- a/frontend/src/components/Project/ProjectBranchProtectionRulesSettingPanel.vue
+++ b/frontend/src/components/Project/ProjectBranchProtectionRulesSettingPanel.vue
@@ -16,7 +16,10 @@
class="w-full flex flex-row justify-between items-center px-3 py-2 border border-b-0 last:border-b"
>
<NTag type="success" round>
- {{ rule.nameFilter }}
+ <template v-if="rule.nameFilter">{{ rule.nameFilter }}</template>
+ <span v-else class="text-control-placeholder">
+ {{ $t("common.all") }}
+ </span>
</NTag>
<div class="flex flex-row justify-end items-center">
<NButton text :disabled="!allowEdit" @click="handleEditRule(rule)">
@@ -53,6 +56,7 @@ import { ref } from "vue";
import { useProjectBranchProtectionRules } from "@/store/modules/v1/projectProtectionRoles";
import { ComposedProject } from "@/types";
import { ProtectionRule } from "@/types/proto/v1/project_service";
+import CreateProjectBranchProtectionRulePanel from "./CreateProjectBranchProtectionRulePanel.vue";
const props = defineProps<{
project: ComposedProject;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index e41dc7e79d..5a51c10478 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1960,11 +1960,12 @@
"add-rule": "Add Rule",
"branch-name-pattern": {
"self": "Branch name pattern",
- "description": "Support wildcard such as feature/* or *-stable"
+ "description": "Support wildcard such as feature/* or *-stable. Empty string matches all branches."
},
"applies-to-n-branches": "Applies to {n} branch | Applies to {n} branches",
"only-allow-specified-roles-to-create-branch": "Only allow specified roles to create branch",
- "no-protection-rule-configured": "No protection rule configured."
+ "no-protection-rule-configured": "No protection rule configured.",
+ "only-apply-to-main-branches": "Only apply to main branches"
}
},
"members": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index a45fe656cb..bdb4307617 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1959,11 +1959,12 @@
"add-rule": "Agregar Regla",
"branch-name-pattern": {
"self": "Patrón de nombre de rama",
- "description": "Soporta comodines como feature/* o *-stable"
+ "description": "Admite comodines como feature/* o *-stable. \nLa cadena vacía coincide con todas las ramas."
},
"applies-to-n-branches": "Se aplica a {n} ramas",
"only-allow-specified-roles-to-create-branch": "Sólo permitir roles especificados para crear rama",
- "no-protection-rule-configured": "No hay regla de protección configurada"
+ "no-protection-rule-configured": "No hay regla de protección configurada",
+ "only-apply-to-main-branches": "Sólo aplica en sucursales principales"
}
},
"members": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 175ff6b835..595b34a3d3 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1958,11 +1958,12 @@
"add-rule": "ルールを追加する",
"branch-name-pattern": {
"self": "ブランチ名のパターン",
- "description": "feature/*や*-stableなどのワイルドカードをサポートします。"
+ "description": "feature/* や *-stable などのワイルドカードをサポートします。\n空の文字列はすべてのブランチに一致します。"
},
"applies-to-n-branches": "{n}ブランチに適用されます | {n}ブランチに適用されます",
"only-allow-specified-roles-to-create-branch": "指定された役割のみがブランチの作成を許可します",
- "no-protection-rule-configured": "保護ルールが設定されていません。"
+ "no-protection-rule-configured": "保護ルールが設定されていません。",
+ "only-apply-to-main-branches": "メインブランチにのみ適用されます"
}
},
"members": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 4faee99f73..b34f726d28 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1960,11 +1960,12 @@
"add-rule": "Thêm quy tắc",
"branch-name-pattern": {
"self": "Mẫu tên chi nhánh",
- "description": "Hỗ trợ ký tự đại diện như tính năng/* hoặc *-ổn định"
+ "description": "Hỗ trợ ký tự đại diện như feature/* hoặc *-stable. \nChuỗi rỗng khớp với tất cả các nhánh."
},
"applies-to-n-branches": "Áp dụng cho chi nhánh {n} | Áp dụng cho {n} chi nhánh",
"only-allow-specified-roles-to-create-branch": "Chỉ cho phép các vai trò được chỉ định để tạo chi nhánh",
- "no-protection-rule-configured": "Không có quy tắc bảo vệ nào được cấu hình."
+ "no-protection-rule-configured": "Không có quy tắc bảo vệ nào được cấu hình.",
+ "only-apply-to-main-branches": "Chỉ áp dụng cho chi nhánh chính"
}
},
"members": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 584ab9e56b..a7098f5800 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1955,11 +1955,12 @@
"add-rule": "添加分支",
"branch-name-pattern": {
"self": "分支名称模式",
- "description": "支持通配符,如 feature/* 或 *-stable"
+ "description": "支持通配符,如 feature/* 或 *-stable。留空则匹配所有分支。"
},
"applies-to-n-branches": "应用到了 {n} 个分支",
"only-allow-specified-roles-to-create-branch": "只允许指定角色创建分支",
- "no-protection-rule-configured": "没有配置分支保护规则。"
+ "no-protection-rule-configured": "没有配置分支保护规则。",
+ "only-apply-to-main-branches": "只对主分支生效"
}
},
"members": {