Skip to content

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

feat: automatically find a proper assignee for the first task when creating issues (#3299)

Liu Jib9bb5d01559d
diff --git a/frontend/src/plugins/issue/logic/initialize/assignee.ts b/frontend/src/plugins/issue/logic/initialize/assignee.ts
new file mode 100644
index 0000000000..09a9fcd35f
--- /dev/null
+++ b/frontend/src/plugins/issue/logic/initialize/assignee.ts
@@ -0,0 +1,73 @@
+import type { IssueCreate, PipelineApprovalPolicyPayload } from "@/types";
+import {
+ useInstanceStore,
+ useMemberStore,
+ usePolicyStore,
+ useProjectStore,
+} from "@/store";
+import { hasWorkspacePermission } from "@/utils";
+
+export const tryGetDefaultAssignee = async (issueCreate: IssueCreate) => {
+ const firstTask = issueCreate.pipeline?.stageList[0]?.taskList[0];
+ // The pipeline is accidentally empty, so we won't go further
+ if (!firstTask) return;
+
+ const instance = await useInstanceStore().getOrFetchInstanceById(
+ firstTask.instanceId
+ );
+
+ const policy = await usePolicyStore().fetchPolicyByEnvironmentAndType({
+ environmentId: instance.environment.id,
+ type: "bb.policy.pipeline-approval",
+ });
+
+ const payload = policy.payload as PipelineApprovalPolicyPayload;
+
+ if (payload.value === "MANUAL_APPROVAL_NEVER") {
+ // We don't need to approve manually.
+ // But we still set the project owner as the default assignee.
+ // Just to notify the project owner.
+ assignToProjectOwner(issueCreate);
+ return;
+ }
+ if (payload.value === "MANUAL_APPROVAL_ALWAYS") {
+ const assigneeGroup = payload.assigneeGroupList.find(
+ (group) => group.issueType === issueCreate.type
+ );
+
+ if (assigneeGroup && assigneeGroup.value === "PROJECT_OWNER") {
+ // Assign to the project owner if needed.
+ assignToProjectOwner(issueCreate);
+ return;
+ }
+
+ // If we don't find an assignee group for this issue type
+ // or its value is WORKSPACE_OWNER_OR_DBA.
+ assignToWorkspaceOwnerOrDBA(issueCreate);
+ return;
+ }
+};
+
+const assignToProjectOwner = (issueCreate: IssueCreate) => {
+ const project = useProjectStore().getProjectById(issueCreate.projectId);
+ // Find the owner of the project, the first owner we found is okay.
+ const projectOwner = project.memberList.find(
+ (member) => member.role === "OWNER"
+ );
+ if (projectOwner) {
+ issueCreate.assigneeId = projectOwner.principal.id;
+ }
+};
+const assignToWorkspaceOwnerOrDBA = (issueCreate: IssueCreate) => {
+ const memberList = useMemberStore().memberList;
+ // Find the workspace owner or DBA, the first one we found is okay.
+ const ownerOrDBA = memberList.find((member) => {
+ return hasWorkspacePermission(
+ "bb.permission.workspace.manage-issue",
+ member.role
+ );
+ });
+ if (ownerOrDBA) {
+ issueCreate.assigneeId = ownerOrDBA.principal.id;
+ }
+};
diff --git a/frontend/src/plugins/issue/logic/initialize/index.ts b/frontend/src/plugins/issue/logic/initialize/index.ts
index c98ecb8e5f..2b6b056eae 100644
--- a/frontend/src/plugins/issue/logic/initialize/index.ts
+++ b/frontend/src/plugins/issue/logic/initialize/index.ts
@@ -1,6 +1,7 @@
import { computed, ref, Ref, watch } from "vue";
import { useRoute } from "vue-router";
-import { IssueCreate, IssueType } from "@/types";
+import type { IssueCreate, IssueType } from "@/types";
+import { SYSTEM_BOT_ID, UNKNOWN_ID } from "@/types";
import { pushNotification, useIssueStore } from "@/store";
import { idFromSlug } from "@/utils";
import { defaultTemplate, templateForType } from "@/plugins";
@@ -8,6 +9,7 @@ import { BuildNewIssueContext } from "../common";
import { maybeBuildTenantDeployIssue } from "./tenant";
import { maybeBuildGhostIssue } from "./ghost";
import { buildNewStandardIssue } from "./standard";
+import { tryGetDefaultAssignee } from "./assignee";
export function useInitializeIssue(issueSlug: Ref<string>) {
const issueStore = useIssueStore();
@@ -48,6 +50,13 @@ export function useInitializeIssue(issueSlug: Ref<string>) {
issueCreate.value = undefined;
if (create.value) {
issueCreate.value = await buildNewIssue({ template, route });
+ if (
+ issueCreate.value.assigneeId === UNKNOWN_ID ||
+ issueCreate.value.assigneeId === SYSTEM_BOT_ID
+ ) {
+ // Try to find a default assignee of the first task automatically.
+ await tryGetDefaultAssignee(issueCreate.value);
+ }
}
},
{ immediate: true }