Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: derive the correct branch name if it contains slash (e.g. feature/xxx) (#409)
tianzhou1a5b8c3651c9
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vueindex 8165877d72..b2a76161e0 100644--- a/frontend/src/components/Issue/IssueHighlightPanel.vue+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue@@ -22,22 +22,14 @@/></div><div v-if="!create">- <i18n-t- keypath="issue.opened-by-at"- tag="p"- class="text-sm text-control-light"- >+ <i18n-t keypath="issue.opened-by-at" tag="p" class="text-sm text-control-light"><template #creator><router-link:to="`/u/${issue.creator.id}`"class="font-medium text-control hover:underline"- >- {{ issue.creator.name }}- </router-link>- </template>- <template #time>- {{ dayjs(issue.updatedTs * 1000).format("LLL") }}+ >{{ issue.creator.name }}</router-link></template>+ <template #time>{{ dayjs(issue.updatedTs * 1000).format("LLL") }}</template></i18n-t><pv-if="pushEvent"@@ -46,9 +38,11 @@<template v-if="pushEvent.vcsType.startsWith('GITLAB')"><img class="h-4 w-auto" src="../../assets/gitlab-logo.svg" /></template>- <a :href="vcsBranchUrl" target="_blank" class="normal-link">- {{ `${vcsBranch}@${pushEvent.repositoryFullPath}` }}- </a>+ <a+ :href="vcsBranchUrl"+ target="_blank"+ class="normal-link"+ >{{ `${vcsBranch}@${pushEvent.repositoryFullPath}` }}</a><i18n-t keypath="issue.commit-by-at" tag="span"><template #id>@@ -56,17 +50,13 @@:href="pushEvent.fileCommit.url"target="_blank"class="normal-link"- >- {{ pushEvent.fileCommit.id.substring(0, 7) }}:- </a>+ >{{ pushEvent.fileCommit.id.substring(0, 7) }}:</a></template><template #title><span class="text-main">{{ pushEvent.fileCommit.title }}</span></template><template #author>{{ pushEvent.authorName }}</template>- <template #time>- {{ dayjs(pushEvent.fileCommit.createdTs * 1000).format("LLL") }}- </template>+ <template #time>{{ dayjs(pushEvent.fileCommit.createdTs * 1000).format("LLL") }}</template></i18n-t></p></div>@@ -144,10 +134,7 @@ export default defineComponent({const vcsBranch = computed((): string => {if (pushEvent.value) {- if (pushEvent.value.vcsType == "GITLAB_SELF_HOST") {- const parts = pushEvent.value.ref.split("/");- return parts[parts.length - 1];- }+ return pushEvent.value.ref.replace(/^refs\/heads\//g, "")}return "";});diff --git a/plugin/vcs/util.go b/plugin/vcs/util.gonew file mode 100644index 0000000000..1a703d7cd6--- /dev/null+++ b/plugin/vcs/util.go@@ -0,0 +1,16 @@+package vcs++import (+ "fmt"+ "strings"+)++// For now, this method only supports branch reference.+// https://git-scm.com/book/en/v2/Git-Internals-Git-References+func Branch(ref string) (string, error) {+ if strings.HasPrefix(ref, "refs/heads/") {+ return strings.TrimPrefix(ref, "refs/heads/"), nil+ }++ return "", fmt.Errorf("invalid Git ref: %s", ref)+}diff --git a/plugin/vcs/util_test.go b/plugin/vcs/util_test.gonew file mode 100644index 0000000000..7aae9118e1--- /dev/null+++ b/plugin/vcs/util_test.go@@ -0,0 +1,44 @@+package vcs++import (+ "testing"+)++func TestBranch(t *testing.T) {+ tests := []struct {+ ref string+ want string+ wantErr bool+ }{+ {+ ref: "refs/heads/master",+ want: "master",+ wantErr: false,+ },+ {+ ref: "refs/heads/feature/foo",+ want: "feature/foo",+ wantErr: false,+ },+ {+ ref: "refs/heads/feature/foo",+ want: "feature/foo",+ wantErr: false,+ },+ }++ for _, test := range tests {+ result, err := Branch(test.ref)+ if err != nil && !test.wantErr {+ t.Errorf("Branch %q: got error %v, want OK.", test.ref, test.wantErr)+ }++ if err == nil && test.wantErr {+ t.Errorf("Branch %q: got OK, want error", test.ref)+ }++ if result != test.want {+ t.Errorf("Branch %q: got result %v, want %v.", test.ref, result, test.want)+ }+ }+}diff --git a/server/task_executor.go b/server/task_executor.goindex d7cfae7607..079bbdeafe 100644--- a/server/task_executor.go+++ b/server/task_executor.go@@ -173,9 +173,10 @@ func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.}// Writes back the latest schema file to the same branch as the push event.- // Ref format refs/heads/<<branch>>- refComponents := strings.Split(vcsPushEvent.Ref, "/")- branch := refComponents[len(refComponents)-1]+ branch, err := vcs.Branch(vcsPushEvent.Ref)+ if err != nil {+ return true, nil, err+ }bytebaseURL := ""if issue != nil {