Skip to content

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

Add basic step transition matrix and update the step

天舟39a27a027376
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index 30ec3c92c6..ae0156c808 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -115,6 +115,7 @@ export default {
task: belongsTo(),
}),
stepPatch: Model,
+ stepStatusPatch: Model,
// Environment
environment: Model.extend({
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 0bc1e3d5ca..1b1826d0ef 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -8,6 +8,7 @@ import configureActivity from "./activity";
import configureMessage from "./message";
import configureBookmark from "./bookmark";
import configureIssue from "./issue";
+import configureStep from "./step";
import configureProject from "./project";
import configureProjectMember from "./projectMember";
import configureEnvironment from "./environment";
@@ -54,6 +55,9 @@ export default function routes() {
// Issue
configureIssue(this);
+ // Step
+ configureStep(this);
+
// Environment
configureEnvironment(this);
diff --git a/frontend/src/miragejs/routes/step.js b/frontend/src/miragejs/routes/step.js
new file mode 100644
index 0000000000..c7ccc01062
--- /dev/null
+++ b/frontend/src/miragejs/routes/step.js
@@ -0,0 +1,64 @@
+import { Response } from "miragejs";
+import { WORKSPACE_ID } from "./index";
+import { IssueBuiltinFieldId } from "../../plugins";
+
+export default function configureStep(route) {
+ route.patch(
+ "/pipeline/:pipelineId/step/:stepId/status",
+ function (schema, request) {
+ const attrs = this.normalizedRequestAttrs("step-status-patch");
+ const pipeline = schema.pipelines.find(request.params.pipelineId);
+
+ if (!pipeline) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Pipeline " + request.params.pipelineId + " not found" }
+ );
+ }
+
+ const step = schema.steps.find(request.params.stepId);
+ if (!step) {
+ return new Response(
+ 404,
+ {},
+ { errors: "Step " + request.params.stepId + " not found" }
+ );
+ }
+
+ const ts = Date.now();
+
+ const changeList = [];
+
+ if (attrs.status && step.status != attrs.status) {
+ changeList.push({
+ fieldId: IssueBuiltinFieldId.STEP_STATUS,
+ oldValue: step.status,
+ newValue: attrs.status,
+ });
+
+ const updatedStep = step.update({ ...attrs, updatedTs: ts });
+
+ const payload = {
+ changeList,
+ };
+
+ schema.activities.create({
+ creatorId: attrs.updaterId,
+ createdTs: ts,
+ updaterId: attrs.updaterId,
+ updatedTs: ts,
+ actionType: "bytebase.issue.task.step.status.update",
+ containerId: updatedStep.id,
+ comment: attrs.comment,
+ payload,
+ workspaceId: WORKSPACE_ID,
+ });
+
+ return updatedStep;
+ }
+
+ return step;
+ }
+ );
+}
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index fd0d5cc0b7..e66cd0e2d8 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -480,7 +480,7 @@ const workspacesSeeder = (server: any) => {
{
issueStatus: "DONE",
taskStatusList: ["DONE", "SKIPPED", "DONE", "DONE"],
- stepStatusList: ["DONE", "CANCELED", "DONE", "DONE"],
+ stepStatusList: ["DONE", "SKIPPED", "DONE", "DONE"],
},
{
issueStatus: "OPEN",
@@ -490,7 +490,7 @@ const workspacesSeeder = (server: any) => {
{
issueStatus: "CANCELED",
taskStatusList: ["DONE", "SKIPPED", "DONE", "PENDING"],
- stepStatusList: ["DONE", "CANCELED", "DONE", "PENDING"],
+ stepStatusList: ["DONE", "SKIPPED", "DONE", "PENDING"],
},
];
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index c82b8d879b..dcedda4a44 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -28,6 +28,7 @@ export enum IssueBuiltinFieldId {
ROLLBACK_SQL = "12",
SUBSCRIBER_LIST = "13",
TASK_STATUS = "14",
+ STEP_STATUS = "15",
}
export const INPUT_CUSTOM_FIELD_ID_BEGIN = "100";
diff --git a/frontend/src/store/modules/step.ts b/frontend/src/store/modules/step.ts
index fd81be8090..78da64c52e 100644
--- a/frontend/src/store/modules/step.ts
+++ b/frontend/src/store/modules/step.ts
@@ -1,15 +1,16 @@
+import axios from "axios";
import {
- ResourceIdentifier,
ResourceObject,
StepState,
Step,
- Issue,
Task,
unknown,
IssueId,
TaskId,
PipelineId,
Pipeline,
+ StepStatusPatch,
+ StepId,
} from "../../types";
const state: () => StepState = () => ({});
@@ -60,7 +61,34 @@ const getters = {
},
};
-const actions = {};
+const actions = {
+ async updateStatus(
+ { dispatch }: any,
+ {
+ issueId,
+ pipelineId,
+ stepId,
+ stepStatusPatch,
+ }: {
+ issueId: IssueId;
+ pipelineId: PipelineId;
+ stepId: StepId;
+ stepStatusPatch: StepStatusPatch;
+ }
+ ) {
+ // TODO: Returns the updated pipeline and update the issue.
+ const data = (
+ await axios.patch(`/api/pipeline/${pipelineId}/step/${stepId}/status`, {
+ data: {
+ type: "stepstatuspatch",
+ attributes: stepStatusPatch,
+ },
+ })
+ ).data;
+
+ dispatch("issue/fetchIssueById", issueId, { root: true });
+ },
+};
const mutations = {};
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 8942c81806..a87b13afd1 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -1002,7 +1002,7 @@ export const ASSIGNEE_APPLICABLE_ACTION_LIST: Map<
//
// Comparison with GitLab:
// PIPELINE = GitLab Pipeline
-// TASK = GitLab Task
+// TASK = GitLab Stage
// STEP = GitLab Job
//
// Comparison with Octopus:
@@ -1195,13 +1195,7 @@ export type StepType =
| "bytebase.step.approve"
| "bytebase.step.database.schema.update";
-export type StepStatus =
- | "PENDING"
- | "RUNNING"
- | "DONE"
- | "FAILED"
- | "CANCELED"
- | "SKIPPED";
+export type StepStatus = "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
export type DatabaseSchemaUpdateStepPayload = {
sql: string;
@@ -1244,13 +1238,20 @@ export type StepPatch = {
status: StepStatus;
};
+export type StepStatusPatch = {
+ updaterId: PrincipalId;
+ status: StepStatus;
+ comment?: string;
+};
+
// Activity
export type IssueActionType =
| "bytebase.issue.create"
| "bytebase.issue.comment.create"
| "bytebase.issue.field.update"
| "bytebase.issue.status.update"
- | "bytebase.issue.task.status.update";
+ | "bytebase.issue.task.status.update"
+ | "bytebase.issue.task.step.status.update";
export type ActionType = IssueActionType;
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index 79957dfff1..43b18c039e 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -4,17 +4,20 @@ import {
EMPTY_ID,
Environment,
Pipeline,
+ Step,
+ StepStatus,
Task,
+ UNKNOWN_ID,
} from "../types";
export function activeTask(pipeline: Pipeline): Task {
for (const task of pipeline.taskList) {
if (
- task.status === "PENDING" ||
- task.status === "RUNNING" ||
+ task.status == "PENDING" ||
+ task.status == "RUNNING" ||
// "FAILED" is also a transient task status, which requires user
// to take further action (e.g. Cancel, Skip, Retry)
- task.status === "FAILED"
+ task.status == "FAILED"
) {
return task;
}
@@ -26,6 +29,22 @@ export function activeTaskIsRunning(pipeline: Pipeline): boolean {
return activeTask(pipeline).status === "RUNNING";
}
+export function activeStep(pipeline: Pipeline): Step {
+ const task = activeTask(pipeline);
+ for (const step of task.stepList) {
+ if (
+ step.status == "PENDING" ||
+ step.status == "RUNNING" ||
+ // "FAILED" is also a transient step status, which requires user
+ // to take further action (e.g. Skip, Retry)
+ step.status == "FAILED"
+ ) {
+ return step;
+ }
+ }
+ return empty("STEP") as Step;
+}
+
export function activeEnvironment(pipeline: Pipeline): Environment {
const task: Task = activeTask(pipeline);
if (task.id == EMPTY_ID) {
@@ -41,3 +60,85 @@ export function activeDatabase(pipeline: Pipeline): Database {
}
return task.database;
}
+
+export type StepStatusTransitionType = "RUN" | "RETRY" | "CANCEL" | "SKIP";
+
+export interface StepStatusTransition {
+ type: StepStatusTransitionType;
+ to: StepStatus;
+ buttonName: string;
+ buttonClass: string;
+}
+
+const STEP_STATUS_TRANSITION_LIST: Map<
+ StepStatusTransitionType,
+ StepStatusTransition
+> = new Map([
+ [
+ "RUN",
+ {
+ type: "RUN",
+ to: "RUNNING",
+ buttonName: "Run",
+ buttonClass: "btn-primary",
+ },
+ ],
+ [
+ "RETRY",
+ {
+ type: "RETRY",
+ to: "RUNNING",
+ buttonName: "Retry",
+ buttonClass: "btn-primary",
+ },
+ ],
+ [
+ "CANCEL",
+ {
+ type: "CANCEL",
+ to: "PENDING",
+ buttonName: "Cancel",
+ buttonClass: "btn-primary",
+ },
+ ],
+ [
+ "SKIP",
+ {
+ type: "SKIP",
+ actionName: "Skip",
+ to: "SKIPPED",
+ buttonName: "Skip",
+ buttonClass: "btn-normal",
+ },
+ ],
+]);
+
+// The transition button is ordered from right to left on the UI
+const APPLICABLE_STEP_TRANSITION_LIST: Map<
+ StepStatus,
+ StepStatusTransitionType[]
+> = new Map([
+ ["PENDING", ["RUN", "SKIP"]],
+ ["RUNNING", ["CANCEL"]],
+ ["DONE", []],
+ ["FAILED", ["RETRY", "SKIP"]],
+ ["SKIPPED", []],
+]);
+
+export function applicableStepTransition(
+ pipeline: Pipeline
+): StepStatusTransition[] {
+ const step = activeStep(pipeline);
+
+ if (step.id == EMPTY_ID || step.id == UNKNOWN_ID) {
+ return [];
+ }
+
+ const list: StepStatusTransitionType[] = APPLICABLE_STEP_TRANSITION_LIST.get(
+ step.status
+ )!;
+
+ return list.map((type: StepStatusTransitionType) => {
+ return STEP_STATUS_TRANSITION_LIST.get(type)!;
+ });
+}
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index f375fa7650..a8616c51b0 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -343,15 +343,6 @@ export default {
payload.newStatus
);
}
- case "bb.msg.issue.task.status.update": {
- const payload = message.payload as IssueUpdateStatusMessagePayload;
- return (
- "changed issue task status from " +
- payload.oldStatus +
- " to " +
- payload.newStatus
- );
- }
case "bb.msg.issue.comment":
return "commented issue";
}
diff --git a/frontend/src/views/IssueActivityPanel.vue b/frontend/src/views/IssueActivityPanel.vue
index 68dd888c95..5825106b38 100644
--- a/frontend/src/views/IssueActivityPanel.vue
+++ b/frontend/src/views/IssueActivityPanel.vue
@@ -490,7 +490,8 @@ export default {
return "commented";
case "bytebase.issue.field.update":
case "bytebase.issue.status.update":
- case "bytebase.issue.task.status.update": {
+ case "bytebase.issue.task.status.update":
+ case "bytebase.issue.task.step.status.update": {
const updateInfoList: string[] = [];
for (const update of (activity.payload as ActionIssueFieldUpdatePayload)
?.changeList || []) {
@@ -509,6 +510,10 @@ export default {
name = "task status";
oldValue = update.oldValue;
newValue = update.newValue;
+ } else if (update.fieldId == IssueBuiltinFieldId.STEP_STATUS) {
+ name = "step status";
+ oldValue = update.oldValue;
+ newValue = update.newValue;
} else if (update.fieldId == IssueBuiltinFieldId.ASSIGNEE) {
name = "assignee";
if (update.oldValue) {
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index fdb10640c1..35c940fe51 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -24,30 +24,21 @@
</template>
<!-- Action Button List -->
<div
- v-else-if="applicableStatusTransitionList.length > 0"
- class="flex flex-row-reverse"
+ v-else-if="applicableStepStatusTransitionList.length > 0"
+ class="flex space-x-2"
>
<template
- v-for="(transition, index) in applicableStatusTransitionList"
+ v-for="(
+ transition, index
+ ) in applicableStepStatusTransitionList.reverse()"
:key="index"
>
<button
type="button"
- :class="
- index == 0
- ? transition.type == 'RESOLVE'
- ? 'btn-success'
- : transition.type == 'NEXT'
- ? 'btn-primary'
- : 'btn-normal'
- : 'btn-normal mr-2'
- "
- :disabled="!allowTransition(transition)"
- @click.prevent="
- tryStartIssueStatusTransition(transition.type, () => {})
- "
+ :class="transition.buttonClass"
+ @click.prevent="tryStartStepStatusTransition(transition)"
>
- {{ transition.actionName }}
+ {{ transition.buttonName }}
</button>
</template>
</div>
@@ -169,21 +160,21 @@
</template>
<script lang="ts">
-import {
- computed,
- onMounted,
- watch,
- watchEffect,
- reactive,
- ref,
- ComputedRef,
-} from "vue";
+import { computed, onMounted, watch, watchEffect, reactive, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import cloneDeep from "lodash-es/cloneDeep";
import isEmpty from "lodash-es/isEmpty";
import isEqual from "lodash-es/isEqual";
-import { idFromSlug, issueSlug, isDemo, pendingResolve } from "../utils";
+import {
+ idFromSlug,
+ issueSlug,
+ isDemo,
+ pendingResolve,
+ StepStatusTransition,
+ applicableStepTransition,
+ activeStep,
+} from "../utils";
import IssueHighlightPanel from "../views/IssueHighlightPanel.vue";
import IssueTaskFlow from "./IssueTaskFlow.vue";
import IssueOutputPanel from "../views/IssueOutputPanel.vue";
@@ -211,6 +202,8 @@ import {
UNKNOWN_ID,
ProjectId,
Environment,
+ StepStatusPatch,
+ StepId,
} from "../types";
import {
defaulTemplate,
@@ -520,6 +513,49 @@ export default {
}
return true;
};
+
+ const tryStartStepStatusTransition = (transition: StepStatusTransition) => {
+ const step = activeStep((state.issue as Issue).pipeline);
+ doStepStatusTransition(transition, step.id);
+ };
+
+ const doStepStatusTransition = (
+ transition: StepStatusTransition,
+ stepId: StepId,
+ comment?: string
+ ) => {
+ const stepStatusPatch: StepStatusPatch = {
+ updaterId: currentUser.value.id,
+ status: transition.to,
+ comment: comment ? comment.trim() : undefined,
+ };
+
+ store.dispatch("step/updateStatus", {
+ issueId: (state.issue as Issue).id,
+ pipelineId: (state.issue as Issue).pipeline.id,
+ stepId,
+ stepStatusPatch,
+ });
+ };
+
+ const changeStepStatus = (
+ taskId: TaskId,
+ taskStatus: TaskStatus,
+ comment?: string
+ ) => {
+ const taskStatusPatch: TaskStatusPatch = {
+ updaterId: currentUser.value.id,
+ status: taskStatus,
+ comment: comment ? comment.trim() : undefined,
+ };
+
+ store.dispatch("task/updateTaskStatus", {
+ issueId: (state.issue as Issue).id,
+ taskId,
+ taskStatusPatch,
+ });
+ };
+
const tryStartIssueStatusTransition = (
type: IssueStatusTransitionType,
didTransit: () => {}
@@ -753,6 +789,18 @@ export default {
return state.issue.type == "bytebase.database.schema.update";
});
+ const applicableStepStatusTransitionList = computed(
+ (): StepStatusTransition[] => {
+ let list: StepStatusTransition[] = [];
+
+ if (currentUser.value.id === (state.issue as Issue).assignee?.id) {
+ list = applicableStepTransition((state.issue as Issue).pipeline);
+ }
+
+ return list;
+ }
+ );
+
const applicableStatusTransitionList = computed(
(): IssueStatusTransition[] => {
const list: IssueStatusTransitionType[] = [];
@@ -801,13 +849,16 @@ export default {
updateSql,
updateRollbackSql,
allowTransition,
+ tryStartStepStatusTransition,
+ doStepStatusTransition,
+ changeStepStatus,
tryStartIssueStatusTransition,
doIssueStatusTransition,
+ changeTaskStatus,
updateAssigneeId,
updateSubscriberIdList,
updateCustomField,
doCreate,
- changeTaskStatus,
workflowType,
allowCreate,
currentUser,
@@ -822,6 +873,7 @@ export default {
showIssueOutputPanel,
showIssueSqlPanel,
showIssueRollbackSqlPanel,
+ applicableStepStatusTransitionList,
applicableStatusTransitionList,
};
},