Skip to content

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

chore: use empty string to receive changes from all branches (#3194)

Danny Xu6864784d1f4e
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index 371df95082..d96ea14815 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -43,7 +43,7 @@
</div>
<div>
<div class="textlabel">
- {{ $t("common.branch") }} <span class="text-red-600">*</span>
+ {{ $t("common.branch") }}
</div>
<div class="mt-1 textinfolabel">
{{ $t("repository.branch-observe-file-change") }}
@@ -54,9 +54,12 @@
name="branch"
type="text"
class="textfield mt-2 w-full"
- placeholder="e.g. master"
+ placeholder="e.g. main"
:disabled="!allowEdit"
/>
+ <div class="mt-2 textinfolabel">
+ {{ $t("repository.branch-specify-tip") }}
+ </div>
</div>
<div>
<div class="textlabel">{{ $t("repository.base-directory") }}</div>
diff --git a/frontend/src/components/RepositoryPanel.vue b/frontend/src/components/RepositoryPanel.vue
index 338f6ce189..2d988d5c95 100644
--- a/frontend/src/components/RepositoryPanel.vue
+++ b/frontend/src/components/RepositoryPanel.vue
@@ -328,7 +328,6 @@ export default defineComponent({
const allowUpdate = computed(() => {
return (
- !isEmpty(state.repositoryConfig.branchFilter) &&
!isEmpty(state.repositoryConfig.filePathTemplate) &&
(props.repository.branchFilter !==
state.repositoryConfig.branchFilter ||
diff --git a/frontend/src/components/RepositorySetupWizard.vue b/frontend/src/components/RepositorySetupWizard.vue
index 7bc6d39d9f..0db01115d0 100644
--- a/frontend/src/components/RepositorySetupWizard.vue
+++ b/frontend/src/components/RepositorySetupWizard.vue
@@ -254,10 +254,7 @@ export default defineComponent({
const allowNext = computed((): boolean => {
if (state.currentStep == CONFIGURE_DEPLOY_STEP) {
- return (
- !isEmpty(state.config.repositoryConfig.branchFilter.trim()) &&
- !isEmpty(state.config.repositoryConfig.filePathTemplate.trim())
- );
+ return !isEmpty(state.config.repositoryConfig.filePathTemplate.trim());
}
return true;
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 6b057ac281..eef17e9436 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -915,6 +915,7 @@
},
"repository": {
"branch-observe-file-change": "The branch where Bytebase observes the file change.",
+ "branch-specify-tip": "Tips: You can use empty branch to receive changes from all branches.",
"base-directory": "Base directory",
"base-directory-description": "The root directory where Bytebase observes the file change. If empty, then it observes the entire repository.",
"file-path-template": "File path template",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 1a7dd39cf1..e0841b96e9 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -915,6 +915,7 @@
},
"repository": {
"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",
+ "branch-specify-tip": "诀窍: 可以使用空字符串跟踪所有分支的变更.",
"base-directory": "根目录",
"base-directory-description": "Bytebase 跟踪文件变更的根目录。如果为空,则他会跟踪整个仓库。",
"file-path-template": "文件路径模版",
diff --git a/frontend/src/types/repository.ts b/frontend/src/types/repository.ts
index 1c6c08c1da..be98a80fc2 100644
--- a/frontend/src/types/repository.ts
+++ b/frontend/src/types/repository.ts
@@ -98,6 +98,10 @@ export function baseDirectoryWebUrl(
repository: Repository,
params: WebUrlReplaceParams = {}
): string {
+ // If branchFilter is empty, we can't locate to the exact branch name, thus we will just return the repository web url
+ if (isEmpty(repository.branchFilter)) {
+ return repository.webUrl;
+ }
let url = "";
if (repository.vcs.type == "GITLAB_SELF_HOST") {
url = `${repository.webUrl}/-/tree/${repository.branchFilter}`;
diff --git a/server/project.go b/server/project.go
index 67b6976420..7ab1ecdc1a 100644
--- a/server/project.go
+++ b/server/project.go
@@ -244,6 +244,9 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, repositoryCreate); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformed create linked repository request").SetInternal(err)
}
+ if repositoryCreate.BranchFilter == "" && repositoryCreate.SchemaPathTemplate != "" {
+ return echo.NewHTTPError(http.StatusBadRequest, "Schema path template is supported only if branch is specified")
+ }
// We need to check the FilePathTemplate in create repository request.
// This avoids to a certain extent that the creation succeeds but does not work.
@@ -472,6 +475,16 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
repo := repoList[0]
repoPatch.ID = &repo.ID
+ newSchemaPathTemplate, newBranchFilter := repo.SchemaPathTemplate, repo.BranchFilter
+ if repoPatch.SchemaPathTemplate != nil {
+ newSchemaPathTemplate = *repoPatch.SchemaPathTemplate
+ }
+ if repoPatch.BranchFilter != nil {
+ newBranchFilter = *repoPatch.BranchFilter
+ }
+ if newBranchFilter == "" && newSchemaPathTemplate != "" {
+ return echo.NewHTTPError(http.StatusBadRequest, "Schema path template is supported only if branch is specified")
+ }
// We need to check the FilePathTemplate in create repository request.
// This avoids to a certain extent that the creation succeeds but does not work.
diff --git a/server/task_executor.go b/server/task_executor.go
index 3397142db1..202546e78c 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -175,11 +175,11 @@ func postMigration(ctx context.Context, server *Server, task *api.Task, vcsPushE
return true, nil, errors.Errorf("failed to find linked repository for database %q", task.Database.Name)
}
- // We write back the latest schema after migration for VCS-based projects when schema path template is specified and
+ // We write back the latest schema after migration for VCS-based projects when schema path template and branch filter is specified and
// 1) baseline migration for SDL,
// 2) all DDL/Ghost migrations.
writeBack := false
- if repo != nil && repo.SchemaPathTemplate != "" {
+ if repo != nil && repo.SchemaPathTemplate != "" && repo.BranchFilter != "" {
if repo.Project.SchemaChangeType == api.ProjectSchemaChangeTypeSDL {
if task.Type == api.TaskDatabaseSchemaBaseline {
writeBack = true
@@ -243,17 +243,7 @@ func postMigration(ctx context.Context, server *Server, task *api.Task, vcsPushE
bytebaseURL = fmt.Sprintf("%s/issue/%s?stage=%d", server.profile.ExternalURL, api.IssueSlug(issue), task.StageID)
}
- // TODO(d): we need to figure out the baseline write-back for users using wildcard branch filter.
- branch := repo.BranchFilter
- if vcsPushEvent != nil {
- b, err := parseBranchNameFromRefs(vcsPushEvent.Ref)
- if err != nil {
- return true, nil, errors.Errorf("failed to parse branch name: %s", vcsPushEvent.Ref)
- }
- branch = b
- }
- // Use the branch name from the commit as we will write back to the same branch.
- commitID, err := writeBackLatestSchema(ctx, server, repo, vcsPushEvent, mi, branch, latestSchemaFile, schema, bytebaseURL)
+ commitID, err := writeBackLatestSchema(ctx, server, repo, vcsPushEvent, mi, repo.BranchFilter, latestSchemaFile, schema, bytebaseURL)
if err != nil {
return true, nil, err
}
diff --git a/server/webhook.go b/server/webhook.go
index 9598921820..fd4540db4d 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -429,9 +429,8 @@ func (s *Server) filterRepository(ctx context.Context, webhookEndpointID string,
}
func (*Server) isWebhookEventBranch(pushEventRef, branchFilter string) (bool, error) {
- // TODO(d): we will accept all pushes from wildcard branch filter for now.
- // We should implement our own branch filter later.
- if strings.HasSuffix(branchFilter, "*") {
+ // Empty branch filter will accept pushed from any branch.
+ if branchFilter == "" {
return true, nil
}
branch, err := parseBranchNameFromRefs(pushEventRef)