Skip to content

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

ProjectHook related CRUD UI

天舟6aef685cb3ab
diff --git a/frontend/src/assets/dingtalk-logo.png b/frontend/src/assets/dingtalk-logo.png
new file mode 100644
index 0000000000..70b31a0bfb
Binary files /dev/null and b/frontend/src/assets/dingtalk-logo.png differ
diff --git a/frontend/src/assets/discord-logo.svg b/frontend/src/assets/discord-logo.svg
new file mode 100644
index 0000000000..3efe1ec110
--- /dev/null
+++ b/frontend/src/assets/discord-logo.svg
@@ -0,0 +1,10 @@
+<svg width="71" height="55" viewBox="0 0 71 55" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g clip-path="url(#clip0)">
+<path d="M60.1045 4.8978C55.5792 2.8214 50.7265 1.2916 45.6527 0.41542C45.5603 0.39851 45.468 0.440769 45.4204 0.525289C44.7963 1.6353 44.105 3.0834 43.6209 4.2216C38.1637 3.4046 32.7345 3.4046 27.3892 4.2216C26.905 3.0581 26.1886 1.6353 25.5617 0.525289C25.5141 0.443589 25.4218 0.40133 25.3294 0.41542C20.2584 1.2888 15.4057 2.8186 10.8776 4.8978C10.8384 4.9147 10.8048 4.9429 10.7825 4.9795C1.57795 18.7309 -0.943561 32.1443 0.293408 45.3914C0.299005 45.4562 0.335386 45.5182 0.385761 45.5576C6.45866 50.0174 12.3413 52.7249 18.1147 54.5195C18.2071 54.5477 18.305 54.5139 18.3638 54.4378C19.7295 52.5728 20.9469 50.6063 21.9907 48.5383C22.0523 48.4172 21.9935 48.2735 21.8676 48.2256C19.9366 47.4931 18.0979 46.6 16.3292 45.5858C16.1893 45.5041 16.1781 45.304 16.3068 45.2082C16.679 44.9293 17.0513 44.6391 17.4067 44.3461C17.471 44.2926 17.5606 44.2813 17.6362 44.3151C29.2558 49.6202 41.8354 49.6202 53.3179 44.3151C53.3935 44.2785 53.4831 44.2898 53.5502 44.3433C53.9057 44.6363 54.2779 44.9293 54.6529 45.2082C54.7816 45.304 54.7732 45.5041 54.6333 45.5858C52.8646 46.6197 51.0259 47.4931 49.0921 48.2228C48.9662 48.2707 48.9102 48.4172 48.9718 48.5383C50.038 50.6034 51.2554 52.5699 52.5959 54.435C52.6519 54.5139 52.7526 54.5477 52.845 54.5195C58.6464 52.7249 64.529 50.0174 70.6019 45.5576C70.6551 45.5182 70.6887 45.459 70.6943 45.3942C72.1747 30.0791 68.2147 16.7757 60.1968 4.9823C60.1772 4.9429 60.1437 4.9147 60.1045 4.8978ZM23.7259 37.3253C20.2276 37.3253 17.3451 34.1136 17.3451 30.1693C17.3451 26.225 20.1717 23.0133 23.7259 23.0133C27.308 23.0133 30.1626 26.2532 30.1066 30.1693C30.1066 34.1136 27.28 37.3253 23.7259 37.3253ZM47.3178 37.3253C43.8196 37.3253 40.9371 34.1136 40.9371 30.1693C40.9371 26.225 43.7636 23.0133 47.3178 23.0133C50.9 23.0133 53.7545 26.2532 53.6986 30.1693C53.6986 34.1136 50.9 37.3253 47.3178 37.3253Z" fill="#5865F2"/>
+</g>
+<defs>
+<clipPath id="clip0">
+<rect width="71" height="55" fill="white"/>
+</clipPath>
+</defs>
+</svg>
diff --git a/frontend/src/assets/feishu-logo.png b/frontend/src/assets/feishu-logo.png
new file mode 100644
index 0000000000..8d10f4c945
Binary files /dev/null and b/frontend/src/assets/feishu-logo.png differ
diff --git a/frontend/src/assets/slack-logo.png b/frontend/src/assets/slack-logo.png
new file mode 100644
index 0000000000..d07f61893d
Binary files /dev/null and b/frontend/src/assets/slack-logo.png differ
diff --git a/frontend/src/assets/teams-logo.svg b/frontend/src/assets/teams-logo.svg
new file mode 100644
index 0000000000..3409e6cfae
--- /dev/null
+++ b/frontend/src/assets/teams-logo.svg
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2228.833 2073.333">
+ <path fill="#5059C9" d="M1554.637,777.5h575.713c54.391,0,98.483,44.092,98.483,98.483c0,0,0,0,0,0v524.398 c0,199.901-162.051,361.952-361.952,361.952h0h-1.711c-199.901,0.028-361.975-162-362.004-361.901c0-0.017,0-0.034,0-0.052V828.971 C1503.167,800.544,1526.211,777.5,1554.637,777.5L1554.637,777.5z"/>
+ <circle fill="#5059C9" cx="1943.75" cy="440.583" r="233.25"/>
+ <circle fill="#7B83EB" cx="1218.083" cy="336.917" r="336.917"/>
+ <path fill="#7B83EB" d="M1667.323,777.5H717.01c-53.743,1.33-96.257,45.931-95.01,99.676v598.105 c-7.505,322.519,247.657,590.16,570.167,598.053c322.51-7.893,577.671-275.534,570.167-598.053V877.176 C1763.579,823.431,1721.066,778.83,1667.323,777.5z"/>
+ <path opacity=".1" d="M1244,777.5v838.145c-0.258,38.435-23.549,72.964-59.09,87.598 c-11.316,4.787-23.478,7.254-35.765,7.257H667.613c-6.738-17.105-12.958-34.21-18.142-51.833 c-18.144-59.477-27.402-121.307-27.472-183.49V877.02c-1.246-53.659,41.198-98.19,94.855-99.52H1244z"/>
+ <path opacity=".2" d="M1192.167,777.5v889.978c-0.002,12.287-2.47,24.449-7.257,35.765 c-14.634,35.541-49.163,58.833-87.598,59.09H691.975c-8.812-17.105-17.105-34.21-24.362-51.833 c-7.257-17.623-12.958-34.21-18.142-51.833c-18.144-59.476-27.402-121.307-27.472-183.49V877.02 c-1.246-53.659,41.198-98.19,94.855-99.52H1192.167z"/>
+ <path opacity=".2" d="M1192.167,777.5v786.312c-0.395,52.223-42.632,94.46-94.855,94.855h-447.84 c-18.144-59.476-27.402-121.307-27.472-183.49V877.02c-1.246-53.659,41.198-98.19,94.855-99.52H1192.167z"/>
+ <path opacity=".2" d="M1140.333,777.5v786.312c-0.395,52.223-42.632,94.46-94.855,94.855H649.472 c-18.144-59.476-27.402-121.307-27.472-183.49V877.02c-1.246-53.659,41.198-98.19,94.855-99.52H1140.333z"/>
+ <path opacity=".1" d="M1244,509.522v163.275c-8.812,0.518-17.105,1.037-25.917,1.037 c-8.812,0-17.105-0.518-25.917-1.037c-17.496-1.161-34.848-3.937-51.833-8.293c-104.963-24.857-191.679-98.469-233.25-198.003 c-7.153-16.715-12.706-34.071-16.587-51.833h258.648C1201.449,414.866,1243.801,457.217,1244,509.522z"/>
+ <path opacity=".2" d="M1192.167,561.355v111.442c-17.496-1.161-34.848-3.937-51.833-8.293 c-104.963-24.857-191.679-98.469-233.25-198.003h190.228C1149.616,466.699,1191.968,509.051,1192.167,561.355z"/>
+ <path opacity=".2" d="M1192.167,561.355v111.442c-17.496-1.161-34.848-3.937-51.833-8.293 c-104.963-24.857-191.679-98.469-233.25-198.003h190.228C1149.616,466.699,1191.968,509.051,1192.167,561.355z"/>
+ <path opacity=".2" d="M1140.333,561.355v103.148c-104.963-24.857-191.679-98.469-233.25-198.003 h138.395C1097.783,466.699,1140.134,509.051,1140.333,561.355z"/>
+ <linearGradient id="a" gradientUnits="userSpaceOnUse" x1="198.099" y1="1683.0726" x2="942.2344" y2="394.2607" gradientTransform="matrix(1 0 0 -1 0 2075.3333)">
+ <stop offset="0" stop-color="#5a62c3"/>
+ <stop offset=".5" stop-color="#4d55bd"/>
+ <stop offset="1" stop-color="#3940ab"/>
+ </linearGradient>
+ <path fill="url(#a)" d="M95.01,466.5h950.312c52.473,0,95.01,42.538,95.01,95.01v950.312c0,52.473-42.538,95.01-95.01,95.01 H95.01c-52.473,0-95.01-42.538-95.01-95.01V561.51C0,509.038,42.538,466.5,95.01,466.5z"/>
+ <path fill="#FFF" d="M820.211,828.193H630.241v517.297H509.211V828.193H320.123V727.844h500.088V828.193z"/>
+</svg>
diff --git a/frontend/src/assets/wecom-logo.png b/frontend/src/assets/wecom-logo.png
new file mode 100644
index 0000000000..49a44f6943
Binary files /dev/null and b/frontend/src/assets/wecom-logo.png differ
diff --git a/frontend/src/components/ProjectWebhookCard.vue b/frontend/src/components/ProjectWebhookCard.vue
index 50d4fb351b..cc48550943 100644
--- a/frontend/src/components/ProjectWebhookCard.vue
+++ b/frontend/src/components/ProjectWebhookCard.vue
@@ -4,9 +4,7 @@
>
<div class="flex py-2 px-4 justify-between">
<div class="flex flex-row space-x-2 items-center">
- <!-- <template v-if="projectHook.type.startsWith('GITLAB')">
- <img class="h-6 w-auto" src="../assets/gitlab-logo.svg" />
- </template> -->
+ <img class="h-5 w-5" :src="`/src/assets/${logo}`" />
<h3 class="text-lg leading-6 font-medium text-main">
{{ projectHook.name }}
</h3>
@@ -30,26 +28,28 @@
<div class="grid grid-cols-5 gap-4 px-4 py-2 items-center">
<dt class="text-sm font-medium text-control-light">Events</dt>
<dd class="py-0.5 flex text-sm text-main col-span-4">
- {{ projectHook.activityList.join(", ") }}
+ {{ activityListStr }}
</dd>
</div>
<div class="grid grid-cols-5 gap-4 px-4 py-2 items-center">
- <dt class="text-sm font-medium text-control-light">Created by</dt>
+ <dt class="text-sm font-medium text-control-light">
+ Last updated by
+ </dt>
<dd class="py-0.5 flex items-center text-sm text-main col-span-4">
<div class="flex flex-row items-center space-x-2 mr-1">
<div class="flex flex-row items-center space-x-1">
<PrincipalAvatar
- :principal="projectHook.creator"
+ :principal="projectHook.updater"
:size="'SMALL'"
/>
<router-link
- :to="`/u/${projectHook.creator.id}`"
+ :to="`/u/${projectHook.updater.id}`"
class="normal-link"
- >{{ projectHook.creator.name }}
+ >{{ projectHook.updater.name }}
</router-link>
</div>
</div>
- at {{ humanizeTs(projectHook.createdTs) }}
+ at {{ humanizeTs(projectHook.updatedTs) }}
</dd>
</div>
</dl>
@@ -58,10 +58,15 @@
</template>
<script lang="ts">
-import { reactive, PropType } from "vue";
+import { reactive, PropType, computed } from "vue";
import { useRouter } from "vue-router";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
-import { ProjectHook, redirectURL } from "../types";
+import {
+ ProjectHook,
+ PROJECT_HOOK_TYPE_ITEM_LIST,
+ PROJECT_HOOK_EVENT_ITEM_LIST,
+ redirectURL,
+} from "../types";
import { projectHookSlug } from "../utils";
interface LocalState {}
@@ -89,10 +94,35 @@ export default {
});
};
+ const logo = computed(() => {
+ for (const item of PROJECT_HOOK_TYPE_ITEM_LIST) {
+ if (item.type == props.projectHook.type) {
+ return item.logo;
+ }
+ }
+
+ return "";
+ });
+
+ const activityListStr = computed(() => {
+ const list = props.projectHook.activityList.map((activity) => {
+ for (const item of PROJECT_HOOK_EVENT_ITEM_LIST) {
+ if (item.event == activity) {
+ return item.title;
+ }
+ }
+ return activity;
+ });
+
+ return list.join(", ");
+ });
+
return {
state,
redirectURL,
viewProjectHook,
+ logo,
+ activityListStr,
};
},
};
diff --git a/frontend/src/components/ProjectWebhookForm.vue b/frontend/src/components/ProjectWebhookForm.vue
new file mode 100644
index 0000000000..7bfd5ba322
--- /dev/null
+++ b/frontend/src/components/ProjectWebhookForm.vue
@@ -0,0 +1,362 @@
+<template>
+ <div class="space-y-4">
+ <div v-if="create">
+ <label class="textlabel"> Destination </label>
+ <div class="mt-1 grid grid-cols-1 gap-4 sm:grid-cols-6">
+ <template
+ v-for="(item, index) in PROJECT_HOOK_TYPE_ITEM_LIST"
+ :key="index"
+ >
+ <div
+ class="
+ flex
+ justify-center
+ px-2
+ py-4
+ border border-control-border
+ hover:bg-control-bg-hover
+ cursor-pointer
+ "
+ @click.capture="state.webhook.type = item.type"
+ >
+ <div class="flex flex-col items-center">
+ <img
+ class="h-10 w-10 rounded-full"
+ :src="`/src/assets/${item.logo}`"
+ alt=""
+ />
+ <p class="mt-1 text-center textlabel">
+ {{ item.name }}
+ </p>
+ <div class="mt-3 radio text-sm">
+ <input
+ type="radio"
+ class="btn"
+ :checked="state.webhook.type == item.type"
+ />
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
+ </div>
+ <div>
+ <label for="name" class="textlabel">
+ Name <span class="text-red-600">*</span>
+ </label>
+ <input
+ id="name"
+ name="name"
+ type="text"
+ class="textfield mt-1 w-full"
+ :placeholder="namePlaceholder"
+ :disabled="!allowEdit"
+ v-model="state.webhook.name"
+ />
+ </div>
+ <div>
+ <label for="url" class="textlabel">
+ Webhook URL <span class="text-red-600">*</span>
+ </label>
+ <input
+ id="url"
+ name="url"
+ type="text"
+ class="textfield mt-1 w-full"
+ :placeholder="urlPlaceholder"
+ :disabled="!allowEdit"
+ v-model="state.webhook.url"
+ />
+ </div>
+ <div>
+ <div class="text-md leading-6 font-medium text-main">Events</div>
+ <div
+ v-for="(item, index) in PROJECT_HOOK_EVENT_ITEM_LIST"
+ :key="index"
+ class="mt-4 space-y-4"
+ >
+ <BBCheckbox
+ :title="item.title"
+ :label="item.label"
+ :value="eventOn(item.event)"
+ @toggle="
+ (on) => {
+ toggleEvent(item.event, on);
+ }
+ "
+ />
+ </div>
+ </div>
+ <div
+ class="flex pt-5"
+ :class="!create && allowEdit ? 'justify-between' : 'justify-end'"
+ >
+ <BBButtonConfirm
+ v-if="!create && allowEdit"
+ :style="'DELETE'"
+ :buttonText="'Delete this webhook'"
+ :okText="'Delete'"
+ :confirmTitle="`Delete webhook '${webhook.name}' and all its execution history?`"
+ :requireConfirm="true"
+ @confirm="deleteWebhook"
+ />
+ <div>
+ <button
+ type="button"
+ class="btn-normal py-2 px-4"
+ @click.prevent="cancel"
+ >
+ {{ allowEdit ? "Cancel" : "Back" }}
+ </button>
+ <template v-if="allowEdit">
+ <button
+ v-if="create"
+ type="submit"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!allowCreate"
+ @click.prevent="createWebhook"
+ >
+ Create
+ </button>
+ <button
+ v-else
+ type="submit"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!valueChanged"
+ @click.prevent="updateWebhook"
+ >
+ Update
+ </button>
+ </template>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { reactive } from "@vue/reactivity";
+import { computed, PropType, watch } from "@vue/runtime-core";
+import {
+ ActionType,
+ Project,
+ ProjectHook,
+ ProjectHookCreate,
+ ProjectHookPatch,
+ PROJECT_HOOK_TYPE_ITEM_LIST,
+ PROJECT_HOOK_EVENT_ITEM_LIST,
+} from "../types";
+import { cloneDeep, isEmpty, isEqual } from "lodash";
+import { useRouter } from "vue-router";
+import { projectHookSlug, projectSlug } from "../utils";
+import { useStore } from "vuex";
+
+interface LocalState {
+ webhook: ProjectHook | ProjectHookCreate;
+}
+
+export default {
+ name: "ProjectWebhookForm",
+ emits: ["change-repository"],
+ 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<ProjectHook | ProjectHookCreate>,
+ },
+ },
+ components: {},
+ setup(props, { emit }) {
+ const store = useStore();
+ const router = useRouter();
+
+ const state = reactive<LocalState>({
+ webhook: cloneDeep(props.webhook),
+ });
+
+ watch(
+ () => props.webhook,
+ (cur: ProjectHook | ProjectHookCreate) => {
+ state.webhook = cloneDeep(cur);
+ }
+ );
+
+ const namePlaceholder = computed(() => {
+ if (state.webhook.type == "bb.plugin.webhook.slack") {
+ return "Slack Webhook";
+ } else if (state.webhook.type == "bb.plugin.webhook.discord") {
+ return "Discord Webhook";
+ } else if (state.webhook.type == "bb.plugin.webhook.teams") {
+ return "Teams Webhook";
+ } else if (state.webhook.type == "bb.plugin.webhook.dingtalk") {
+ return "DingTalk Webhook";
+ } else if (state.webhook.type == "bb.plugin.webhook.feishu") {
+ return "Feishu Webhook";
+ } else if (state.webhook.type == "bb.plugin.webhook.wecom") {
+ return "WeCom Webhook";
+ }
+
+ return "My 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/...";
+ }
+
+ return "Webhook URL";
+ });
+
+ const valueChanged = computed(() => {
+ return !isEqual(props.webhook, state.webhook);
+ });
+
+ const allowCreate = computed(() => {
+ return (
+ !isEmpty(state.webhook.type) &&
+ !isEmpty(state.webhook.name) &&
+ !isEmpty(state.webhook.url)
+ );
+ });
+
+ const eventOn = (type: ActionType) => {
+ for (const activityType of props.webhook.activityList) {
+ if (activityType == type) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ const toggleEvent = (type: ActionType, on: boolean) => {
+ if (on) {
+ for (const activityType of state.webhook.activityList) {
+ if (activityType == type) {
+ return;
+ }
+ }
+ state.webhook.activityList.push(type);
+ } else {
+ const list: ActionType[] = [];
+ for (const activityType of state.webhook.activityList) {
+ if (activityType != type) {
+ list.push(activityType);
+ }
+ }
+ state.webhook.activityList = list;
+ }
+ state.webhook.activityList.sort();
+ };
+
+ const cancel = () => {
+ router.push({
+ name: "workspace.project.detail",
+ params: {
+ projectSlug: projectSlug(props.project),
+ },
+ hash: "#hook",
+ });
+ };
+
+ const createWebhook = () => {
+ store
+ .dispatch("projectHook/createProjectHook", {
+ projectId: props.project.id,
+ projectHookCreate: state.webhook,
+ })
+ .then((webhook: ProjectHook) => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `Successfully created webhook "${webhook.name}".`,
+ });
+ router.push({
+ name: "workspace.project.hook.detail",
+ params: {
+ projectHookSlug: projectHookSlug(webhook),
+ },
+ });
+ });
+ };
+
+ const updateWebhook = () => {
+ const projectHookPatch: ProjectHookPatch = {};
+ if (props.webhook.name != state.webhook.name) {
+ projectHookPatch.name = state.webhook.name;
+ }
+ if (props.webhook.url != state.webhook.url) {
+ projectHookPatch.url = state.webhook.url;
+ }
+ if (props.webhook.activityList != state.webhook.activityList) {
+ projectHookPatch.activityList = state.webhook.activityList.join(",");
+ }
+ store
+ .dispatch("projectHook/updateProjectHookById", {
+ projectId: props.project.id,
+ projectHookId: (state.webhook as ProjectHook).id,
+ projectHookPatch,
+ })
+ .then((webhook: ProjectHook) => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `Successfully updated webhook "${webhook.name}".`,
+ });
+ });
+ };
+
+ const deleteWebhook = () => {
+ const name = state.webhook.name;
+ store
+ .dispatch("projectHook/deleteProjectHookById", {
+ projectId: props.project.id,
+ projectHookId: (state.webhook as ProjectHook).id,
+ })
+ .then(() => {
+ store.dispatch("notification/pushNotification", {
+ module: "bytebase",
+ style: "SUCCESS",
+ title: `Successfully deleted webhook "${name}".`,
+ });
+ cancel();
+ });
+ };
+
+ return {
+ PROJECT_HOOK_TYPE_ITEM_LIST,
+ PROJECT_HOOK_EVENT_ITEM_LIST,
+ state,
+ namePlaceholder,
+ urlPlaceholder,
+ valueChanged,
+ allowCreate,
+ eventOn,
+ toggleEvent,
+ cancel,
+ createWebhook,
+ updateWebhook,
+ deleteWebhook,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/layouts/ProjectLayout.vue b/frontend/src/layouts/ProjectLayout.vue
index 503f633dee..141087c282 100644
--- a/frontend/src/layouts/ProjectLayout.vue
+++ b/frontend/src/layouts/ProjectLayout.vue
@@ -19,9 +19,10 @@
<div class="max-w-7xl mx-auto py-6 px-6">
<router-view
- :selectedTab="state.selectedIndex"
:projectSlug="projectSlug"
:projectHookSlug="projectHookSlug"
+ :selectedTab="state.selectedIndex"
+ :allowEdit="allowEdit"
/>
</div>
</template>
@@ -30,7 +31,7 @@
import { computed, onMounted, reactive, watch } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
-import { idFromSlug } from "../utils";
+import { idFromSlug, isProjectOwner } from "../utils";
import ArchiveBanner from "../components/ArchiveBanner.vue";
const OVERVIEW_TAB = 0;
@@ -71,6 +72,8 @@ export default {
const store = useStore();
const router = useRouter();
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
const state = reactive<LocalState>({
selectedIndex: OVERVIEW_TAB,
});
@@ -81,6 +84,25 @@ export default {
);
});
+ // Only the project owner can edit the project general info and configure version control.
+ // This means even the workspace owner won't be able to edit it.
+ // On the other hand, we allow workspace owner to change project membership in case
+ // project is locked somehow. See the relevant method in ProjectMemberTable for more info.
+ const allowEdit = computed(() => {
+ if (project.value.rowStatus == "ARCHIVED") {
+ return false;
+ }
+
+ for (const member of project.value.memberList) {
+ if (member.principal.id == currentUser.value.id) {
+ if (isProjectOwner(member.role)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ });
+
const selectProjectTabOnHash = () => {
if (router.currentRoute.value.name == "workspace.project.detail") {
if (router.currentRoute.value.hash) {
@@ -126,6 +148,7 @@ export default {
return {
state,
project,
+ allowEdit,
selectTab,
projectTabItemList,
};
diff --git a/frontend/src/store/modules/projectHook.ts b/frontend/src/store/modules/projectHook.ts
index 6ce78997ee..4428929320 100644
--- a/frontend/src/store/modules/projectHook.ts
+++ b/frontend/src/store/modules/projectHook.ts
@@ -7,6 +7,7 @@ import {
ProjectHookState,
ProjectId,
ResourceObject,
+ unknown,
} from "../../types";
function convert(
@@ -33,10 +34,7 @@ const getters = {
projectHookById:
(state: ProjectHookState) =>
- (
- projectId: ProjectId,
- projectHookId: ProjectHookId
- ): ProjectHook | undefined => {
+ (projectId: ProjectId, projectHookId: ProjectHookId): ProjectHook => {
const list = state.projectHookListByProjectId.get(projectId);
if (list) {
for (const hook of list) {
@@ -45,7 +43,7 @@ const getters = {
}
}
}
- return undefined;
+ return unknown("PROJECT_HOOK") as ProjectHook;
},
};
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 6371162c79..b405bba9c7 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -12,6 +12,7 @@ import { Member } from "./member";
import { Pipeline, Stage, Task } from "./pipeline";
import { Principal } from "./principal";
import { Project, ProjectMember } from "./project";
+import { ProjectHook } from "./projectHook";
import { Repository } from "./repository";
import { VCS } from "./vcs";
@@ -86,6 +87,7 @@ export type ResourceType =
| "MEMBER"
| "ENVIRONMENT"
| "PROJECT"
+ | "PROJECT_HOOK"
| "PROJECT_MEMBER"
| "INSTANCE"
| "DATABASE"
@@ -108,6 +110,7 @@ export const unknown = (
| Member
| Environment
| Project
+ | ProjectHook
| ProjectMember
| Instance
| Database
@@ -173,6 +176,19 @@ export const unknown = (
visibility: "PUBLIC",
};
+ const UNKNOWN_PROJECT_HOOK: ProjectHook = {
+ id: UNKNOWN_ID,
+ projectId: UNKNOWN_ID,
+ creator: UNKNOWN_PRINCIPAL,
+ updater: UNKNOWN_PRINCIPAL,
+ createdTs: 0,
+ updatedTs: 0,
+ type: "",
+ name: "",
+ url: "",
+ activityList: [],
+ };
+
const UNKNOWN_PROJECT_MEMBER: ProjectMember = {
id: UNKNOWN_ID,
project: UNKNOWN_PROJECT,
@@ -365,6 +381,8 @@ export const unknown = (
return UNKNOWN_ENVIRONMENT;
case "PROJECT":
return UNKNOWN_PROJECT;
+ case "PROJECT_HOOK":
+ return UNKNOWN_PROJECT_HOOK;
case "PROJECT_MEMBER":
return UNKNOWN_PROJECT_MEMBER;
case "INSTANCE":
@@ -404,6 +422,7 @@ export const empty = (
| Member
| Environment
| Project
+ | ProjectHook
| ProjectMember
| Instance
| Database
@@ -467,6 +486,19 @@ export const empty = (
visibility: "PUBLIC",
};
+ const EMPTY_PROJECT_HOOK: ProjectHook = {
+ id: EMPTY_ID,
+ projectId: EMPTY_ID,
+ creator: EMPTY_PRINCIPAL,
+ updater: EMPTY_PRINCIPAL,
+ createdTs: 0,
+ updatedTs: 0,
+ type: "",
+ name: "",
+ url: "",
+ activityList: [],
+ };
+
const EMPTY_PROJECT_MEMBER: ProjectMember = {
id: EMPTY_ID,
project: EMPTY_PROJECT,
@@ -659,6 +691,8 @@ export const empty = (
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/projectHook.ts b/frontend/src/types/projectHook.ts
index a6ea91b542..0968393a6a 100644
--- a/frontend/src/types/projectHook.ts
+++ b/frontend/src/types/projectHook.ts
@@ -2,6 +2,81 @@ import { ActionType } from "./activity";
import { MemberId, ProjectId } from "./id";
import { Principal } from "./principal";
+type ProjectHookTypeItem = {
+ type: string;
+ name: string;
+ logo: string;
+ urlPrefix: string;
+};
+
+export const PROJECT_HOOK_TYPE_ITEM_LIST: ProjectHookTypeItem[] = [
+ {
+ type: "bb.plugin.webhook.slack",
+ name: "Slack",
+ logo: "slack-logo.png",
+ urlPrefix: "https://hooks.slack.com/",
+ },
+ {
+ type: "bb.plugin.webhook.discord",
+ name: "Discord",
+ logo: "discord-logo.svg",
+ urlPrefix: "https://discord.com/api/webhooks",
+ },
+ {
+ type: "bb.plugin.webhook.teams",
+ name: "Teams",
+ logo: "teams-logo.svg",
+ urlPrefix: "",
+ },
+ {
+ type: "bb.plugin.webhook.dingtalk",
+ name: "DingTalk",
+ logo: "dingtalk-logo.png",
+ urlPrefix: "https://oapi.dingtalk.com",
+ },
+ {
+ type: "bb.plugin.webhook.feishu",
+ name: "Feishu",
+ logo: "feishu-logo.png",
+ urlPrefix: "https://open.feishu.cn",
+ },
+ {
+ type: "bb.plugin.webhook.wecom",
+ name: "WeCom",
+ logo: "wecom-logo.png",
+ urlPrefix: "https://qyapi.weixin.qq.com",
+ },
+];
+
+type ProjectHookEventItem = {
+ title: string;
+ label: string;
+ event: ActionType;
+};
+
+export const PROJECT_HOOK_EVENT_ITEM_LIST: ProjectHookEventItem[] = [
+ {
+ title: "Issue status change",
+ label: "When issue status has changed",
+ event: "bb.issue.status.update",
+ },
+ {
+ title: "Issue task status change",
+ label: "When issue's enclosing task status has changed",
+ event: "bb.pipeline.task.status.update",
+ },
+ {
+ title: "Issue info change",
+ label: "When issue info (e.g. assignee, title, description) has changed",
+ event: "bb.issue.field.update",
+ },
+ {
+ title: "Issue comment creation",
+ label: "When new issue comment has been created",
+ event: "bb.issue.comment.create",
+ },
+];
+
// Project Member
export type ProjectHook = {
id: MemberId;
@@ -16,6 +91,7 @@ export type ProjectHook = {
updatedTs: number;
// Domain specific fields
+ type: string;
name: string;
url: string;
activityList: ActionType[];
@@ -23,6 +99,7 @@ export type ProjectHook = {
export type ProjectHookCreate = {
// Domain specific fields
+ type: string;
name: string;
url: string;
activityList: ActionType[];
@@ -32,5 +109,6 @@ export type ProjectHookPatch = {
// Domain specific fields
name?: string;
url?: string;
- activityList?: ActionType[];
+ // Comma separated list. Server doesn't support deserialize into pointer to string array (*[]string in Golang)
+ activityList?: string;
};
diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vue
index 94adeb71bd..51833904ad 100644
--- a/frontend/src/views/ProjectDetail.vue
+++ b/frontend/src/views/ProjectDetail.vue
@@ -63,20 +63,22 @@ export default {
ProjectSettingPanel,
},
props: {
+ projectSlug: {
+ required: true,
+ type: String,
+ },
selectedTab: {
required: true,
type: Number,
},
- projectSlug: {
+ allowEdit: {
required: true,
- type: String,
+ type: Boolean,
},
},
setup(props, { emit }) {
const store = useStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
-
const project = computed(() => {
return store.getters["project/projectById"](
idFromSlug(props.projectSlug)
@@ -100,25 +102,6 @@ export default {
return sortDatabaseList(list, environmentList.value);
});
- // Only the project owner can edit the project general info and configure version control.
- // This means even the workspace owner won't be able to edit it.
- // On the other hand, we allow workspace owner to change project membership in case
- // project is locked somehow. See the relevant method in ProjectMemberTable for more info.
- const allowEdit = computed(() => {
- if (project.value.rowStatus == "ARCHIVED") {
- return false;
- }
-
- for (const member of project.value.memberList) {
- if (member.principal.id == currentUser.value.id) {
- if (isProjectOwner(member.role)) {
- return true;
- }
- }
- }
- return false;
- });
-
return {
OVERVIEW_TAB,
MIGRATION_HISTORY_TAB,
@@ -127,7 +110,6 @@ export default {
SETTING_TAB,
project,
databaseList,
- allowEdit,
};
},
};
diff --git a/frontend/src/views/ProjectWebhookCreate.vue b/frontend/src/views/ProjectWebhookCreate.vue
index f812811abc..79e5831a4c 100644
--- a/frontend/src/views/ProjectWebhookCreate.vue
+++ b/frontend/src/views/ProjectWebhookCreate.vue
@@ -1,11 +1,28 @@
<template>
- <div>{{ project.name }}</div>
+ <div class="space-y-4 divide-y divide-block-border">
+ <div class="text-xl leading-6 font-medium text-main">Create webhook</div>
+ <ProjectWebhookForm
+ class="pt-4"
+ :create="true"
+ :project="project"
+ :webhook="DEFAULT_NEW_WEBHOOK"
+ />
+ </div>
</template>
<script lang="ts">
import { computed } from "@vue/runtime-core";
import { useStore } from "vuex";
+import ProjectWebhookForm from "../components/ProjectWebhookForm.vue";
import { idFromSlug } from "../utils";
+import { ProjectHookCreate } from "../types";
+
+const DEFAULT_NEW_WEBHOOK: ProjectHookCreate = {
+ type: "bb.plugin.webhook.slack",
+ name: "",
+ url: "",
+ activityList: ["bb.issue.status.update"],
+};
export default {
name: "ProjectWebhookCreate",
@@ -15,7 +32,7 @@ export default {
type: String,
},
},
- components: {},
+ components: { ProjectWebhookForm },
setup(props, ctx) {
const store = useStore();
@@ -25,7 +42,10 @@ export default {
);
});
- return { project };
+ return {
+ DEFAULT_NEW_WEBHOOK,
+ project,
+ };
},
};
</script>
diff --git a/frontend/src/views/ProjectWebhookDetail.vue b/frontend/src/views/ProjectWebhookDetail.vue
index a1c1baf64a..74a47e350b 100644
--- a/frontend/src/views/ProjectWebhookDetail.vue
+++ b/frontend/src/views/ProjectWebhookDetail.vue
@@ -1,11 +1,27 @@
<template>
- <div>{{ project.name }} - {{ projectHook.name }}</div>
+ <div class="space-y-4 divide-y divide-block-border">
+ <div class="flex flex-row space-x-2 items-center">
+ <img class="h-6 w-6" :src="`/src/assets/${logo}`" />
+ <h3 class="text-xl leading-6 font-medium text-main">
+ {{ projectHook.name }}
+ </h3>
+ </div>
+ <ProjectWebhookForm
+ class="pt-4"
+ :allowEdit="allowEdit"
+ :create="false"
+ :project="project"
+ :webhook="projectHook"
+ />
+ </div>
</template>
<script lang="ts">
import { computed } from "@vue/runtime-core";
+import ProjectWebhookForm from "../components/ProjectWebhookForm.vue";
import { idFromSlug } from "../utils";
import { useStore } from "vuex";
+import { PROJECT_HOOK_TYPE_ITEM_LIST } from "../types";
export default {
name: "ProjectWebhookDetail",
@@ -18,8 +34,12 @@ export default {
required: true,
type: String,
},
+ allowEdit: {
+ required: true,
+ type: Boolean,
+ },
},
- components: {},
+ components: { ProjectWebhookForm },
setup(props, ctx) {
const store = useStore();
@@ -36,9 +56,20 @@ export default {
);
});
+ const logo = computed(() => {
+ for (const item of PROJECT_HOOK_TYPE_ITEM_LIST) {
+ if (item.type == projectHook.value.type) {
+ return item.logo;
+ }
+ }
+
+ return "";
+ });
+
return {
project,
projectHook,
+ logo,
};
},
};