Skip to content

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

refactor: move gitlab and vcs code to plugin/vcs (#309)

tianzhoud5c5ed7a0e44
diff --git a/api/activity.go b/api/activity.go
index 4671854e3f..abdb956b19 100644
--- a/api/activity.go
+++ b/api/activity.go
@@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
- "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/vcs"
)
// ActivityType is the type for an activity.
@@ -220,7 +220,7 @@ type ActivityMemberActivateDeactivatePayload struct {
// ActivityProjectRepositoryPushPayload is the API message payloads for pushing repositories.
type ActivityProjectRepositoryPushPayload struct {
- VCSPushEvent common.VCSPushEvent `json:"pushEvent"`
+ VCSPushEvent vcs.VCSPushEvent `json:"pushEvent"`
// Used by activity table to display info without paying the join cost
// IssueID/IssueName only exist if the push event leads to the issue creation.
IssueID int `json:"issueId,omitempty"`
diff --git a/api/issue.go b/api/issue.go
index 8754e7903c..d14c8f2d6b 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -3,8 +3,8 @@ package api
import (
"context"
- "github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/vcs"
)
// IssueStatus is the status of an issue.
@@ -158,7 +158,7 @@ type UpdateSchemaContext struct {
// When a project is in tenant mode, there should be one item in the list.
UpdateSchemaDetailList []*UpdateSchemaDetail `json:"updateSchemaDetailList"`
// VCSPushEvent is the event information for VCS push.
- VCSPushEvent *common.VCSPushEvent
+ VCSPushEvent *vcs.VCSPushEvent
}
// IssueFind is the API message for finding issues.
diff --git a/api/task.go b/api/task.go
index dc250a096a..7647a5fedf 100644
--- a/api/task.go
+++ b/api/task.go
@@ -6,6 +6,7 @@ import (
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/vcs"
)
// These are special onboarding tasks for demo purpose when bootstraping the workspace.
@@ -86,10 +87,10 @@ type TaskDatabaseCreatePayload struct {
// TaskDatabaseSchemaUpdatePayload is the task payload for database schema update.
type TaskDatabaseSchemaUpdatePayload struct {
- MigrationType db.MigrationType `json:"migrationType,omitempty"`
- Statement string `json:"statement,omitempty"`
- RollbackStatement string `json:"rollbackStatement,omitempty"`
- VCSPushEvent *common.VCSPushEvent `json:"pushEvent,omitempty"`
+ MigrationType db.MigrationType `json:"migrationType,omitempty"`
+ Statement string `json:"statement,omitempty"`
+ RollbackStatement string `json:"rollbackStatement,omitempty"`
+ VCSPushEvent *vcs.VCSPushEvent `json:"pushEvent,omitempty"`
}
// TaskDatabaseBackupPayload is the task payload for database backup.
@@ -164,7 +165,7 @@ type TaskCreate struct {
Collation string `jsonapi:"attr,collation"`
Labels string `jsonapi:"attr,labels"`
BackupID *int `jsonapi:"attr,backupId"`
- VCSPushEvent *common.VCSPushEvent
+ VCSPushEvent *vcs.VCSPushEvent
MigrationType db.MigrationType `jsonapi:"attr,migrationType"`
}
diff --git a/api/vcs.go b/api/vcs.go
index c4661b7cb2..8cf7190a01 100644
--- a/api/vcs.go
+++ b/api/vcs.go
@@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
- "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/vcs"
)
// VCS is the API message for VCS.
@@ -20,12 +20,12 @@ type VCS struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Type common.VCSType `jsonapi:"attr,type"`
- InstanceURL string `jsonapi:"attr,instanceUrl"`
- APIURL string `jsonapi:"attr,apiUrl"`
- ApplicationID string `jsonapi:"attr,applicationId"`
- Secret string `jsonapi:"attr,secret"`
+ Name string `jsonapi:"attr,name"`
+ Type vcs.VCSType `jsonapi:"attr,type"`
+ InstanceURL string `jsonapi:"attr,instanceUrl"`
+ APIURL string `jsonapi:"attr,apiUrl"`
+ ApplicationID string `jsonapi:"attr,applicationId"`
+ Secret string `jsonapi:"attr,secret"`
}
// VCSCreate is the API message for creating a VCS.
@@ -35,9 +35,9 @@ type VCSCreate struct {
CreatorID int
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Type common.VCSType `jsonapi:"attr,type"`
- InstanceURL string `jsonapi:"attr,instanceUrl"`
+ Name string `jsonapi:"attr,name"`
+ Type vcs.VCSType `jsonapi:"attr,type"`
+ InstanceURL string `jsonapi:"attr,instanceUrl"`
// APIURL derives from InstanceURL
APIURL string
ApplicationID string `jsonapi:"attr,applicationId"`
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index 9b896b8152..173e7fbe31 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -10,7 +10,7 @@ import (
"strings"
"sync"
- "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/vcs"
"go.uber.org/zap"
)
@@ -193,7 +193,7 @@ func (e MigrationStatus) String() string {
// MigrationInfoPayload is the API message for migration info payload.
type MigrationInfoPayload struct {
- VCSPushEvent *common.VCSPushEvent `json:"pushEvent,omitempty"`
+ VCSPushEvent *vcs.VCSPushEvent `json:"pushEvent,omitempty"`
}
// MigrationInfo is the API message for migration info.
diff --git a/external/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.go
similarity index 100%
rename from external/gitlab/gitlab.go
rename to plugin/vcs/gitlab/gitlab.go
diff --git a/common/vcs.go b/plugin/vcs/vcs.go
similarity index 98%
rename from common/vcs.go
rename to plugin/vcs/vcs.go
index 0083494190..4ee81cc63a 100644
--- a/common/vcs.go
+++ b/plugin/vcs/vcs.go
@@ -1,4 +1,4 @@
-package common
+package vcs
// VCSType is the type of VCS.
type VCSType string
diff --git a/server/issue.go b/server/issue.go
index f7cba7d3f3..b0983a48c9 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -13,6 +13,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/vcs"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
@@ -825,7 +826,7 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.I
return createdPipeline, nil
}
-func getSchemaUpdateTask(database *api.Database, migrationType db.MigrationType, vcsPushEvent *common.VCSPushEvent, d *api.UpdateSchemaDetail) (*api.TaskCreate, error) {
+func getSchemaUpdateTask(database *api.Database, migrationType db.MigrationType, vcsPushEvent *vcs.VCSPushEvent, d *api.UpdateSchemaDetail) (*api.TaskCreate, error) {
taskName := fmt.Sprintf("Establish %q baseline", database.Name)
if migrationType == db.Migrate {
taskName = fmt.Sprintf("Update %q schema", database.Name)
diff --git a/server/project.go b/server/project.go
index ed377d6265..654c2c97f2 100644
--- a/server/project.go
+++ b/server/project.go
@@ -11,7 +11,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
- "github.com/bytebase/bytebase/external/gitlab"
+ "github.com/bytebase/bytebase/plugin/vcs/gitlab"
"github.com/google/jsonapi"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
diff --git a/server/task_executor_schema_update.go b/server/task_executor_schema_update.go
index cbc0ab7dd4..5ad457e4f9 100644
--- a/server/task_executor_schema_update.go
+++ b/server/task_executor_schema_update.go
@@ -12,8 +12,9 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
- "github.com/bytebase/bytebase/external/gitlab"
"github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/vcs"
+ "github.com/bytebase/bytebase/plugin/vcs/gitlab"
"go.uber.org/zap"
)
@@ -246,7 +247,7 @@ func (exec *SchemaUpdateTaskExecutor) RunOnce(ctx context.Context, server *Serve
// Writes back the latest schema to the repository after migration
// Returns the commit id on success.
-func writeBackLatestSchema(ctx context.Context, server *Server, repository *api.Repository, pushEvent *common.VCSPushEvent, mi *db.MigrationInfo, branch string, latestSchemaFile string, schema string, bytebaseURL string) (string, error) {
+func writeBackLatestSchema(ctx context.Context, server *Server, repository *api.Repository, pushEvent *vcs.VCSPushEvent, mi *db.MigrationInfo, branch string, latestSchemaFile string, schema string, bytebaseURL string) (string, error) {
filePath := fmt.Sprintf("projects/%s/repository/files/%s", repository.ExternalID, url.QueryEscape(latestSchemaFile))
getFilePath := filePath + "?ref=" + url.QueryEscape(branch)
diff --git a/server/vcs.go b/server/vcs.go
index 797433c8fa..dc2ea49804 100644
--- a/server/vcs.go
+++ b/server/vcs.go
@@ -9,7 +9,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
- "github.com/bytebase/bytebase/external/gitlab"
+ "github.com/bytebase/bytebase/plugin/vcs/gitlab"
"github.com/google/jsonapi"
"github.com/labstack/echo/v4"
)
diff --git a/server/webhook.go b/server/webhook.go
index 89054f7f55..4ebdb27887 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -15,8 +15,9 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
- "github.com/bytebase/bytebase/external/gitlab"
"github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/vcs"
+ "github.com/bytebase/bytebase/plugin/vcs/gitlab"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
@@ -107,7 +108,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
}
- vcsPushEvent := common.VCSPushEvent{
+ vcsPushEvent := vcs.VCSPushEvent{
VCSType: repository.VCS.Type,
BaseDirectory: repository.BaseDirectory,
Ref: pushEvent.Ref,
@@ -115,7 +116,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
RepositoryURL: pushEvent.Project.WebURL,
RepositoryFullPath: pushEvent.Project.FullPath,
AuthorName: pushEvent.AuthorName,
- FileCommit: common.VCSFileCommit{
+ FileCommit: vcs.VCSFileCommit{
ID: commit.ID,
Title: commit.Title,
Message: commit.Message,