Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(VCS): auto-remove the source branch after PR is merged (#2936)
ecmadaoc3601f630f2b
diff --git a/plugin/vcs/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.goindex a0b99b2f5b..b96e796aab 100644--- a/plugin/vcs/gitlab/gitlab.go+++ b/plugin/vcs/gitlab/gitlab.go@@ -770,10 +770,11 @@ type gitlabBranchCreate struct {}type gitlabMergeRequestCreate struct {- Title string `json:"title"`- Description string `json:"description"`- SourceBranch string `json:"source_branch"`- TargetBranch string `json:"target_branch"`+ Title string `json:"title"`+ Description string `json:"description"`+ SourceBranch string `json:"source_branch"`+ TargetBranch string `json:"target_branch"`+ RemoveSourceBranch bool `json:"remove_source_branch"`}// GetBranch gets the given branch in the repository.@@ -875,10 +876,11 @@ func (p *Provider) CreateBranch(ctx context.Context, oauthCtx common.OauthContexfunc (p *Provider) CreatePullRequest(ctx context.Context, oauthCtx common.OauthContext, instanceURL, repositoryID string, pullRequestCreate *vcs.PullRequestCreate) error {body, err := json.Marshal(gitlabMergeRequestCreate{- Title: pullRequestCreate.Title,- Description: pullRequestCreate.Body,- SourceBranch: pullRequestCreate.Head,- TargetBranch: pullRequestCreate.Base,+ Title: pullRequestCreate.Title,+ Description: pullRequestCreate.Body,+ SourceBranch: pullRequestCreate.Head,+ TargetBranch: pullRequestCreate.Base,+ RemoveSourceBranch: pullRequestCreate.RemoveHeadAfterMerged,},)if err != nil {diff --git a/plugin/vcs/gitlab/sql-review.yml b/plugin/vcs/gitlab/sql-review.ymlindex 0f2a7d4a81..aa9fe5973f 100644--- a/plugin/vcs/gitlab/sql-review.yml+++ b/plugin/vcs/gitlab/sql-review.yml@@ -12,7 +12,7 @@ sql-review:- echo "Start request $API/pull/$CI_MERGE_REQUEST_IID"- 'response=$(curl -s --show-error -X GET "$API/pull/$CI_MERGE_REQUEST_IID" -H "Content-type: application/json" -H "X-SQL-Review-Token: $%s")'- echo $response- - xml=$(echo $response | jq -r '.content')+ - content=$(echo $response | jq -r '.content')- status=$(echo $response | jq -r '.status')- for msg in $(echo $content | jq -r '.[]'); do echo $msg >> sql-review.xml; done- if [ "$status" == "ERROR" ]; then exit 1; fidiff --git a/plugin/vcs/vcs.go b/plugin/vcs/vcs.goindex 2a216931b5..416f54eb8a 100644--- a/plugin/vcs/vcs.go+++ b/plugin/vcs/vcs.go@@ -151,6 +151,9 @@ type PullRequestCreate struct {Body string `json:"body"`Head string `json:"head"`Base string `json:"base"`+ // Flag indicating if a merge request should remove the source branch after merging.+ // Only support GitLab.+ RemoveHeadAfterMerged bool `json:"-"`}// Provider is the interface for VCS provider.diff --git a/server/project.go b/server/project.goindex f6dc61967e..af91cf9bfc 100644--- a/server/project.go+++ b/server/project.go@@ -636,10 +636,11 @@ func (s *Server) setupVCSSQLReviewCI(ctx context.Context, repository *api.Reposirepository.VCS.InstanceURL,repository.ExternalID,&vcsPlugin.PullRequestCreate{- Title: sqlReviewInVCSPRTitle,- Body: "This pull request is auto-generated by Bytebase.",- Head: branch.Name,- Base: repository.BranchFilter,+ Title: sqlReviewInVCSPRTitle,+ Body: "This pull request is auto-generated by Bytebase for GitOps workflow.",+ Head: branch.Name,+ Base: repository.BranchFilter,+ RemoveHeadAfterMerged: true,},)}