Skip to content

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

feat(frontend): support LGTM check setting (isDev guarded) (#2773)

Liu Ji86f55b65ed8f
diff --git a/frontend/src/components/Issue/TaskCheckBadgeBar.vue b/frontend/src/components/Issue/TaskCheckBadgeBar.vue
index 7071fff5d2..0da67313c5 100644
--- a/frontend/src/components/Issue/TaskCheckBadgeBar.vue
+++ b/frontend/src/components/Issue/TaskCheckBadgeBar.vue
@@ -234,6 +234,7 @@ const TaskCheckTypeOrderList: TaskCheckType[] = [
"bb.task-check.database.connect",
"bb.task-check.instance.migration-schema",
"bb.task-check.database.statement.advise",
+ "bb.task-check.issue.lgtm",
];
const TaskCheckTypeOrderDict = new Map<TaskCheckType, number>(
TaskCheckTypeOrderList.map((type, index) => [type, index])
@@ -264,5 +265,6 @@ const TaskCheckTypeNameDict = new Map<TaskCheckType, string>([
"task.check-type.earliest-allowed-time",
],
["bb.task-check.database.ghost.sync", "task.check-type.ghost-sync"],
+ ["bb.task-check.issue.lgtm", "task.check-type.lgtm"],
]);
</script>
diff --git a/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue b/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue
new file mode 100644
index 0000000000..0c61060535
--- /dev/null
+++ b/frontend/src/components/Project/ProjectSetting/ProjectAdvancedSettingPanel.vue
@@ -0,0 +1,150 @@
+<template>
+ <div class="max-w-md space-y-4">
+ <p class="text-lg font-medium leading-7 text-main">
+ {{ $t("common.advanced") }}
+ </p>
+ <div class="space-y-4">
+ <div class="flex items-center space-x-1">
+ <label class="textlabel">
+ {{ $t("project.lgtm-check.self") }}
+ </label>
+ <FeatureBadge feature="bb.feature.lgtm" class="text-accent" />
+ </div>
+
+ <label class="flex items-center space-x-4">
+ <input
+ v-model="state.lgtmCheckValue"
+ tabindex="-1"
+ type="radio"
+ class="text-accent disabled:text-accent-disabled focus:ring-accent"
+ value="DISABLED"
+ :disabled="!allowEdit"
+ />
+ <div class="-mt-0.5">
+ <div class="textlabel">
+ {{ $t("project.lgtm-check.disabled") }}
+ </div>
+ </div>
+ </label>
+
+ <label class="flex items-center space-x-4">
+ <input
+ v-model="state.lgtmCheckValue"
+ tabindex="-1"
+ type="radio"
+ class="text-accent disabled:text-accent-disabled focus:ring-accent"
+ value="PROJECT_MEMBER"
+ :disabled="!allowEdit"
+ />
+ <div class="-mt-0.5">
+ <div class="textlabel">
+ {{ $t("project.lgtm-check.project-member") }}
+ </div>
+ </div>
+ </label>
+
+ <label class="flex items-center space-x-4">
+ <input
+ v-model="state.lgtmCheckValue"
+ tabindex="-1"
+ type="radio"
+ class="text-accent disabled:text-accent-disabled focus:ring-accent"
+ value="PROJECT_OWNER"
+ :disabled="!allowEdit"
+ />
+ <div class="-mt-0.5">
+ <div class="textlabel">
+ {{ $t("project.lgtm-check.project-owner") }}
+ </div>
+ </div>
+ </label>
+ </div>
+
+ <div v-if="allowEdit" class="flex justify-end">
+ <button
+ type="button"
+ class="btn-primary"
+ :disabled="!allowSave"
+ @click.prevent="save"
+ >
+ {{ $t("common.save") }}
+ </button>
+ </div>
+
+ <FeatureModal
+ v-if="state.missingFeature !== undefined"
+ :feature="state.missingFeature"
+ @cancel="state.missingFeature = undefined"
+ />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, PropType, reactive, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { FeatureType, LGTMCheckValue, Project, ProjectPatch } from "@/types";
+import { featureToRef, pushNotification, useProjectStore } from "@/store";
+import FeatureBadge from "@/components/FeatureBadge.vue";
+
+interface LocalState {
+ lgtmCheckValue: LGTMCheckValue;
+ missingFeature: FeatureType | undefined;
+}
+
+const props = defineProps({
+ project: {
+ required: true,
+ type: Object as PropType<Project>,
+ },
+ allowEdit: {
+ default: true,
+ type: Boolean,
+ },
+});
+const { t } = useI18n();
+const projectStore = useProjectStore();
+const hasLGTMFeature = featureToRef("bb.feature.lgtm");
+
+const state = reactive<LocalState>({
+ lgtmCheckValue: props.project.lgtmCheckSetting.value,
+ missingFeature: undefined,
+});
+
+const allowSave = computed((): boolean => {
+ return state.lgtmCheckValue !== props.project.lgtmCheckSetting.value;
+});
+
+const save = () => {
+ if (!hasLGTMFeature.value) {
+ state.missingFeature = "bb.feature.lgtm";
+ return;
+ }
+
+ const projectPatch: ProjectPatch = {
+ lgtmCheckSetting: {
+ value: state.lgtmCheckValue,
+ },
+ };
+
+ projectStore
+ .patchProject({
+ projectId: props.project.id,
+ projectPatch,
+ })
+ .then((updatedProject: Project) => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("project.settings.success-updated"),
+ });
+ });
+};
+
+// Sync the local state if props changed
+watch(
+ () => props.project.lgtmCheckSetting.value,
+ (value) => {
+ state.lgtmCheckValue = value;
+ }
+);
+</script>
diff --git a/frontend/src/components/Project/ProjectSetting/index.ts b/frontend/src/components/Project/ProjectSetting/index.ts
new file mode 100644
index 0000000000..ea82e8b3b6
--- /dev/null
+++ b/frontend/src/components/Project/ProjectSetting/index.ts
@@ -0,0 +1,3 @@
+import ProjectAdvancedSettingPanel from "./ProjectAdvancedSettingPanel.vue";
+
+export { ProjectAdvancedSettingPanel };
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index 3cfb4cc9f1..6b652520ff 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -2,6 +2,12 @@
<div class="max-w-3xl mx-auto space-y-4">
<div class="divide-y divide-block-border space-y-6">
<ProjectGeneralSettingPanel :project="project" :allow-edit="allowEdit" />
+ <ProjectAdvancedSettingPanel
+ v-if="isDev"
+ :project="project"
+ :allow-edit="allowEdit"
+ class="pt-4"
+ />
<div class="pt-4">
<ProjectMemberPanel :project="project" />
</div>
@@ -41,6 +47,7 @@
import { computed, defineComponent, PropType } from "vue";
import { isProjectOwner } from "../utils";
import ProjectGeneralSettingPanel from "../components/ProjectGeneralSettingPanel.vue";
+import { ProjectAdvancedSettingPanel } from "../components/Project/ProjectSetting";
import ProjectMemberPanel from "../components/ProjectMemberPanel.vue";
import { ProjectPatch, Project } from "../types";
import { useCurrentUser, useProjectStore } from "@/store";
@@ -49,6 +56,7 @@ export default defineComponent({
name: "ProjectSettingPanel",
components: {
ProjectGeneralSettingPanel,
+ ProjectAdvancedSettingPanel,
ProjectMemberPanel,
},
props: {
diff --git a/frontend/src/components/misc/SQLPreviewPopover.vue b/frontend/src/components/misc/SQLPreviewPopover.vue
index d7ce65a04f..f4cd2a0d77 100644
--- a/frontend/src/components/misc/SQLPreviewPopover.vue
+++ b/frontend/src/components/misc/SQLPreviewPopover.vue
@@ -31,7 +31,7 @@ export default defineComponent({
props: {
statement: {
type: String,
- required: true,
+ default: "",
},
maxLength: {
type: Number,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index bb788d26bc..8a6c3021d0 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -211,7 +211,8 @@
"load-more": "Load more",
"access-denied": "Access denied",
"no": "No",
- "yes": "Yes"
+ "yes": "Yes",
+ "advanced": "Advanced"
},
"error-page": {
"go-back-home": "Go back home"
@@ -249,7 +250,8 @@
"sql-review": "SQL review",
"earliest-allowed-time": "Earliest allowed time",
"ghost-sync": "gh-ost sync",
- "statement-type": "Statement type"
+ "statement-type": "Statement type",
+ "lgtm": "LGTM"
},
"earliest-allowed-time-hint": "'@:{'common.when'}' specifies the expected execution timing for this task. If this field is not specified, the task will be executed once it has passed all other gating criteria.",
"earliest-allowed-time-unset": "Unset",
@@ -1094,7 +1096,13 @@
"tenant": "Tenant"
},
"db-name-template": "@:common.database @:common.name @:common.template",
- "select": "Select project"
+ "select": "Select project",
+ "lgtm-check": {
+ "self": "LGTM check",
+ "disabled": "Skip LGTM check",
+ "project-member": "Require LGTM from project members",
+ "project-owner": "Require LGTM from project owner"
+ }
},
"inbox": {
"mark-all-as-read": "Mark all as read",
@@ -1367,6 +1375,10 @@
"title": "Environment tier",
"desc": "Mark environment as protected."
},
+ "bb-feature-lgtm": {
+ "title": "LGTM check",
+ "desc": "Check if the issue has an \"LGTM\" comment."
+ },
"bb-feature-sql-review": {
"title": "SQL review policy",
"desc": "Customize the SQL review policy for different environments, can only use limited rules in the free plan. @:{'subscription.trial'}."
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index ceb42978ba..2a6d5360b7 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -211,7 +211,8 @@
"load-more": "加载更多",
"access-denied": "拒绝访问",
"no": "否",
- "yes": "是"
+ "yes": "是",
+ "advanced": "高级"
},
"error-page": {
"go-back-home": "回到主页"
@@ -249,7 +250,8 @@
"sql-review": "SQL 审查",
"earliest-allowed-time": "最早执行时间",
"ghost-sync": "gh-ost 同步",
- "statement-type": "语句类型"
+ "statement-type": "语句类型",
+ "lgtm": "LGTM"
},
"earliest-allowed-time-hint": "'@:{'common.when'}' 指定了该任务最早允许执行的时间。如果该字段没有被指定,则任务会在满足其他条件后立即执行。",
"comment": "评论",
@@ -1094,7 +1096,13 @@
"tenant": "多租户"
},
"db-name-template": "数据库名称模板",
- "select": "选择项目"
+ "select": "选择项目",
+ "lgtm-check": {
+ "self": "LGTM 检查",
+ "disabled": "跳过 LGTM 检查",
+ "project-member": "需要来自项目成员的 LGTM",
+ "project-owner": "需要来自项目所有者的 LGTM"
+ }
},
"inbox": {
"mark-all-as-read": "全部标记为已读",
@@ -1367,6 +1375,10 @@
"title": "环境级别",
"desc": "「环境级别」可以将环境标记为受保护的"
},
+ "bb-feature-lgtm": {
+ "title": "LGTM 检查",
+ "desc": "检查工单是否有 \"LGTM\" 评论。"
+ },
"bb-feature-sql-review": {
"title": "Schema 审核策略",
"desc": "给不同的环境定制 schema 审核策略,免费版仅可使用部分规则。可以通过@:{'subscription.upgrade'}来完全开启该功能。"
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index ba482e2120..8e7598668d 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -52,6 +52,7 @@ function convert(
dbNameTemplate: attrs.dbNameTemplate,
roleProvider: attrs.roleProvider,
schemaChangeType: attrs.schemaChangeType,
+ lgtmCheckSetting: attrs.lgtmCheckSetting,
};
const memberList: ProjectMember[] = [];
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 251607b540..433b18b48f 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -16,6 +16,7 @@ import {
Project,
ProjectMember,
EmptyProjectRoleProviderPayload,
+ getDefaultLGTMCheckSetting,
} from "./project";
import { ProjectWebhook } from "./projectWebhook";
import { Repository } from "./repository";
@@ -203,6 +204,7 @@ const makeUnknown = (type: ResourceType) => {
rowStatus: "NORMAL",
name: "<<Unknown environment>>",
order: 0,
+ tier: "UNPROTECTED",
};
const UNKNOWN_PROJECT: Project = {
@@ -220,6 +222,8 @@ const makeUnknown = (type: ResourceType) => {
tenantMode: "DISABLED",
dbNameTemplate: "",
roleProvider: "BYTEBASE",
+ schemaChangeType: "DDL",
+ lgtmCheckSetting: getDefaultLGTMCheckSetting(),
};
const UNKNOWN_PROJECT_HOOK: ProjectWebhook = {
@@ -628,6 +632,7 @@ const makeEmpty = (type: ResourceType) => {
rowStatus: "NORMAL",
name: "",
order: 0,
+ tier: "UNPROTECTED",
};
const EMPTY_PROJECT: Project = {
@@ -645,6 +650,8 @@ const makeEmpty = (type: ResourceType) => {
tenantMode: "DISABLED",
dbNameTemplate: "",
roleProvider: "BYTEBASE",
+ schemaChangeType: "DDL",
+ lgtmCheckSetting: getDefaultLGTMCheckSetting(),
};
const EMPTY_PROJECT_HOOK: ProjectWebhook = {
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 012976ac6a..db5ac1be1b 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -218,7 +218,8 @@ export type TaskCheckType =
| "bb.task-check.database.connect"
| "bb.task-check.instance.migration-schema"
| "bb.task-check.general.earliest-allowed-time"
- | "bb.task-check.database.ghost.sync";
+ | "bb.task-check.database.ghost.sync"
+ | "bb.task-check.issue.lgtm";
export type TaskCheckDatabaseStatementAdvisePayload = {
statement: string;
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index df800e15e3..5c68c3fdd2 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -18,6 +18,7 @@ export type FeatureType =
| "bb.feature.approval-policy"
| "bb.feature.backup-policy"
| "bb.feature.environment-tier-policy"
+ | "bb.feature.lgtm"
// Admin & Security
| "bb.feature.rbac"
| "bb.feature.3rd-party-auth"
@@ -85,6 +86,7 @@ export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([
["bb.feature.approval-policy", [false, true, true]],
["bb.feature.backup-policy", [false, true, true]],
["bb.feature.environment-tier-policy", [false, false, true]],
+ ["bb.feature.lgtm", [false, false, true]],
// Admin & Security
["bb.feature.rbac", [false, true, true]],
["bb.feature.3rd-party-auth", [false, true, true]],
diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.ts
index d7556b9936..6c447f0b60 100644
--- a/frontend/src/types/project.ts
+++ b/frontend/src/types/project.ts
@@ -20,6 +20,12 @@ export type ProjectRoleProvider =
export type SchemaChangeType = "DDL" | "SDL";
+export type LGTMCheckValue = "DISABLED" | "PROJECT_OWNER" | "PROJECT_MEMBER";
+
+export type LGTMCheckSetting = {
+ value: LGTMCheckValue;
+};
+
export type ProjectRoleProviderPayload = {
vcsRole: string;
lastSyncTs: number;
@@ -53,6 +59,13 @@ export type Project = {
dbNameTemplate: string;
roleProvider: ProjectRoleProvider;
schemaChangeType: SchemaChangeType;
+ lgtmCheckSetting: LGTMCheckSetting;
+};
+
+export const getDefaultLGTMCheckSetting = (): LGTMCheckSetting => {
+ return {
+ value: "DISABLED",
+ };
};
export type ProjectCreate = {
@@ -74,6 +87,7 @@ export type ProjectPatch = {
key?: string;
roleProvider?: ProjectRoleProvider;
schemaChangeType?: SchemaChangeType;
+ lgtmCheckSetting?: LGTMCheckSetting;
};
// Project Member