Skip to content

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

chore: don't create draft branch (#9700)

Danny Xuf29726d8499d
diff --git a/.github/workflows/test_link.yml b/.github/workflows/test_link.yml
index 7327a44675..cdd31bef97 100644
--- a/.github/workflows/test_link.yml
+++ b/.github/workflows/test_link.yml
@@ -10,13 +10,12 @@ on:
jobs:
go-tests:
- runs-on: ubuntu-latest
+ runs-on: self-hosted
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: 1.21.3
- cache: false
- - name: Test link in product is valid
+ - name: Validate links
run: go test -timeout 600s -v ./scripts/... | tee test.log; exit ${PIPESTATUS[0]}
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vue
index aa782d04f4..1604e3fb3e 100644
--- a/frontend/src/components/Branch/BranchDetailView.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -110,8 +110,7 @@
import { asyncComputed } from "@vueuse/core";
import dayjs from "dayjs";
import { cloneDeep, head, isEqual, uniqueId } from "lodash-es";
-import { NButton, NDivider, NInput, useDialog, NTag } from "naive-ui";
-import { Status } from "nice-grpc-common";
+import { NButton, NDivider, NInput, NTag } from "naive-ui";
import { CSSProperties, computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -138,7 +137,7 @@ import { projectV1Slug } from "@/utils";
import { provideSQLCheckContext } from "../SQLCheck";
import MergeBranchPanel from "./MergeBranchPanel.vue";
import SchemaDesignEditor from "./SchemaDesignEditor.vue";
-import { generateForkedBranchName, validateBranchName } from "./utils";
+import { validateBranchName } from "./utils";
interface LocalState {
branchId: string;
@@ -162,7 +161,6 @@ const { branchList, ready } = useBranchList(
getProjectAndBranchId(props.branch.name)[0]
);
const { runSQLCheck } = provideSQLCheckContext();
-const dialog = useDialog();
const state = reactive<LocalState>({
branchId: "",
isEditing: false,
@@ -381,78 +379,13 @@ const handleSaveBranch = async () => {
state.isSaving = true;
if (updateMask.length !== 0) {
- if (branch.value.parentBranch === "") {
- const branchName = generateForkedBranchName(branch.value);
- const newBranch = await branchStore.createBranchDraft(
- project.value.name,
- branchName,
- branch.value.name
- );
- try {
- await branchStore.mergeBranch({
- name: branch.value.name,
- headBranch: newBranch.name,
- });
- } catch (error: any) {
- // If there is conflict, we need to show the conflict and let user resolve it.
- if (error.code === Status.FAILED_PRECONDITION) {
- dialog.create({
- negativeText: t("schema-designer.save-draft"),
- positiveText: t("schema-designer.diff-editor.resolve"),
- title: t("schema-designer.diff-editor.auto-merge-failed"),
- content: t("schema-designer.diff-editor.need-to-resolve-conflicts"),
- autoFocus: true,
- closable: true,
- maskClosable: true,
- closeOnEsc: true,
- onNegativeClick: () => {
- // Go to draft branch detail page after merge failed.
- const [_, branchId] = getProjectAndBranchId(newBranch.name);
- state.isEditing = false;
- router.replace({
- name: "workspace.project.branch.detail",
- params: {
- projectSlug: projectV1Slug(project.value),
- branchName: branchId,
- },
- });
- },
- onPositiveClick: () => {
- state.showDiffEditor = true;
- mergeBranchPanelContext.value = {
- sourceBranchName: newBranch.name,
- targetBranchName: branch.value.name,
- };
- },
- });
- } else {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: `Request error occurred`,
- description: error.details,
- });
- }
- state.isSaving = false;
- return;
- }
-
- // Delete the draft after merged.
- await branchStore.deleteBranch(newBranch.name);
- // Fetch the latest schema design after merged.
- await branchStore.fetchBranchByName(
- branch.value.name,
- false /* !useCache */
- );
- } else {
- await branchStore.updateBranch(
- Branch.fromPartial({
- name: branch.value.name,
- schemaMetadata: mergedMetadata,
- }),
- updateMask
- );
- }
+ await branchStore.updateBranch(
+ Branch.fromPartial({
+ name: branch.value.name,
+ schemaMetadata: mergedMetadata,
+ }),
+ updateMask
+ );
pushNotification({
module: "bytebase",
diff --git a/scripts/check_link_test.go b/scripts/check_link_test.go
index 2342c27b12..21a1905fa9 100644
--- a/scripts/check_link_test.go
+++ b/scripts/check_link_test.go
@@ -1,12 +1,12 @@
package tests
import (
+ "io"
"net/http"
"os"
"path/filepath"
"regexp"
"testing"
- "time"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
@@ -31,7 +31,7 @@ var (
frontendDirectory = "../frontend"
)
-func TestLinkHealth(t *testing.T) {
+func TestValidateLinks(t *testing.T) {
links, err := extractLinkRecursive()
require.NoError(t, err)
@@ -44,10 +44,10 @@ func TestLinkHealth(t *testing.T) {
}
func extractLinkRecursive() (map[string]bool, error) {
- // Initialize the result map
+ // Initialize the result map.
links := make(map[string]bool)
- // Define the function to be used with os.Walk
+ // Define the function to be used with os.Walk.
walkFn := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@@ -89,20 +89,18 @@ func extractLinkRecursive() (map[string]bool, error) {
}
func checkLinkWithRetry(link string) error {
- for i := 0; i < 3; i++ {
- // Request the link and check the response status code is 200.
- res, err := http.Head(link)
- // Make the linter happy.
- _ = res.Body.Close()
- if err != nil {
- return errors.Wrapf(err, "failed to request link: %s", link)
- }
- if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusPermanentRedirect {
- time.Sleep(1 * time.Minute)
- continue
- }
- return nil
+ // Request the link and check the response status code is 200.
+ resp, err := http.Get(link)
+ if err != nil {
+ return errors.Wrapf(err, "failed to request link %q", link)
}
-
- return errors.Errorf("Link %s is not reachable after %d retries", link, 3)
+ defer resp.Body.Close()
+ b, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return errors.Wrapf(err, "failed to read link %q", link)
+ }
+ if resp.StatusCode != http.StatusOK {
+ return errors.Errorf("link %q returned status %q content %q", link, resp.Status, b)
+ }
+ return nil
}