Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(frontend): ship project webhook to v1 API (#6040)
Liu Ji67b97301aaf9
diff --git a/frontend/src/components/ProjectWebhookCard.vue b/frontend/src/components/ProjectWebhookCard.vueindex 46564cc34a..c4913849f9 100644--- a/frontend/src/components/ProjectWebhookCard.vue+++ b/frontend/src/components/ProjectWebhookCard.vue@@ -6,30 +6,28 @@<div class="flex flex-row space-x-2 items-center"><!-- This awkward code is author couldn't figure out proper way to use dynamic src under vitehttps://github.com/vitejs/vite/issues/1265 -->- <template v-if="projectWebhook.type == 'bb.plugin.webhook.slack'">+ <template v-if="projectWebhook.type === Webhook_Type.TYPE_SLACK"><img class="h-5 w-5" src="../assets/slack-logo.png" /></template>- <template- v-else-if="projectWebhook.type == 'bb.plugin.webhook.discord'"- >+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_DISCORD"><img class="h-5 w-5" src="../assets/discord-logo.svg" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.teams'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_TEAMS"><img class="h-5 w-5" src="../assets/teams-logo.svg" /></template><template- v-else-if="projectWebhook.type == 'bb.plugin.webhook.dingtalk'"+ v-else-if="projectWebhook.type === Webhook_Type.TYPE_DINGTALK"><img class="h-5 w-5" src="../assets/dingtalk-logo.png" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.feishu'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_FEISHU"><img class="h-5 w-5" src="../assets/feishu-logo.webp" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.wecom'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_WECOM"><img class="h-5 w-5" src="../assets/wecom-logo.png" /></template><h3 class="text-lg leading-6 font-medium text-main">- {{ projectWebhook.name }}+ {{ projectWebhook.title }}</h3></div><button@@ -61,60 +59,46 @@</div></template>-<script lang="ts">-import { reactive, PropType, computed, defineComponent } from "vue";+<script lang="ts" setup>+import { PropType, computed } from "vue";import { useRouter } from "vue-router";+import { projectWebhookV1ActivityItemList } from "@/types";import {- ProjectWebhook,- PROJECT_HOOK_ACTIVITY_ITEM_LIST,- redirectUrl,-} from "../types";-import { projectWebhookSlug } from "../utils";--// eslint-disable-next-line @typescript-eslint/no-empty-interface-interface LocalState {}+ Webhook,+ Webhook_Type,+ activity_TypeToJSON,+} from "@/types/proto/v1/project_service";+import { projectWebhookV1Slug } from "@/utils";-export default defineComponent({- name: "ProjectWebhookCard",- props: {- projectWebhook: {- required: true,- type: Object as PropType<ProjectWebhook>,- },+const props = defineProps({+ projectWebhook: {+ required: true,+ type: Object as PropType<Webhook>,},- setup(props) {- const router = useRouter();-- const state = reactive<LocalState>({});-- const viewProjectWebhook = () => {- router.push({- name: "workspace.project.hook.detail",- params: {- projectWebhookSlug: projectWebhookSlug(props.projectWebhook),- },- });- };+});+const router = useRouter();- const activityListStr = computed(() => {- const list = props.projectWebhook.activityList.map((activity) => {- for (const item of PROJECT_HOOK_ACTIVITY_ITEM_LIST()) {- if (item.activity == activity) {- return item.title;- }- }- return activity;- });+const viewProjectWebhook = () => {+ router.push({+ name: "workspace.project.hook.detail",+ params: {+ projectWebhookSlug: projectWebhookV1Slug(props.projectWebhook),+ },+ });+};- return list.join(", ");- });+const activityListStr = computed(() => {+ const wellknownActivityItemList = projectWebhookV1ActivityItemList();+ const list = props.projectWebhook.notificationTypes.map((activity) => {+ const item = wellknownActivityItemList.find(+ (item) => item.activity === activity+ );+ if (item) {+ return item.title;+ }+ return activity_TypeToJSON(activity);+ });- return {- state,- redirectUrl,- viewProjectWebhook,- activityListStr,- };- },+ return list.join(", ");});</script>diff --git a/frontend/src/components/ProjectWebhookForm.vue b/frontend/src/components/ProjectWebhookForm.vueindex 5a1b466684..2b24d6f114 100644--- a/frontend/src/components/ProjectWebhookForm.vue+++ b/frontend/src/components/ProjectWebhookForm.vue@@ -6,7 +6,7 @@</label><div class="mt-1 grid grid-cols-1 gap-4 sm:grid-cols-7"><template- v-for="(item, index) in PROJECT_HOOK_TYPE_ITEM_LIST()"+ v-for="(item, index) in projectWebhookV1TypeItemList()":key="index"><div@@ -16,25 +16,25 @@<div class="flex flex-col items-center"><!-- This awkward code is author couldn't figure out proper way to use dynamic src under vitehttps://github.com/vitejs/vite/issues/1265 -->- <template v-if="item.type == 'bb.plugin.webhook.slack'">+ <template v-if="item.type === Webhook_Type.TYPE_SLACK"><img class="h-10 w-10" src="../assets/slack-logo.png" alt="" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.discord'">+ <template v-else-if="item.type === Webhook_Type.TYPE_DISCORD"><img class="h-10 w-10" src="../assets/discord-logo.svg" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.teams'">+ <template v-else-if="item.type === Webhook_Type.TYPE_TEAMS"><img class="h-10 w-10" src="../assets/teams-logo.svg" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.dingtalk'">+ <template v-else-if="item.type === Webhook_Type.TYPE_DINGTALK"><img class="h-10 w-10" src="../assets/dingtalk-logo.png" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.feishu'">+ <template v-else-if="item.type === Webhook_Type.TYPE_FEISHU"><img class="h-10 w-10" src="../assets/feishu-logo.webp" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.wecom'">+ <template v-else-if="item.type === Webhook_Type.TYPE_WECOM"><img class="h-10 w-10" src="../assets/wecom-logo.png" /></template>- <template v-else-if="item.type == 'bb.plugin.webhook.custom'">+ <template v-else-if="item.type === Webhook_Type.TYPE_CUSTOM"><heroicons-outline:puzzle class="w-10 h-10" /></template><p class="mt-1 text-center textlabel">@@ -58,7 +58,7 @@</label><inputid="name"- v-model="state.webhook.name"+ v-model="state.webhook.title"name="name"type="text"class="textfield mt-1 w-full"@@ -72,7 +72,7 @@<span class="text-red-600">*</span></label><div class="mt-1 textinfolabel">- <template v-if="state.webhook.type == 'bb.plugin.webhook.slack'">+ <template v-if="state.webhook.type === Webhook_Type.TYPE_SLACK">{{$t("project.webhook.creation.desc", {destination: $t("common.slack"),@@ -89,7 +89,7 @@}}</a>.</template>- <template v-else-if="state.webhook.type == 'bb.plugin.webhook.discord'">+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_DISCORD">{{$t("project.webhook.creation.desc", {destination: $t("common.discord"),@@ -106,7 +106,7 @@}}</a>.</template>- <template v-else-if="state.webhook.type == 'bb.plugin.webhook.teams'">+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_TEAMS">{{$t("project.webhook.creation.desc", {destination: $t("common.teams"),@@ -123,9 +123,7 @@}}</a>.</template>- <template- v-else-if="state.webhook.type == 'bb.plugin.webhook.dingtalk'"- >+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_DINGTALK">{{$t("project.webhook.creation.desc", {destination: $t("common.dingtalk"),@@ -144,7 +142,7 @@}}</a>.</template>- <template v-else-if="state.webhook.type == 'bb.plugin.webhook.feishu'">+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_FEISHU">{{$t("project.webhook.creation.desc", {destination: $t("common.feishu"),@@ -165,7 +163,7 @@>.</template><!-- WeCom doesn't seem to provide official webhook setup guide for the enduser -->- <template v-else-if="state.webhook.type == 'bb.plugin.webhook.wecom'">+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_WECOM">{{$t("project.webhook.creation.desc", {destination: $t("common.wecom"),@@ -182,7 +180,7 @@}}</a>.</template>- <template v-else-if="state.webhook.type == 'bb.plugin.webhook.custom'">+ <template v-else-if="state.webhook.type === Webhook_Type.TYPE_CUSTOM">{{$t("project.webhook.creation.desc", {destination: $t("common.custom"),@@ -215,16 +213,16 @@{{ $t("project.webhook.triggering-activity") }}</div><div- v-for="(item, index) in PROJECT_HOOK_ACTIVITY_ITEM_LIST()"+ v-for="(item, index) in projectWebhookV1ActivityItemList()":key="index"class="mt-4 space-y-4"><BBCheckbox:title="item.title":label="item.label"- :value="eventOn(item.activity)"+ :value="isEventOn(item.activity)"@toggle="- (on) => {+ (on: boolean) => {toggleEvent(item.activity, on);}"@@ -240,7 +238,7 @@:style="'DELETE'":button-text="$t('project.webhook.deletion.btn-text')":ok-text="'Delete'"- :confirm-title="`Delete webhook '${webhook.name}' and all its execution history?`"+ :confirm-title="`Delete webhook '${webhook.title}' and all its execution history?`":require-confirm="true"@confirm="deleteWebhook"/>@@ -273,241 +271,218 @@</div></template>-<script lang="ts">-import { reactive, computed, PropType, watch, defineComponent } from "vue";-import {- ActivityType,- Project,- ProjectWebhook,- ProjectWebhookCreate,- ProjectWebhookPatch,- PROJECT_HOOK_TYPE_ITEM_LIST,- PROJECT_HOOK_ACTIVITY_ITEM_LIST,-} from "../types";+<script lang="ts" setup>+import { reactive, computed, PropType, watch } from "vue";import { cloneDeep, isEmpty, isEqual } from "lodash-es";import { useRouter } from "vue-router";-import { projectWebhookSlug, projectSlug } from "../utils";import { useI18n } from "vue-i18n";-import { pushNotification, useProjectWebhookStore } from "@/store";++import { projectV1Slug, projectWebhookV1Slug } from "../utils";+import {+ pushNotification,+ useProjectWebhookV1Store,+ useGracefulRequest,+} from "@/store";+import {+ Activity_Type,+ Project,+ Webhook,+ Webhook_Type,+} from "@/types/proto/v1/project_service";+import {+ projectWebhookV1ActivityItemList,+ projectWebhookV1TypeItemList,+} from "@/types";interface LocalState {- webhook: ProjectWebhook | ProjectWebhookCreate;+ webhook: Webhook;}-export default defineComponent({- name: "ProjectWebhookForm",- props: {- allowEdit: {- default: true,- type: Boolean,- },- create: {- type: Boolean,- default: false,- },- project: {- required: true,- type: Object as PropType<Project>,- },- webhook: {- required: true,- type: Object as PropType<ProjectWebhook | ProjectWebhookCreate>,- },+const props = defineProps({+ allowEdit: {+ default: true,+ type: Boolean,+ },+ create: {+ type: Boolean,+ default: false,+ },+ project: {+ required: true,+ type: Object as PropType<Project>,},- emits: ["change-repository"],- setup(props) {- const router = useRouter();- const { t } = useI18n();- const projectWebhookStore = useProjectWebhookStore();+ webhook: {+ required: true,+ type: Object as PropType<Webhook>,+ },+});- const state = reactive<LocalState>({- webhook: cloneDeep(props.webhook),- });+const router = useRouter();+const { t } = useI18n();- watch(- () => props.webhook,- (cur: ProjectWebhook | ProjectWebhookCreate) => {- state.webhook = cloneDeep(cur);- }- );+const projectWebhookV1Store = useProjectWebhookV1Store();+const state = reactive<LocalState>({+ webhook: cloneDeep(props.webhook),+});- const namePlaceholder = computed(() => {- if (state.webhook.type == "bb.plugin.webhook.slack") {- return `${t("common.slack")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.discord") {- return `${t("common.discord")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.teams") {- return `${t("common.teams")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.dingtalk") {- return `${t("common.dingtalk")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.feishu") {- return `${t("common.feishu")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.wecom") {- return `${t("common.wecom")} Webhook`;- } else if (state.webhook.type == "bb.plugin.webhook.custom") {- return `${t("common.custom")} Webhook`;- }+watch(+ () => props.webhook,+ (webhook) => {+ state.webhook = cloneDeep(webhook);+ }+);- return "My Webhook";- });+const namePlaceholder = computed(() => {+ if (state.webhook.type === Webhook_Type.TYPE_SLACK) {+ return `${t("common.slack")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_DISCORD) {+ return `${t("common.discord")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_TEAMS) {+ return `${t("common.teams")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_DINGTALK) {+ return `${t("common.dingtalk")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_FEISHU) {+ return `${t("common.feishu")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_WECOM) {+ return `${t("common.wecom")} Webhook`;+ } else if (state.webhook.type === Webhook_Type.TYPE_CUSTOM) {+ return `${t("common.custom")} Webhook`;+ }- const urlPlaceholder = computed(() => {- if (state.webhook.type == "bb.plugin.webhook.slack") {- return "https://hooks.slack.com/services/...";- } else if (state.webhook.type == "bb.plugin.webhook.discord") {- return "https://discord.com/api/webhooks/...";- } else if (state.webhook.type == "bb.plugin.webhook.teams") {- return "https://acme123.webhook.office.com/webhookb2/...";- } else if (state.webhook.type == "bb.plugin.webhook.dingtalk") {- return "https://oapi.dingtalk.com/robot/...";- } else if (state.webhook.type == "bb.plugin.webhook.feishu") {- return "https://open.feishu.cn/open-apis/bot/v2/hook/...";- } else if (state.webhook.type == "bb.plugin.webhook.wecom") {- return "https://qyapi.weixin.qq.com/cgi-bin/webhook/...";- } else if (state.webhook.type == "bb.plugin.webhook.custom") {- return "https://example.com/api/webhook/...";- }+ return "My Webhook";+});- return "Webhook URL";- });+const urlPlaceholder = computed(() => {+ if (state.webhook.type === Webhook_Type.TYPE_SLACK) {+ return "https://hooks.slack.com/services/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_DISCORD) {+ return "https://discord.com/api/webhooks/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_TEAMS) {+ return "https://acme123.webhook.office.com/webhookb2/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_DINGTALK) {+ return "https://oapi.dingtalk.com/robot/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_FEISHU) {+ return "https://open.feishu.cn/open-apis/bot/v2/hook/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_WECOM) {+ return "https://qyapi.weixin.qq.com/cgi-bin/webhook/...";+ } else if (state.webhook.type === Webhook_Type.TYPE_CUSTOM) {+ return "https://example.com/api/webhook/...";+ }- const valueChanged = computed(() => {- return !isEqual(props.webhook, state.webhook);- });+ return "Webhook URL";+});- const allowCreate = computed(() => {- return (- !isEmpty(state.webhook.type) &&- !isEmpty(state.webhook.name) &&- !isEmpty(state.webhook.url) &&- !isEmpty(state.webhook.activityList)- );- });+const valueChanged = computed(() => {+ return !isEqual(props.webhook, state.webhook);+});- const eventOn = (type: ActivityType) => {- for (const activityType of props.webhook.activityList) {- if (activityType == type) {- return true;- }- }- return false;- };+const allowCreate = computed(() => {+ return (+ !isEmpty(state.webhook.title) &&+ !isEmpty(state.webhook.url) &&+ !isEmpty(state.webhook.notificationTypes)+ );+});++const isEventOn = (type: Activity_Type) => {+ return props.webhook.notificationTypes.includes(type);+};++const toggleEvent = (type: Activity_Type, on: boolean) => {+ if (on) {+ if (state.webhook.notificationTypes.includes(type)) {+ return;+ }+ state.webhook.notificationTypes.push(type);+ } else {+ const index = state.webhook.notificationTypes.indexOf(type);+ if (index >= 0) {+ state.webhook.notificationTypes.splice(index, 1);+ }+ }+ state.webhook.notificationTypes.sort();+};++const cancel = () => {+ router.push({+ name: "workspace.project.detail",+ params: {+ projectSlug: projectV1Slug(props.project),+ },+ hash: "#webhook",+ });+};- const toggleEvent = (type: ActivityType, on: boolean) => {- if (on) {- for (const activityType of state.webhook.activityList) {- if (activityType == type) {- return;- }- }- state.webhook.activityList.push(type);- } else {- const list: ActivityType[] = [];- for (const activityType of state.webhook.activityList) {- if (activityType != type) {- list.push(activityType);- }- }- state.webhook.activityList = list;- }- state.webhook.activityList.sort();- };+const createWebhook = () => {+ useGracefulRequest(async () => {+ const { webhook } = state;+ const updatedProject = await projectWebhookV1Store.createProjectWebhook(+ props.project,+ webhook+ );- const cancel = () => {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("project.webhook.success-created-prompt", {+ name: webhook.title,+ }),+ });+ const createdWebhook = updatedProject.webhooks.find((wh) => {+ return (+ wh.title === webhook.title &&+ wh.type == webhook.type &&+ wh.url === webhook.url+ );+ });+ if (createdWebhook) {router.push({- name: "workspace.project.detail",+ name: "workspace.project.hook.detail",params: {- projectSlug: projectSlug(props.project),+ projectWebhookSlug: projectWebhookV1Slug(createdWebhook),},- hash: "#webhook",});- };-- const createWebhook = () => {- projectWebhookStore- .createProjectWebhook({- projectId: props.project.id,- projectWebhookCreate: state.webhook,- })- .then((webhook: ProjectWebhook) => {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("project.webhook.success-created-prompt", {- name: webhook.name,- }),- });- router.push({- name: "workspace.project.hook.detail",- params: {- projectWebhookSlug: projectWebhookSlug(webhook),- },- });- });- };+ }+ });+};- const updateWebhook = () => {- const projectWebhookPatch: ProjectWebhookPatch = {};- if (props.webhook.name != state.webhook.name) {- projectWebhookPatch.name = state.webhook.name;- }- if (props.webhook.url != state.webhook.url) {- projectWebhookPatch.url = state.webhook.url;- }- if (props.webhook.activityList != state.webhook.activityList) {- projectWebhookPatch.activityList = state.webhook.activityList.join(",");- }- projectWebhookStore- .updateProjectWebhookById({- projectId: props.project.id,- projectWebhookId: (state.webhook as ProjectWebhook).id,- projectWebhookPatch,- })- .then((webhook: ProjectWebhook) => {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("project.webhook.success-updated-prompt", {- name: webhook.name,- }),- });- });- };-- const deleteWebhook = () => {- const name = state.webhook.name;- projectWebhookStore- .deleteProjectWebhookById({- projectId: props.project.id,- projectWebhookId: (state.webhook as ProjectWebhook).id,- })- .then(() => {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("project.webhook.success-deleted-prompt", {- name: name,- }),- });- cancel();- });- };+const updateWebhook = () => {+ useGracefulRequest(async () => {+ const updateMask: string[] = [];+ if (state.webhook.title !== props.webhook.title) {+ updateMask.push("title");+ }+ if (state.webhook.url !== props.webhook.url) {+ updateMask.push("url");+ }+ if (+ !isEqual(state.webhook.notificationTypes, props.webhook.notificationTypes)+ ) {+ updateMask.push("notification_type");+ }+ await projectWebhookV1Store.updateProjectWebhook(state.webhook, updateMask);+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("project.webhook.success-updated-prompt", {+ name: state.webhook.title,+ }),+ });+ });+};- return {- PROJECT_HOOK_TYPE_ITEM_LIST,- PROJECT_HOOK_ACTIVITY_ITEM_LIST,- state,- namePlaceholder,- urlPlaceholder,- valueChanged,- allowCreate,- eventOn,- toggleEvent,- cancel,- createWebhook,- updateWebhook,- deleteWebhook,- };- },-});+const deleteWebhook = () => {+ useGracefulRequest(async () => {+ const name = state.webhook.title;+ await projectWebhookV1Store.deleteProjectWebhook(state.webhook);+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("project.webhook.success-deleted-prompt", {+ name,+ }),+ });+ cancel();+ });+};</script>diff --git a/frontend/src/components/ProjectWebhookPanel.vue b/frontend/src/components/ProjectWebhookPanel.vueindex de2d295e1a..2127366407 100644--- a/frontend/src/components/ProjectWebhookPanel.vue+++ b/frontend/src/components/ProjectWebhookPanel.vue@@ -35,55 +35,32 @@</div></template>-<script lang="ts">-import { computed, PropType, watchEffect, defineComponent } from "vue";+<script lang="ts" setup>+import { computed, PropType } from "vue";import { useRouter } from "vue-router";-import { useProjectWebhookStore } from "@/store";import ProjectWebhookCard from "./ProjectWebhookCard.vue";-import { Project } from "../types";+import { Project } from "@/types/proto/v1/project_service";-export default defineComponent({- name: "ProjectWebhookPanel",- components: {- ProjectWebhookCard,+const props = defineProps({+ project: {+ required: true,+ type: Object as PropType<Project>,},- props: {- project: {- required: true,- type: Object as PropType<Project>,- },- allowEdit: {- default: true,- type: Boolean,- },+ allowEdit: {+ default: true,+ type: Boolean,},- setup(props) {- const router = useRouter();- const projectWebhookStore = useProjectWebhookStore();-- const prepareProjectWebhookList = () => {- projectWebhookStore.fetchProjectWebhookListByProjectId(props.project.id);- };-- watchEffect(prepareProjectWebhookList);-- const projectWebhookList = computed(() => {- return projectWebhookStore.projectWebhookListByProjectId(- props.project.id- );- });-- const addProjectWebhook = () => {- router.push({- name: "workspace.project.hook.create",- });- };+});+const router = useRouter();- return {- projectWebhookList,- addProjectWebhook,- };- },+const projectWebhookList = computed(() => {+ return props.project.webhooks;});++const addProjectWebhook = () => {+ router.push({+ name: "workspace.project.hook.create",+ });+};</script>diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 84c1e40edd..f7e2bbeaf5 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -37,7 +37,6 @@ import Home from "../views/Home.vue";import {hasFeature,useVCSStore,- useProjectWebhookStore,useDataSourceStore,useSQLReviewStore,useProjectStore,@@ -58,6 +57,7 @@ import {useSubscriptionStore,useUserStore,useProjectV1Store,+ useProjectWebhookV1Store,} from "@/store";import { useConversationStore } from "@/plugins/ai/store";import { PlanType } from "@/types/proto/v1/subscription_service";@@ -836,11 +836,17 @@ const routes: Array<RouteRecordRaw> = [const projectSlug = route.params.projectSlug as string;const projectWebhookSlug = route.params.projectWebhookSlug as string;- return `${t("common.webhook")} - ${- useProjectWebhookStore().projectWebhookById(- idFromSlug(projectSlug),+ const project = useProjectV1Store().getProjectByUID(+ idFromSlug(projectSlug)+ );+ const webhook =+ useProjectWebhookV1Store().getProjectWebhookFromProjectById(+ project,idFromSlug(projectWebhookSlug)- ).name+ );++ return `${t("common.webhook")} - ${+ webhook?.title ?? "unknown"}`;},allowBookmark: true,@@ -1123,9 +1129,9 @@ router.beforeEach((to, from, next) => {const environmentStore = useEnvironmentStore();const instanceStore = useInstanceStore();const routerStore = useRouterStore();- const projectWebhookStore = useProjectWebhookStore();const projectStore = useProjectStore();const projectV1Store = useProjectV1Store();+ const projectWebhookV1Store = useProjectWebhookV1Store();const isLoggedIn = authStore.isLoggedIn();@@ -1446,25 +1452,24 @@ router.beforeEach((to, from, next) => {projectStore.fetchProjectById(idFromSlug(projectSlug)).then(() => projectV1Store.fetchProjectByUID(idFromSlug(projectSlug)))- .then(() => {+ .then((project) => {if (!projectWebhookSlug) {next();} else {- projectWebhookStore- .fetchProjectWebhookById({- projectId: idFromSlug(projectSlug),- projectWebhookId: idFromSlug(projectWebhookSlug),- })- .then(() => {- next();- })- .catch((error) => {- next({- name: "error.404",- replace: false,- });- throw error;+ const webhook =+ projectWebhookV1Store.getProjectWebhookFromProjectById(+ project,+ idFromSlug(projectWebhookSlug)+ );+ if (webhook) {+ next();+ } else {+ next({+ name: "error.404",+ replace: false,});+ throw new Error("not found");+ }}}).catch((error) => {diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex 46ac154d19..a5f6942262 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -24,7 +24,6 @@ export * from "./policy";export * from "./slowQueryPolicy";export * from "./principal";export * from "./project";-export * from "./projectWebhook";export * from "./repository";export * from "./router";export * from "./setting";@@ -53,3 +52,5 @@ export * from "./slowQuery";export * from "./role";export * from "./v1";++export * from "./utils";diff --git a/frontend/src/store/modules/projectWebhook.ts b/frontend/src/store/modules/projectWebhook.tsdeleted file mode 100644index 229713b282..0000000000--- a/frontend/src/store/modules/projectWebhook.ts+++ /dev/null@@ -1,214 +0,0 @@-import { defineStore } from "pinia";-import axios from "axios";-import {- ProjectId,- ProjectWebhook,- ProjectWebhookCreate,- ProjectWebhookId,- ProjectWebhookPatch,- ProjectWebhookState,- ProjectWebhookTestResult,- ResourceObject,- unknown,-} from "@/types";--function convert(- projectWebhook: ResourceObject,- includedList: ResourceObject[]-): ProjectWebhook {- return {- ...(projectWebhook.attributes as Omit<ProjectWebhook, "id">),- id: parseInt(projectWebhook.id),- };-}--function convertTestResult(- testResult: ResourceObject-): ProjectWebhookTestResult {- return {- ...(testResult.attributes as ProjectWebhookTestResult),- };-}--export const useProjectWebhookStore = defineStore("projectWebhook", {- state: (): ProjectWebhookState => ({- projectWebhookList: new Map(),- }),-- actions: {- projectWebhookListByProjectId(projectId: ProjectId): ProjectWebhook[] {- return this.projectWebhookList.get(projectId) || [];- },- projectWebhookById(- projectId: ProjectId,- projectWebhookId: ProjectWebhookId- ): ProjectWebhook {- const list = this.projectWebhookList.get(projectId);- if (list) {- for (const hook of list) {- if (hook.id == projectWebhookId) {- return hook;- }- }- }- return unknown("PROJECT_HOOK") as ProjectWebhook;- },- async createProjectWebhook({- projectId,- projectWebhookCreate,- }: {- projectId: ProjectId;- projectWebhookCreate: ProjectWebhookCreate;- }): Promise<ProjectWebhook> {- const data = (- await axios.post(`/api/project/${projectId}/webhook`, {- data: {- type: "projectWebhookCreate",- attributes: projectWebhookCreate,- },- })- ).data;- const createdProjectWebhook = convert(data.data, data.included);-- this.upsertProjectWebhookByProjectId({- projectId,- projectWebhook: createdProjectWebhook,- });-- return createdProjectWebhook;- },-- async fetchProjectWebhookListByProjectId(- projectId: ProjectId- ): Promise<ProjectWebhook[]> {- const data = (await axios.get(`/api/project/${projectId}/webhook`)).data;- const projectWebhookList = data.data.map(- (projectWebhook: ResourceObject) => {- return convert(projectWebhook, data.included);- }- );-- this.setProjectWebhookListByProjectId({- projectId,- projectWebhookList,- });-- return projectWebhookList;- },-- async fetchProjectWebhookById({- projectId,- projectWebhookId,- }: {- projectId: ProjectId;- projectWebhookId: ProjectWebhookId;- }): Promise<ProjectWebhook> {- const data = (- await axios.get(`/api/project/${projectId}/webhook/${projectWebhookId}`)- ).data;- const projectWebhook = convert(data.data, data.included);-- this.upsertProjectWebhookByProjectId({- projectId,- projectWebhook,- });-- return projectWebhook;- },-- async updateProjectWebhookById({- projectId,- projectWebhookId,- projectWebhookPatch,- }: {- projectId: ProjectId;- projectWebhookId: ProjectWebhookId;- projectWebhookPatch: ProjectWebhookPatch;- }) {- const data = (- await axios.patch(- `/api/project/${projectId}/webhook/${projectWebhookId}`,- {- data: {- type: "projectWebhookPatch",- attributes: projectWebhookPatch,- },- }- )- ).data;- const updatedProjectWebhook = convert(data.data, data.included);-- this.upsertProjectWebhookByProjectId({- projectId,- projectWebhook: updatedProjectWebhook,- });-- return updatedProjectWebhook;- },-- async deleteProjectWebhookById({- projectId,- projectWebhookId,- }: {- projectId: ProjectId;- projectWebhookId: ProjectWebhookId;- }) {- await axios.delete(- `/api/project/${projectId}/webhook/${projectWebhookId}`- );-- const list = this.projectWebhookList.get(projectId);- if (list) {- const i = list.findIndex((item) => item.id == projectWebhookId);- if (i >= 0) {- list.splice(i, 1);- }- }- },-- async testProjectWebhookById({- projectId,- projectWebhookId,- }: {- projectId: ProjectId;- projectWebhookId: ProjectWebhookId;- }) {- const data = (- await axios.get(- `/api/project/${projectId}/webhook/${projectWebhookId}/test`- )- ).data;-- return convertTestResult(data.data);- },- setProjectWebhookListByProjectId({- projectId,- projectWebhookList,- }: {- projectId: ProjectId;- projectWebhookList: ProjectWebhook[];- }) {- this.projectWebhookList.set(projectId, projectWebhookList);- },-- upsertProjectWebhookByProjectId({- projectId,- projectWebhook,- }: {- projectId: ProjectId;- projectWebhook: ProjectWebhook;- }) {- const list = this.projectWebhookList.get(projectId);- if (list) {- const i = list.findIndex((item) => item.id == projectWebhook.id);- if (i >= 0) {- list[i] = projectWebhook;- } else {- list.push(projectWebhook);- }- } else {- this.projectWebhookList.set(projectId, [projectWebhook]);- }- },- },-});diff --git a/frontend/src/store/modules/v1/index.ts b/frontend/src/store/modules/v1/index.tsindex ac217a851e..122ea63357 100644--- a/frontend/src/store/modules/v1/index.ts+++ b/frontend/src/store/modules/v1/index.ts@@ -1,4 +1,5 @@export * from "./project";export * from "./projectIamPolicy";+export * from "./projectWebhook";export * from "./deploymentConfig";export * from "./databaseSecret";diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.tsindex 57d7b617ec..e89c61397d 100644--- a/frontend/src/store/modules/v1/project.ts+++ b/frontend/src/store/modules/v1/project.ts@@ -111,6 +111,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {return {projectMapByName,projectList,+ upsertProjectMap,getProjectByUID,fetchProjectList,fetchProjectByName,diff --git a/frontend/src/store/modules/v1/projectWebhook.ts b/frontend/src/store/modules/v1/projectWebhook.tsnew file mode 100644index 0000000000..f769dea0c2--- /dev/null+++ b/frontend/src/store/modules/v1/projectWebhook.ts@@ -0,0 +1,62 @@+import { defineStore } from "pinia";+import { projectServiceClient } from "@/grpcweb";++import { Project, Webhook } from "@/types/proto/v1/project_service";+import { useProjectV1Store } from "./project";+import { IdType } from "@/types";+import { extractProjectWebhookID } from "@/utils";++export const useProjectWebhookV1Store = defineStore("projectWebhook_v1", () => {+ const getProjectWebhookFromProjectById = (+ project: Project,+ webhookId: IdType+ ) => {+ if (typeof webhookId === "string") {+ webhookId = parseInt(webhookId, 10);+ }+ return project.webhooks.find((webhook) => {+ return parseInt(extractProjectWebhookID(webhook.name), 10) === webhookId;+ });+ };+ const createProjectWebhook = async (project: Project, webhook: Webhook) => {+ const updatedProject = await projectServiceClient.addWebhook({+ project: project.name,+ webhook,+ });+ await useProjectV1Store().upsertProjectMap([updatedProject]);+ return updatedProject;+ };+ const updateProjectWebhook = async (+ webhook: Webhook,+ updateMask: string[]+ ) => {+ const updatedProject = await projectServiceClient.updateWebhook({+ webhook,+ updateMask,+ });+ await useProjectV1Store().upsertProjectMap([updatedProject]);+ return updatedProject;+ };+ const deleteProjectWebhook = async (webhook: Webhook) => {+ const updatedProject = await projectServiceClient.removeWebhook({+ webhook,+ });+ await useProjectV1Store().upsertProjectMap([updatedProject]);+ return updatedProject;+ };+ const testProjectWebhook = async (project: Project, webhook: Webhook) => {+ const response = await projectServiceClient.testWebhook({+ project: project.name,+ webhook,+ });+ return response;+ };++ return {+ getProjectWebhookFromProjectById,+ createProjectWebhook,+ updateProjectWebhook,+ deleteProjectWebhook,+ testProjectWebhook,+ };+});diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex af89b46019..048b6c8bde 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -14,7 +14,6 @@ import { Member } from "./member";import { Pipeline, Stage, Task, TaskProgress } from "./pipeline";import { Principal } from "./principal";import { Project, ProjectMember } from "./project";-import { ProjectWebhook } from "./projectWebhook";import { Repository } from "./repository";import { VCS } from "./vcs";import { Policy, DefaultApprovalPolicy } from "./policy";@@ -110,7 +109,6 @@ export type ResourceType =| "MEMBER"| "ENVIRONMENT"| "PROJECT"- | "PROJECT_HOOK"| "PROJECT_MEMBER"| "INSTANCE"| "DATABASE"@@ -138,7 +136,6 @@ interface ResourceMaker {(type: "MEMBER"): Member;(type: "ENVIRONMENT"): Environment;(type: "PROJECT"): Project;- (type: "PROJECT_HOOK"): ProjectWebhook;(type: "PROJECT_MEMBER"): ProjectMember;(type: "INSTANCE"): Instance;(type: "DATABASE"): Database;@@ -202,15 +199,6 @@ const makeUnknown = (type: ResourceType) => {schemaChangeType: "DDL",};- const UNKNOWN_PROJECT_HOOK: ProjectWebhook = {- id: UNKNOWN_ID,- projectId: UNKNOWN_ID,- type: "",- name: "",- url: "",- activityList: [],- };-const UNKNOWN_PROJECT_MEMBER: ProjectMember = {id: `projects/${UNKNOWN_ID}/roles/${UNKNOWN_ID}/principals/${UNKNOWN_ID}`,project: UNKNOWN_PROJECT,@@ -473,8 +461,6 @@ const makeUnknown = (type: ResourceType) => {return UNKNOWN_ENVIRONMENT;case "PROJECT":return UNKNOWN_PROJECT;- case "PROJECT_HOOK":- return UNKNOWN_PROJECT_HOOK;case "PROJECT_MEMBER":return UNKNOWN_PROJECT_MEMBER;case "INSTANCE":@@ -558,15 +544,6 @@ const makeEmpty = (type: ResourceType) => {schemaChangeType: "DDL",};- const EMPTY_PROJECT_HOOK: ProjectWebhook = {- id: EMPTY_ID,- projectId: EMPTY_ID,- type: "",- name: "",- url: "",- activityList: [],- };-const EMPTY_PROJECT_MEMBER: ProjectMember = {id: `projects/${EMPTY_ID}/roles/${EMPTY_ID}/principals/${EMPTY_ID}`,project: EMPTY_PROJECT,@@ -838,8 +815,6 @@ const makeEmpty = (type: ResourceType) => {return EMPTY_ENVIRONMENT;case "PROJECT":return EMPTY_PROJECT;- case "PROJECT_HOOK":- return EMPTY_PROJECT_HOOK;case "PROJECT_MEMBER":return EMPTY_PROJECT_MEMBER;case "INSTANCE":diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 5b721f6db3..21b5f278b6 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -28,7 +28,6 @@ export * from "./plan";export * from "./policy";export * from "./principal";export * from "./project";-export * from "./projectWebhook";export * from "./repository";export * from "./sql";export * from "./sqlAdvice";diff --git a/frontend/src/types/mfa.ts b/frontend/src/types/mfa.tsindex e69de29bb2..892ab66e1e 100644--- a/frontend/src/types/mfa.ts+++ b/frontend/src/types/mfa.ts@@ -0,0 +1,3 @@+// make linter happy+// remove this if we really have something to export+export {};diff --git a/frontend/src/types/projectWebhook.ts b/frontend/src/types/projectWebhook.tsdeleted file mode 100644index faedf77ac2..0000000000--- a/frontend/src/types/projectWebhook.ts+++ /dev/null@@ -1,123 +0,0 @@-import { ActivityType } from "./activity";-import { MemberId, ProjectId } from "./id";-import { t } from "../plugins/i18n";--type ProjectWebhookTypeItem = {- type: string;- name: string;- urlPrefix: string;-};--export const PROJECT_HOOK_TYPE_ITEM_LIST: () => ProjectWebhookTypeItem[] =- () => [- {- type: "bb.plugin.webhook.slack",- name: t("common.slack"),- urlPrefix: "https://hooks.slack.com/",- },- {- type: "bb.plugin.webhook.discord",- name: t("common.discord"),- urlPrefix: "https://discord.com/api/webhooks",- },- {- type: "bb.plugin.webhook.teams",- name: t("common.teams"),- urlPrefix: "",- },- {- type: "bb.plugin.webhook.dingtalk",- name: t("common.dingtalk"),- urlPrefix: "https://oapi.dingtalk.com",- },- {- type: "bb.plugin.webhook.feishu",- name: t("common.feishu"),- urlPrefix: "https://open.feishu.cn",- },- {- type: "bb.plugin.webhook.wecom",- name: t("common.wecom"),- urlPrefix: "https://qyapi.weixin.qq.com",- },- {- type: "bb.plugin.webhook.custom",- name: t("common.custom"),- urlPrefix:- "https://bytebase.com/docs/administration/webhook-integration/project-webhook#custom?source=console",- },- ];--type ProjectWebhookActivityItem = {- title: string;- label: string;- activity: ActivityType;-};--export const PROJECT_HOOK_ACTIVITY_ITEM_LIST: () => ProjectWebhookActivityItem[] =- () => [- {- title: t("project.webhook.activity-item.issue-creation.title"),- label: t("project.webhook.activity-item.issue-creation.label"),- activity: "bb.issue.create",- },- {- title: t("project.webhook.activity-item.issue-status-change.title"),- label: t("project.webhook.activity-item.issue-status-change.label"),- activity: "bb.issue.status.update",- },- {- title: t("project.webhook.activity-item.issue-stage-status-change.title"),- label: t("project.webhook.activity-item.issue-stage-status-change.label"),- activity: "bb.pipeline.stage.status.update",- },- {- title: t("project.webhook.activity-item.issue-task-status-change.title"),- label: t("project.webhook.activity-item.issue-task-status-change.label"),- activity: "bb.pipeline.task.status.update",- },- {- title: t("project.webhook.activity-item.issue-info-change.title"),- label: t("project.webhook.activity-item.issue-info-change.label"),- activity: "bb.issue.field.update",- },- {- title: t("project.webhook.activity-item.issue-comment-creation.title"),- label: t("project.webhook.activity-item.issue-comment-creation.label"),- activity: "bb.issue.comment.create",- },- ];--// Project Member-export type ProjectWebhook = {- id: MemberId;-- // Related fields- projectId: ProjectId;-- // Domain specific fields- type: string;- name: string;- url: string;- activityList: ActivityType[];-};--export type ProjectWebhookCreate = {- // Domain specific fields- type: string;- name: string;- url: string;- activityList: ActivityType[];-};--export type ProjectWebhookPatch = {- // Domain specific fields- name?: string;- url?: string;- // Comma separated list. Server doesn't support deserialize into pointer to string array (*[]string in Golang)- activityList?: string;-};--export type ProjectWebhookTestResult = {- error?: string;-};diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 9e384de5a1..7061117bf8 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -36,7 +36,6 @@ import { Member } from "./member";import { Notification } from "./notification";import { Principal } from "./principal";import { Project } from "./project";-import { ProjectWebhook } from "./projectWebhook";import { Repository } from "./repository";import { Setting, SettingName } from "./setting";import { VCS } from "./vcs";@@ -110,10 +109,6 @@ export interface ProjectState {projectById: Map<ProjectId, Project>;}-export interface ProjectWebhookState {- projectWebhookList: Map<ProjectId, ProjectWebhook[]>;-}-export interface EnvironmentState {environmentList: Environment[];}diff --git a/frontend/src/types/v1/index.ts b/frontend/src/types/v1/index.tsindex 9ff8c7dff4..0e85ce1f25 100644--- a/frontend/src/types/v1/index.ts+++ b/frontend/src/types/v1/index.ts@@ -1 +1,2 @@export * from "./project";+export * from "./projectWebhook";diff --git a/frontend/src/types/v1/projectWebhook.ts b/frontend/src/types/v1/projectWebhook.tsnew file mode 100644index 0000000000..5ae0632d83--- /dev/null+++ b/frontend/src/types/v1/projectWebhook.ts@@ -0,0 +1,114 @@+import { t } from "@/plugins/i18n";+import { EMPTY_ID } from "../const";+import {+ Activity_Type,+ Webhook,+ Webhook_Type,+} from "../proto/v1/project_service";++export const emptyProjectWebhook = () => {+ return Webhook.fromJSON({+ name: `projects/${EMPTY_ID}/webhooks/${EMPTY_ID}`,+ type: Webhook_Type.TYPE_SLACK,+ title: "",+ url: "",+ notificationTypes: [Activity_Type.TYPE_ISSUE_STATUS_UPDATE],+ });+};++type ProjectWebhookV1TypeItem = {+ type: Webhook_Type;+ name: string;+ urlPrefix: string;+};++export const projectWebhookV1TypeItemList = (): ProjectWebhookV1TypeItem[] => {+ return [+ {+ type: Webhook_Type.TYPE_SLACK,+ name: t("common.slack"),+ urlPrefix: "https://hooks.slack.com/",+ },+ {+ type: Webhook_Type.TYPE_DISCORD,+ name: t("common.discord"),+ urlPrefix: "https://discord.com/api/webhooks",+ },+ {+ type: Webhook_Type.TYPE_TEAMS,+ name: t("common.teams"),+ urlPrefix: "",+ },+ {+ type: Webhook_Type.TYPE_DINGTALK,+ name: t("common.dingtalk"),+ urlPrefix: "https://oapi.dingtalk.com",+ },+ {+ type: Webhook_Type.TYPE_FEISHU,+ name: t("common.feishu"),+ urlPrefix: "https://open.feishu.cn",+ },+ {+ type: Webhook_Type.TYPE_WECOM,+ name: t("common.wecom"),+ urlPrefix: "https://qyapi.weixin.qq.com",+ },+ {+ type: Webhook_Type.TYPE_CUSTOM,+ name: t("common.custom"),+ urlPrefix:+ "https://bytebase.com/docs/administration/webhook-integration/project-webhook#custom?source=console",+ },+ ];+};++type ProjectWebhookV1ActivityItem = {+ title: string;+ label: string;+ activity: Activity_Type;+};++export const projectWebhookV1ActivityItemList =+ (): ProjectWebhookV1ActivityItem[] => {+ return [+ {+ title: t("project.webhook.activity-item.issue-creation.title"),+ label: t("project.webhook.activity-item.issue-creation.label"),+ activity: Activity_Type.TYPE_ISSUE_CREATE,+ },+ {+ title: t("project.webhook.activity-item.issue-status-change.title"),+ label: t("project.webhook.activity-item.issue-status-change.label"),+ activity: Activity_Type.TYPE_ISSUE_STATUS_UPDATE,+ },+ {+ title: t(+ "project.webhook.activity-item.issue-stage-status-change.title"+ ),+ label: t(+ "project.webhook.activity-item.issue-stage-status-change.label"+ ),+ activity: Activity_Type.TYPE_ISSUE_PIPELINE_STAGE_STATUS_UPDATE,+ },+ {+ title: t(+ "project.webhook.activity-item.issue-task-status-change.title"+ ),+ label: t(+ "project.webhook.activity-item.issue-task-status-change.label"+ ),+ activity: Activity_Type.TYPE_ISSUE_PIPELINE_TASK_STATUS_UPDATE,+ },+ {+ title: t("project.webhook.activity-item.issue-info-change.title"),+ label: t("project.webhook.activity-item.issue-info-change.label"),+ activity: Activity_Type.TYPE_ISSUE_FIELD_UPDATE,+ },+ {+ title: t("project.webhook.activity-item.issue-comment-creation.title"),+ label: t("project.webhook.activity-item.issue-comment-creation.label"),+ activity: Activity_Type.TYPE_ISSUE_COMMENT_CREATE,+ },+ ];+ };diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.tsindex ec80118b57..70a8759398 100644--- a/frontend/src/utils/slug.ts+++ b/frontend/src/utils/slug.ts@@ -7,7 +7,6 @@ import {IssueId,MigrationHistoryId,Project,- ProjectWebhook,VCS,SQLReviewPolicy,Sheet,@@ -43,10 +42,6 @@ export function projectSlug(project: Project): string {return [slug(project.name), project.id].join("-");}-export function projectWebhookSlug(projectWebhook: ProjectWebhook): string {- return [slug(projectWebhook.name), projectWebhook.id].join("-");-}-export function instanceSlug(instance: Instance): string {return [slug(instance.environment.name),diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.tsindex c42b0a68f3..295d3e5bcd 100644--- a/frontend/src/utils/v1/index.ts+++ b/frontend/src/utils/v1/index.ts@@ -1,4 +1,4 @@-export * from "./slug";export * from "./project";+export * from "./projectWebhook";export * from "./deploymentConfig";export * from "./label";diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.tsindex c9d4470d32..c8f63d18fc 100644--- a/frontend/src/utils/v1/project.ts+++ b/frontend/src/utils/v1/project.ts@@ -1,3 +1,5 @@+import slug from "slug";+import { DEFAULT_PROJECT_V1_NAME } from "@/types";import { User } from "@/types/proto/v1/auth_service";import { State } from "@/types/proto/v1/common";@@ -8,6 +10,10 @@ import {ProjectPermissionType,} from "../role";+export function projectV1Slug(project: Project): string {+ return [slug(project.title), project.uid].join("-");+}+export const extractProjectResourceName = (name: string) => {const pattern = /(?:^|\/)projects\/([^/]+)(?:$|\/)/;const matches = name.match(pattern);diff --git a/frontend/src/utils/v1/projectWebhook.ts b/frontend/src/utils/v1/projectWebhook.tsnew file mode 100644index 0000000000..df3223a5d9--- /dev/null+++ b/frontend/src/utils/v1/projectWebhook.ts@@ -0,0 +1,13 @@+import { Webhook } from "@/types/proto/v1/project_service";+import slug from "slug";++export const extractProjectWebhookID = (name: string) => {+ const pattern = /(?:^|\/)webhooks\/([^/]+)(?:$|\/)/;+ const matches = name.match(pattern);+ return matches?.[1] ?? "";+};++export function projectWebhookV1Slug(webhook: Webhook): string {+ const id = extractProjectWebhookID(webhook.name);+ return [slug(webhook.title), id].join("-");+}diff --git a/frontend/src/utils/v1/slug.ts b/frontend/src/utils/v1/slug.tsdeleted file mode 100644index 66d11219e2..0000000000--- a/frontend/src/utils/v1/slug.ts+++ /dev/null@@ -1,7 +0,0 @@-import slug from "slug";--import type { Project } from "@/types/proto/v1/project_service";--export function projectV1Slug(project: Project): string {- return [slug(project.title), project.uid].join("-");-}diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex 556a17846f..396a30970b 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -38,7 +38,7 @@<template v-if="project.id !== DEFAULT_PROJECT_ID && hash === 'webhook'"><ProjectWebhookPanelid="webhook"- :project="project"+ :project="projectV1":allow-edit="allowEdit"/></template>diff --git a/frontend/src/views/ProjectWebhookCreate.vue b/frontend/src/views/ProjectWebhookCreate.vueindex debf8f5e24..6cf1e81cda 100644--- a/frontend/src/views/ProjectWebhookCreate.vue+++ b/frontend/src/views/ProjectWebhookCreate.vue@@ -7,7 +7,7 @@class="pt-4":create="true":project="project"- :webhook="DEFAULT_NEW_WEBHOOK"+ :webhook="defaultNewWebhook"/></div></template>@@ -16,15 +16,8 @@import { computed, defineComponent } from "vue";import ProjectWebhookForm from "../components/ProjectWebhookForm.vue";import { idFromSlug } from "../utils";-import { ProjectWebhookCreate } from "../types";-import { useProjectStore } from "@/store";--const DEFAULT_NEW_WEBHOOK: ProjectWebhookCreate = {- type: "bb.plugin.webhook.slack",- name: "",- url: "",- activityList: ["bb.issue.status.update"],-};+import { useProjectV1Store } from "@/store";+import { emptyProjectWebhook } from "@/types";export default defineComponent({name: "ProjectWebhookCreate",@@ -36,14 +29,16 @@ export default defineComponent({},},setup(props) {- const projectStore = useProjectStore();+ const projectV1Store = useProjectV1Store();const project = computed(() => {- return projectStore.getProjectById(idFromSlug(props.projectSlug));+ return projectV1Store.getProjectByUID(idFromSlug(props.projectSlug));});+ const defaultNewWebhook = emptyProjectWebhook();+return {- DEFAULT_NEW_WEBHOOK,+ defaultNewWebhook,project,};},diff --git a/frontend/src/views/ProjectWebhookDetail.vue b/frontend/src/views/ProjectWebhookDetail.vueindex f6a82cb88c..e2ede16477 100644--- a/frontend/src/views/ProjectWebhookDetail.vue+++ b/frontend/src/views/ProjectWebhookDetail.vue@@ -4,33 +4,31 @@<div class="flex flex-row space-x-2 items-center"><!-- This awkward code is author couldn't figure out proper way to use dynamic src under vitehttps://github.com/vitejs/vite/issues/1265 -->- <template v-if="projectWebhook.type == 'bb.plugin.webhook.slack'">+ <template v-if="projectWebhook.type === Webhook_Type.TYPE_SLACK"><img class="h-6 w-6" src="../assets/slack-logo.png" alt="" /></template>- <template- v-else-if="projectWebhook.type == 'bb.plugin.webhook.discord'"- >+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_DISCORD"><img class="h-6 w-6" src="../assets/discord-logo.svg" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.teams'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_TEAMS"><img class="h-6 w-6" src="../assets/teams-logo.svg" /></template><template- v-else-if="projectWebhook.type == 'bb.plugin.webhook.dingtalk'"+ v-else-if="projectWebhook.type === Webhook_Type.TYPE_DINGTALK"><img class="h-6 w-6" src="../assets/dingtalk-logo.png" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.feishu'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_FEISHU"><img class="h-6 w-6" src="../assets/feishu-logo.webp" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.wecom'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_WECOM"><img class="h-6 w-6" src="../assets/wecom-logo.png" /></template>- <template v-else-if="projectWebhook.type == 'bb.plugin.webhook.custom'">+ <template v-else-if="projectWebhook.type === Webhook_Type.TYPE_CUSTOM"><heroicons-outline:puzzle class="w-6 h-6" /></template><h3 class="text-xl leading-6 font-medium text-main">- {{ projectWebhook.name }}+ {{ projectWebhook.title }}</h3></div><button@@ -51,81 +49,74 @@</div></template>-<script lang="ts">-import { computed, defineComponent } from "vue";+<script lang="ts" setup>+import { computed } from "vue";+import { useI18n } from "vue-i18n";+import ProjectWebhookForm from "../components/ProjectWebhookForm.vue";import { idFromSlug } from "../utils";-import { ProjectWebhookTestResult } from "../types";-import { useI18n } from "vue-i18n";import {pushNotification,- useProjectWebhookStore,- useProjectStore,+ useProjectV1Store,+ useProjectWebhookV1Store,+ useGracefulRequest,} from "@/store";+import { Webhook_Type } from "@/types/proto/v1/project_service";+import { emptyProjectWebhook } from "@/types";-export default defineComponent({- name: "ProjectWebhookDetail",- components: { ProjectWebhookForm },- props: {- projectSlug: {- required: true,- type: String,- },- projectWebhookSlug: {- required: true,- type: String,- },- allowEdit: {- required: true,- type: Boolean,- },+const props = defineProps({+ projectSlug: {+ required: true,+ type: String,},- setup(props) {- const { t } = useI18n();- const projectWebhookStore = useProjectWebhookStore();- const projectStore = useProjectStore();-- const project = computed(() => {- return projectStore.getProjectById(idFromSlug(props.projectSlug));- });+ projectWebhookSlug: {+ required: true,+ type: String,+ },+ allowEdit: {+ required: true,+ type: Boolean,+ },+});- const projectWebhook = computed(() => {- return projectWebhookStore.projectWebhookById(- idFromSlug(props.projectSlug),- idFromSlug(props.projectWebhookSlug)- );- });+const { t } = useI18n();+const projectV1Store = useProjectV1Store();+const projectWebhookV1Store = useProjectWebhookV1Store();- const testWebhook = () => {- projectWebhookStore- .testProjectWebhookById({- projectId: idFromSlug(props.projectSlug),- projectWebhookId: idFromSlug(props.projectWebhookSlug),- })- .then((testResult: ProjectWebhookTestResult) => {- if (testResult.error) {- pushNotification({- module: "bytebase",- style: "CRITICAL",- title: t("project.webhook.fail-tested-title"),- description: testResult.error,- manualHide: true,- });- } else {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("project.webhook.success-tested-prompt"),- });- }- });- };+const project = computed(() => {+ return projectV1Store.getProjectByUID(idFromSlug(props.projectSlug));+});- return {- project,- projectWebhook,- testWebhook,- };- },+const projectWebhook = computed(() => {+ const id = idFromSlug(props.projectWebhookSlug);+ return (+ projectWebhookV1Store.getProjectWebhookFromProjectById(project.value, id) ??+ emptyProjectWebhook()+ );});++const testWebhook = () => {+ useGracefulRequest(async () => {+ const result = await useProjectWebhookV1Store().testProjectWebhook(+ project.value,+ projectWebhook.value+ );++ if (result.error) {+ pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: t("project.webhook.fail-tested-title"),+ description: result.error,+ manualHide: true,+ });+ } else {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("project.webhook.success-tested-prompt"),+ });+ }+ });+};</script>