Skip to content

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

Make issue always contain pipeline

天舟0ae0e55f2852
diff --git a/frontend/src/miragejs/routes/issue.js b/frontend/src/miragejs/routes/issue.js
index 97f5712a77..49fdb6e032 100644
--- a/frontend/src/miragejs/routes/issue.js
+++ b/frontend/src/miragejs/routes/issue.js
@@ -43,46 +43,43 @@ export default function configureIssue(route) {
const { pipeline, ...attrs } = this.normalizedRequestAttrs("issue-new");
let createdPipeline;
- // Create pipeline if exists
- if (pipeline) {
- const newPipeline = {
+ const newPipeline = {
+ createdTs: ts,
+ updaterId: attrs.creatorId,
+ updatedTs: ts,
+ name: pipeline.name,
+ status: "OPEN",
+ workspaceId: WORKSPACE_ID,
+ };
+
+ createdPipeline = schema.pipelines.create(newPipeline);
+
+ for (const stage of pipeline.stageList) {
+ const { taskList, databaseId, environmentId, ...stageAttrs } = stage;
+
+ const createdStage = schema.stages.create({
+ ...stageAttrs,
createdTs: ts,
updaterId: attrs.creatorId,
updatedTs: ts,
- name: pipeline.name,
- status: "OPEN",
+ environmentId,
+ databaseId: databaseId != EMPTY_ID ? databaseId : null,
+ status: "PENDING",
+ pipeline: createdPipeline,
workspaceId: WORKSPACE_ID,
- };
-
- createdPipeline = schema.pipelines.create(newPipeline);
-
- for (const stage of pipeline.stageList) {
- const { taskList, databaseId, environmentId, ...stageAttrs } = stage;
+ });
- const createdStage = schema.stages.create({
- ...stageAttrs,
+ for (const task of taskList) {
+ schema.tasks.create({
+ ...task,
createdTs: ts,
updaterId: attrs.creatorId,
updatedTs: ts,
- environmentId,
- databaseId: databaseId != EMPTY_ID ? databaseId : null,
status: "PENDING",
pipeline: createdPipeline,
+ stage: createdStage,
workspaceId: WORKSPACE_ID,
});
-
- for (const task of taskList) {
- schema.tasks.create({
- ...task,
- createdTs: ts,
- updaterId: attrs.creatorId,
- updatedTs: ts,
- status: "PENDING",
- pipeline: createdPipeline,
- stage: createdStage,
- workspaceId: WORKSPACE_ID,
- });
- }
}
}
@@ -280,78 +277,76 @@ export default function configureIssue(route) {
const ts = Date.now();
- if (issue.pipelineId) {
- const pipeline = schema.pipelines.find(issue.pipelineId);
- // Pipeline and issue status is 1-to-1 mapping, so we just change the pipeline status accordingly.
- pipeline.update({
- status: attrs.status,
- });
+ const pipeline = schema.pipelines.find(issue.pipelineId);
+ // Pipeline and issue status is 1-to-1 mapping, so we just change the pipeline status accordingly.
+ pipeline.update({
+ status: attrs.status,
+ });
+
+ const stageList = schema.stages.where({ pipelineId: pipeline.id }).models;
+ if (attrs.status == "DONE") {
+ // Returns error if any of the tasks is not in the end status.
+ for (let i = 0; i < stageList.length; i++) {
+ const taskList = schema.tasks.where({
+ issueId: issue.id,
+ stageId: stageList[i].id,
+ }).models;
+
+ for (let j = 0; j < taskList.length; j++) {
+ if (
+ taskList[j].status != "DONE" &&
+ taskList[j].status != "CANCELED" &&
+ taskList[j].status != "SKIPPED"
+ ) {
+ return new Response(
+ 404,
+ {},
+ {
+ errors: `Can't resolve issue ${issue.name}. Task ${taskList[j].name} in stage ${stageList[i].name} is in ${taskList[j].status} status`,
+ }
+ );
+ }
+ }
+ }
+
+ pipeline.update({ status: "DONE" });
+ }
+
+ // If issue is canceled, we find the current running stages and tasks, mark each of them CANCELED.
+ // We keep PENDING stages and tasks as is since the issue maybe reopened later, and it's better to
+ // keep them in the state before it was canceled.
+ if (attrs.status == "CANCELED") {
+ pipeline.update({ status: "CAMCELED" });
+
+ for (let i = 0; i < stageList.length; i++) {
+ if (stageList[i].status == "RUNNING") {
+ schema.stages.find(stageList[i].id).update({
+ status: "CANCELED",
+ });
- const stageList = schema.stages.where({ pipelineId: pipeline.id }).models;
- if (attrs.status == "DONE") {
- // Returns error if any of the tasks is not in the end status.
- for (let i = 0; i < stageList.length; i++) {
const taskList = schema.tasks.where({
issueId: issue.id,
stageId: stageList[i].id,
}).models;
for (let j = 0; j < taskList.length; j++) {
- if (
- taskList[j].status != "DONE" &&
- taskList[j].status != "CANCELED" &&
- taskList[j].status != "SKIPPED"
- ) {
- return new Response(
- 404,
- {},
- {
- errors: `Can't resolve issue ${issue.name}. Task ${taskList[j].name} in stage ${stageList[i].name} is in ${taskList[j].status} status`,
- }
- );
- }
- }
- }
-
- pipeline.update({ status: "DONE" });
- }
-
- // If issue is canceled, we find the current running stages and tasks, mark each of them CANCELED.
- // We keep PENDING stages and tasks as is since the issue maybe reopened later, and it's better to
- // keep them in the state before it was canceled.
- if (attrs.status == "CANCELED") {
- pipeline.update({ status: "CAMCELED" });
-
- for (let i = 0; i < stageList.length; i++) {
- if (stageList[i].status == "RUNNING") {
- schema.stages.find(stageList[i].id).update({
- status: "CANCELED",
- });
-
- const taskList = schema.tasks.where({
- issueId: issue.id,
- stageId: stageList[i].id,
- }).models;
-
- for (let j = 0; j < taskList.length; j++) {
- if (taskList[j].status == "RUNNING") {
- schema.tasks.find(taskList[j].id).update({
- status: "CANCELED",
- });
- }
+ if (taskList[j].status == "RUNNING") {
+ schema.tasks.find(taskList[j].id).update({
+ status: "CANCELED",
+ });
}
}
}
}
+ }
- // If issue is opened, we just move the pipeline to the PENDING status.
- // We keep stages and tasks status as is since even those status are canceled,
- // we don't known whether it's canceled because of the issue is previously
- // canceled, or it's canceled for a different reason. And it's always safer
- // for user to explicitly resume the execution.
- if (attrs.status == "OPEN") {
- pipeline.update({ status: "PENDING" });
- }
+ // If issue is opened, we just move the pipeline to the PENDING status.
+ // We keep stages and tasks status as is since even those status are canceled,
+ // we don't known whether it's canceled because of the issue is previously
+ // canceled, or it's canceled for a different reason. And it's always safer
+ // for user to explicitly resume the execution.
+ if (attrs.status == "OPEN") {
+ pipeline.update({ status: "PENDING" });
}
const changeList = [];
diff --git a/frontend/src/plugins/issue/DefaultTemplate.ts b/frontend/src/plugins/issue/DefaultTemplate.ts
index f9f830fa86..ee374465f9 100644
--- a/frontend/src/plugins/issue/DefaultTemplate.ts
+++ b/frontend/src/plugins/issue/DefaultTemplate.ts
@@ -10,6 +10,25 @@ const template: IssueTemplate = {
name: "",
type: "bb.general",
description: "",
+ pipeline: {
+ stageList: [
+ {
+ name: "Troubleshoot database",
+ environmentId: ctx.environmentList[0].id,
+ type: "bb.stage.general",
+ taskList: [
+ {
+ name: "Troubleshoot database",
+ type: "bb.task.general",
+ when: "MANUAL",
+ databaseId: UNKNOWN_ID,
+ },
+ ],
+ },
+ ],
+ creatorId: ctx.currentUser.id,
+ name: "Create database pipeline",
+ },
payload: {},
};
},
diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.ts
index 9411111f37..5306ca349f 100644
--- a/frontend/src/store/modules/issue.ts
+++ b/frontend/src/store/modules/issue.ts
@@ -48,15 +48,10 @@ function convert(
let project: Project = unknown("PROJECT") as Project;
project.id = projectId;
- let pipeline: Pipeline;
- if (issue.relationships!.pipeline.data) {
- const pipelineId = (issue.relationships!.pipeline
- .data as ResourceIdentifier).id;
- pipeline = unknown("PIPELINE") as Pipeline;
- pipeline.id = pipelineId;
- } else {
- pipeline = empty("PIPELINE") as Pipeline;
- }
+ const pipelineId = (issue.relationships!.pipeline.data as ResourceIdentifier)
+ .id;
+ let pipeline = unknown("PIPELINE") as Pipeline;
+ pipeline.id = pipelineId;
for (const item of includedList || []) {
if (
diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.ts
index 7e5cfd4fe2..9742297549 100644
--- a/frontend/src/types/issue.ts
+++ b/frontend/src/types/issue.ts
@@ -49,7 +49,7 @@ export type Issue = {
export type IssueNew = {
// Related fields
projectId: ProjectId;
- pipeline?: PipelineNew;
+ pipeline: PipelineNew;
// Standard fields
creatorId: PrincipalId;
diff --git a/frontend/src/types/pipeline.ts b/frontend/src/types/pipeline.ts
index db5da0a374..22606c2705 100644
--- a/frontend/src/types/pipeline.ts
+++ b/frontend/src/types/pipeline.ts
@@ -143,6 +143,7 @@ export type PipelineStatusPatch = {
// Stage
export type StageType =
| "bb.stage.unknown"
+ | "bb.stage.general"
| "bb.stage.final"
| "bb.stage.transition"
| "bb.stage.database.create"
@@ -189,6 +190,7 @@ export type StageNew = {
// Task
export type TaskType =
| "bb.task.unknown"
+ | "bb.task.general"
| "bb.task.approve"
| "bb.task.database.schema.update";
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 860d3b8279..74c202cb50 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -274,6 +274,8 @@ export default {
for (const database of databaseList) {
environmentList.push(database.instance.environment);
}
+ } else {
+ environmentList.push(...store.getters["environment/environmentList"]());
}
const newIssue = {