Skip to content

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

refactor: fix lint warnings and enable golinter (#566)

Danny Xu0dceb297b997
diff --git a/.golangci.yaml b/.golangci.yaml
index 2b81ff4879..622a3ceec2 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -1,5 +1,11 @@
linters:
disable:
- errcheck
+ enable:
+ - goimports
+ - golint
+ - govet
+ - staticcheck
+
run:
timeout: 5m
diff --git a/api/activity.go b/api/activity.go
index 45dbb22c15..55b4012f94 100644
--- a/api/activity.go
+++ b/api/activity.go
@@ -227,7 +227,7 @@ type ActivityMemberActivateDeactivatePayload struct {
// ActivityProjectRepositoryPushPayload is the API message payloads for pushing repositories.
type ActivityProjectRepositoryPushPayload struct {
- VCSPushEvent vcs.VCSPushEvent `json:"pushEvent"`
+ VCSPushEvent vcs.PushEvent `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/auth.go b/api/auth.go
index a49937e9cc..4908e07733 100644
--- a/api/auth.go
+++ b/api/auth.go
@@ -2,6 +2,7 @@ package api
import "github.com/bytebase/bytebase/plugin/vcs"
+// AuthProvider is the authentication provider which only supports GitLab for now.
type AuthProvider struct {
Type vcs.Type `jsonapi:"attr,type"`
Name string `jsonapi:"attr,name"`
diff --git a/api/issue.go b/api/issue.go
index b41f49f2af..659f33d0b7 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -160,7 +160,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 *vcs.VCSPushEvent
+ VCSPushEvent *vcs.PushEvent
}
// IssueFind is the API message for finding issues.
diff --git a/api/principal.go b/api/principal.go
index 5166383582..da8c1d5d96 100644
--- a/api/principal.go
+++ b/api/principal.go
@@ -28,10 +28,13 @@ func (e PrincipalType) String() string {
return ""
}
+// PrincipalAuthProvider is the type of an authentication provider.
type PrincipalAuthProvider string
const (
- PrincipalAuthProviderBytebase PrincipalAuthProvider = "BYTEBASE"
+ // PrincipalAuthProviderBytebase is the Bytebase's own authentication provider.
+ PrincipalAuthProviderBytebase PrincipalAuthProvider = "BYTEBASE"
+ // PrincipalAuthProviderGitlabSelfHost is the self-hosted GitLab authentication provider.
PrincipalAuthProviderGitlabSelfHost PrincipalAuthProvider = "GITLAB_SELF_HOST"
)
diff --git a/api/sheet.go b/api/sheet.go
index 505f9c9309..fd5a1b7681 100644
--- a/api/sheet.go
+++ b/api/sheet.go
@@ -9,11 +9,11 @@ import (
type SheetVisibility string
const (
- // Private is the sheet visibility for PRIVATE. Only sheet OWNER can read/write.
+ // PrivateSheet is the sheet visibility for PRIVATE. Only sheet OWNER can read/write.
PrivateSheet SheetVisibility = "PRIVATE"
- // Project is the sheet visibility for PROJECT. Both sheet OWNER and project OWNER can read/write, and project DEVELOPER can read.
+ // ProjectSheet is the sheet visibility for PROJECT. Both sheet OWNER and project OWNER can read/write, and project DEVELOPER can read.
ProjectSheet SheetVisibility = "PROJECT"
- // Public is the sheet visibility for PUBLIC. Sheet OWNER can read/write, and all others can read.
+ // PublicSheet is the sheet visibility for PUBLIC. Sheet OWNER can read/write, and all others can read.
PublicSheet SheetVisibility = "PUBLIC"
)
@@ -42,12 +42,12 @@ type Sheet struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Related fields
- InstanceID int `jsonapi:"attr,instanceId"`
+ InstanceID int `jsonapi:"attr,instanceId"`
DatabaseID *int `jsonapi:"attr,databaseId"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Statement string `jsonapi:"attr,statement"`
+ Name string `jsonapi:"attr,name"`
+ Statement string `jsonapi:"attr,statement"`
Visibility SheetVisibility `jsonapi:"attr,visibility"`
}
@@ -58,12 +58,12 @@ type SheetCreate struct {
CreatorID int
// Related fields
- InstanceID int `jsonapi:"attr,instanceId"`
+ InstanceID int `jsonapi:"attr,instanceId"`
DatabaseID *int `jsonapi:"attr,databaseId"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Statement string `jsonapi:"attr,statement"`
+ Name string `jsonapi:"attr,name"`
+ Statement string `jsonapi:"attr,statement"`
Visibility SheetVisibility `jsonapi:"attr,visibility"`
}
@@ -76,19 +76,19 @@ type SheetPatch struct {
UpdaterID int
// Related fields
- InstanceID int `jsonapi:"attr,instanceId"`
+ InstanceID int `jsonapi:"attr,instanceId"`
DatabaseID *int `jsonapi:"attr,databaseId"`
// Domain specific fields
- Name *string `jsonapi:"attr,name"`
- Statement *string `jsonapi:"attr,statement"`
+ Name *string `jsonapi:"attr,name"`
+ Statement *string `jsonapi:"attr,statement"`
Visibility *SheetVisibility `jsonapi:"attr,visibility"`
}
// SheetFind is the API message for finding sheets.
type SheetFind struct {
// Standard fields
- ID *int
+ ID *int
RowStatus *RowStatus
// Value is assigned from the jwt subject field passed by the client.
CreatorID *int
diff --git a/api/task.go b/api/task.go
index f1c26db714..cc0982cd69 100644
--- a/api/task.go
+++ b/api/task.go
@@ -89,17 +89,17 @@ type TaskDatabaseCreatePayload struct {
// TaskDatabaseSchemaUpdatePayload is the task payload for database schema update (DDL).
type TaskDatabaseSchemaUpdatePayload struct {
- MigrationType db.MigrationType `json:"migrationType,omitempty"`
- Statement string `json:"statement,omitempty"`
- RollbackStatement string `json:"rollbackStatement,omitempty"`
- VCSPushEvent *vcs.VCSPushEvent `json:"pushEvent,omitempty"`
+ MigrationType db.MigrationType `json:"migrationType,omitempty"`
+ Statement string `json:"statement,omitempty"`
+ RollbackStatement string `json:"rollbackStatement,omitempty"`
+ VCSPushEvent *vcs.PushEvent `json:"pushEvent,omitempty"`
}
// TaskDatabaseDataUpdatePayload is the task payload for database data update (DML).
type TaskDatabaseDataUpdatePayload struct {
- Statement string `json:"statement,omitempty"`
- RollbackStatement string `json:"rollbackStatement,omitempty"`
- VCSPushEvent *vcs.VCSPushEvent `json:"pushEvent,omitempty"`
+ Statement string `json:"statement,omitempty"`
+ RollbackStatement string `json:"rollbackStatement,omitempty"`
+ VCSPushEvent *vcs.PushEvent `json:"pushEvent,omitempty"`
}
// TaskDatabaseBackupPayload is the task payload for database backup.
@@ -174,7 +174,7 @@ type TaskCreate struct {
Collation string `jsonapi:"attr,collation"`
Labels string `jsonapi:"attr,labels"`
BackupID *int `jsonapi:"attr,backupId"`
- VCSPushEvent *vcs.VCSPushEvent
+ VCSPushEvent *vcs.PushEvent
MigrationType db.MigrationType `jsonapi:"attr,migrationType"`
}
diff --git a/bin/bb/cmd/dump.go b/bin/bb/cmd/dump.go
index 5c97a27364..da1d7ce025 100644
--- a/bin/bb/cmd/dump.go
+++ b/bin/bb/cmd/dump.go
@@ -1,4 +1,4 @@
-// cmd is the command surface of Bytebase bb tool provided by bytebase.com.
+// Package cmd is the command surface of Bytebase bb tool provided by bytebase.com.
package cmd
import (
diff --git a/bin/bb/cmd/restore.go b/bin/bb/cmd/restore.go
index b3c4f3493f..534d226de1 100644
--- a/bin/bb/cmd/restore.go
+++ b/bin/bb/cmd/restore.go
@@ -1,4 +1,4 @@
-// cmd is the command surface of Bytebase bb tool provided by bytebase.com.
+// Package cmd is the command surface of Bytebase bb tool provided by bytebase.com.
package cmd
import (
@@ -19,8 +19,12 @@ func init() {
restoreCmd.Flags().StringVar(&port, "port", "", "Port of database. (default mysql:3306 pg:5432).")
restoreCmd.Flags().StringVar(&database, "database", "", "Database to connect and export.")
restoreCmd.Flags().StringVar(&file, "file", "", "File to store the dump.")
- restoreCmd.MarkFlagRequired("database")
- restoreCmd.MarkFlagRequired("file")
+ if err := restoreCmd.MarkFlagRequired("database"); err != nil {
+ panic(err)
+ }
+ if err := restoreCmd.MarkFlagRequired("file"); err != nil {
+ panic(err)
+ }
// tls flags for SSL connection.
restoreCmd.Flags().StringVar(&sslCA, "ssl-ca", "", "CA file in PEM format.")
diff --git a/bin/bb/cmd/root.go b/bin/bb/cmd/root.go
index 77da930f26..f4291fb12a 100644
--- a/bin/bb/cmd/root.go
+++ b/bin/bb/cmd/root.go
@@ -1,4 +1,4 @@
-// cmd is the command surface of Bytebase bb tool provided by bytebase.com.
+// Package cmd is the command surface of Bytebase bb tool provided by bytebase.com.
package cmd
import (
diff --git a/bin/bb/cmd/var.go b/bin/bb/cmd/var.go
index 74648717ec..a748369d04 100644
--- a/bin/bb/cmd/var.go
+++ b/bin/bb/cmd/var.go
@@ -1,4 +1,4 @@
-// cmd is the command surface of Bytebase bb tool provided by bytebase.com.
+// Package cmd is the command surface of Bytebase bb tool provided by bytebase.com.
package cmd
import "go.uber.org/zap"
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index 644354692e..9450375830 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -12,32 +12,32 @@ import (
"go.uber.org/zap"
)
-// licenseService is the service for enterprise license.
-type licenseService struct {
+// LicenseService is the service for enterprise license.
+type LicenseService struct {
l *zap.Logger
config *config.Config
}
// NewLicenseService will create a new enterprise license service.
-func NewLicenseService(l *zap.Logger, dataDir string, mode string) (*licenseService, error) {
+func NewLicenseService(l *zap.Logger, dataDir string, mode string) (*LicenseService, error) {
config, err := config.NewConfig(l, dataDir, mode)
if err != nil {
return nil, err
}
- return &licenseService{
+ return &LicenseService{
config: config,
l: l,
}, nil
}
// StoreLicense will store license into file.
-func (s *licenseService) StoreLicense(tokenString string) error {
+func (s *LicenseService) StoreLicense(tokenString string) error {
return s.writeLicense(tokenString)
}
// LoadLicense will load license from file and validate it.
-func (s *licenseService) LoadLicense() (*enterpriseAPI.License, error) {
+func (s *LicenseService) LoadLicense() (*enterpriseAPI.License, error) {
tokenString, err := s.readLicense()
if err != nil {
return nil, err
@@ -76,7 +76,7 @@ func (s *licenseService) LoadLicense() (*enterpriseAPI.License, error) {
}
// parseClaims will valid and parse JWT claims to license instance.
-func (s *licenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.License, error) {
+func (s *LicenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.License, error) {
err := claims.Valid()
if err != nil {
return nil, common.Errorf(common.Invalid, err)
@@ -126,7 +126,7 @@ func (s *licenseService) parseClaims(claims jwt.MapClaims) (*enterpriseAPI.Licen
return license, nil
}
-func (s *licenseService) readLicense() (string, error) {
+func (s *LicenseService) readLicense() (string, error) {
token, err := ioutil.ReadFile(s.config.StorePath)
if err != nil {
return "", common.Errorf(
@@ -138,7 +138,7 @@ func (s *licenseService) readLicense() (string, error) {
return string(token), nil
}
-func (s *licenseService) writeLicense(token string) error {
+func (s *LicenseService) writeLicense(token string) error {
return ioutil.WriteFile(s.config.StorePath, []byte(token), 0644)
}
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index 2a31e2ec74..3fff1550f9 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -1,4 +1,4 @@
-// Advisor defines the interface for analyzing sql statements.
+// Package advisor defines the interface for analyzing sql statements.
// The advisor could be syntax checker, index suggestion etc.
package advisor
@@ -11,12 +11,16 @@ import (
"go.uber.org/zap"
)
+// Status is the advisor result status.
type Status string
const (
+ // Success is the adivsor status for successes.
Success Status = "SUCCESS"
- Warn Status = "WARN"
- Error Status = "ERROR"
+ // Warn is the adivsor status for warnings.
+ Warn Status = "WARN"
+ // Error is the adivsor status for errors.
+ Error Status = "ERROR"
)
func (e Status) String() string {
@@ -31,14 +35,19 @@ func (e Status) String() string {
return "UNKNOWN"
}
-type AdvisorType string
+// Type is the type of advisor.
+type Type string
const (
- Fake AdvisorType = "bb.plugin.advisor.fake"
- MySQLSyntax AdvisorType = "bb.plugin.advisor.mysql.syntax"
- MySQLMigrationCompatibility AdvisorType = "bb.plugin.advisor.mysql.migration-compatibility"
+ // Fake is a fake advisor type for testing.
+ Fake Type = "bb.plugin.advisor.fake"
+ // MySQLSyntax is an advisor type for MySQL syntax.
+ MySQLSyntax Type = "bb.plugin.advisor.mysql.syntax"
+ // MySQLMigrationCompatibility is an advisor type for MySQL migration compatibility.
+ MySQLMigrationCompatibility Type = "bb.plugin.advisor.mysql.migration-compatibility"
)
+// Advice is the result of an advisor.
type Advice struct {
Status Status
Code common.Code
@@ -46,25 +55,27 @@ type Advice struct {
Content string
}
-type AdvisorContext struct {
+// Context is the context for advisor.
+type Context struct {
Logger *zap.Logger
Charset string
Collation string
}
+// Advisor is the interface for advisor.
type Advisor interface {
- Check(ctx AdvisorContext, statement string) ([]Advice, error)
+ Check(ctx Context, statement string) ([]Advice, error)
}
var (
advisorMu sync.RWMutex
- advisors = make(map[db.Type]map[AdvisorType]Advisor)
+ advisors = make(map[db.Type]map[Type]Advisor)
)
// Register makes a advisor available by the provided id.
// If Register is called twice with the same name or if advisor is nil,
// it panics.
-func Register(dbType db.Type, advType AdvisorType, f Advisor) {
+func Register(dbType db.Type, advType Type, f Advisor) {
advisorMu.Lock()
defer advisorMu.Unlock()
if f == nil {
@@ -72,7 +83,7 @@ func Register(dbType db.Type, advType AdvisorType, f Advisor) {
}
dbAdvisors, ok := advisors[dbType]
if !ok {
- advisors[dbType] = map[AdvisorType]Advisor{
+ advisors[dbType] = map[Type]Advisor{
advType: f,
}
} else {
@@ -83,7 +94,8 @@ func Register(dbType db.Type, advType AdvisorType, f Advisor) {
}
}
-func Check(dbType db.Type, advType AdvisorType, ctx AdvisorContext, statement string) ([]Advice, error) {
+// Check runs the advisor and returns the advices.
+func Check(dbType db.Type, advType Type, ctx Context, statement string) ([]Advice, error) {
advisorMu.RLock()
dbAdvisors, ok := advisors[dbType]
defer advisorMu.RUnlock()
diff --git a/plugin/advisor/fake/fake_advisor.go b/plugin/advisor/fake/fake_advisor.go
index 8d65536f32..9a57a73e98 100644
--- a/plugin/advisor/fake/fake_advisor.go
+++ b/plugin/advisor/fake/fake_advisor.go
@@ -21,7 +21,7 @@ type Advisor struct {
}
// Check is a fake advisor check reporting 1 advice for each severity.
-func (adv *Advisor) Check(ctx advisor.AdvisorContext, statement string) ([]advisor.Advice, error) {
+func (adv *Advisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
return []advisor.Advice{
{
Status: advisor.Success,
diff --git a/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go b/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
index c1259ba9de..4dd6332754 100644
--- a/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
+++ b/plugin/advisor/mysql/mysql_migration_compatibility_advisor.go
@@ -24,7 +24,7 @@ type CompatibilityAdvisor struct {
}
// Check checks schema backward compatibility.
-func (adv *CompatibilityAdvisor) Check(ctx advisor.AdvisorContext, statement string) ([]advisor.Advice, error) {
+func (adv *CompatibilityAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
p := newParser()
root, _, err := p.Parse(statement, ctx.Charset, ctx.Collation)
diff --git a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
index f4c56506ac..a2a5d8a97d 100644
--- a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
+++ b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
@@ -19,7 +19,7 @@ type test struct {
func runTests(t *testing.T, tests []test) {
adv := CompatibilityAdvisor{}
logger, _ := zap.NewDevelopmentConfig().Build()
- ctx := advisor.AdvisorContext{
+ ctx := advisor.Context{
Logger: logger,
Charset: "",
Collation: "",
diff --git a/plugin/advisor/mysql/mysql_syntax_advisor.go b/plugin/advisor/mysql/mysql_syntax_advisor.go
index 4be962124f..1c401b5c6d 100644
--- a/plugin/advisor/mysql/mysql_syntax_advisor.go
+++ b/plugin/advisor/mysql/mysql_syntax_advisor.go
@@ -20,7 +20,7 @@ type SyntaxAdvisor struct {
}
// Check parses the given statement and checks for warnings and errors.
-func (adv *SyntaxAdvisor) Check(ctx advisor.AdvisorContext, statement string) ([]advisor.Advice, error) {
+func (adv *SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
p := newParser()
_, warns, err := p.Parse(statement, ctx.Charset, ctx.Collation)
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index 5ddfcb7d93..fae54183e1 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -205,7 +205,7 @@ func (e MigrationStatus) String() string {
// MigrationInfoPayload is the API message for migration info payload.
type MigrationInfoPayload struct {
- VCSPushEvent *vcs.VCSPushEvent `json:"pushEvent,omitempty"`
+ VCSPushEvent *vcs.PushEvent `json:"pushEvent,omitempty"`
}
// MigrationInfo is the API message for migration info.
diff --git a/plugin/vcs/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.go
index 7451fd3fe5..22cd47ab76 100644
--- a/plugin/vcs/gitlab/gitlab.go
+++ b/plugin/vcs/gitlab/gitlab.go
@@ -134,10 +134,12 @@ func newProvider(config vcs.ProviderConfig) vcs.Provider {
}
}
+// APIURL returns the API URL path of a GitLab instance.
func (provider *Provider) APIURL(instanceURL string) string {
return fmt.Sprintf("%s/%s", instanceURL, apiPath)
}
+// TryLogin will try to login GitLab.
func (provider *Provider) TryLogin(ctx context.Context, oauthCtx common.OauthContext, instanceURL string) (*vcs.UserInfo, error) {
code, body, err := httpGet(
instanceURL,
@@ -171,6 +173,7 @@ func (provider *Provider) TryLogin(ctx context.Context, oauthCtx common.OauthCon
return UserInfo, err
}
+// CreateFile creates a file.
func (provider *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, fileCommitCreate vcs.FileCommitCreate) error {
body, err := json.Marshal(FileCommit{
Branch: fileCommitCreate.Branch,
@@ -207,6 +210,7 @@ func (provider *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthC
return nil
}
+// OverwriteFile overwrite the content of a file.
func (provider *Provider) OverwriteFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, fileCommitCreate vcs.FileCommitCreate) error {
body, err := json.Marshal(FileCommit{
Branch: fileCommitCreate.Branch,
@@ -244,6 +248,7 @@ func (provider *Provider) OverwriteFile(ctx context.Context, oauthCtx common.Oau
return nil
}
+// ReadFileMeta reads the content of a file.
func (provider *Provider) ReadFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, commitID string) (string, error) {
code, body, err := httpGet(
instanceURL,
@@ -274,6 +279,7 @@ func (provider *Provider) ReadFile(ctx context.Context, oauthCtx common.OauthCon
return body, nil
}
+// ReadFileMeta reads the metadata of a file.
func (provider *Provider) ReadFileMeta(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, branch string) (*vcs.FileMeta, error) {
code, body, err := httpGet(
instanceURL,
@@ -311,6 +317,7 @@ func (provider *Provider) ReadFileMeta(ctx context.Context, oauthCtx common.Oaut
}, nil
}
+// CreateWebhook creates a webhook in a GitLab project.
func (provider *Provider) CreateWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, payload []byte) (string, error) {
resourcePath := fmt.Sprintf("projects/%s/hooks", repositoryID)
code, body, err := httpPost(
@@ -351,8 +358,9 @@ func (provider *Provider) CreateWebhook(ctx context.Context, oauthCtx common.Oau
return strconv.Itoa(webhookInfo.ID), nil
}
-func (provider *Provider) PatchWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookId string, payload []byte) error {
- resourcePath := fmt.Sprintf("projects/%s/hooks/%s", repositoryID, webhookId)
+// PatchWebhook patches a webhook in a GitLab project.
+func (provider *Provider) PatchWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string, payload []byte) error {
+ resourcePath := fmt.Sprintf("projects/%s/hooks/%s", repositoryID, webhookID)
code, _, err := httpPut(
instanceURL,
resourcePath,
@@ -366,17 +374,18 @@ func (provider *Provider) PatchWebhook(ctx context.Context, oauthCtx common.Oaut
oauthCtx.Refresher,
)
if err != nil {
- return fmt.Errorf("failed to patch webhook ID %s for repository %s from GitLab instance %s: %w", webhookId, repositoryID, instanceURL, err)
+ return fmt.Errorf("failed to patch webhook ID %s for repository %s from GitLab instance %s: %w", webhookID, repositoryID, instanceURL, err)
}
if code >= 300 {
- return fmt.Errorf("failed to patch webhook ID %s for repository %s from GitLab instance %s, status code: %d", webhookId, repositoryID, instanceURL, code)
+ return fmt.Errorf("failed to patch webhook ID %s for repository %s from GitLab instance %s, status code: %d", webhookID, repositoryID, instanceURL, code)
}
return nil
}
-func (provider *Provider) DeleteWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookId string) error {
- resourcePath := fmt.Sprintf("projects/%s/hooks/%s", repositoryID, webhookId)
+// DeleteWebhook deletes a webhook in a GitLab project.
+func (provider *Provider) DeleteWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string) error {
+ resourcePath := fmt.Sprintf("projects/%s/hooks/%s", repositoryID, webhookID)
code, _, err := httpDelete(
instanceURL,
resourcePath,
@@ -389,11 +398,11 @@ func (provider *Provider) DeleteWebhook(ctx context.Context, oauthCtx common.Oau
oauthCtx.Refresher,
)
if err != nil {
- return fmt.Errorf("failed to delete webhook ID %s for repository %s from GitLab instance %s: %w", webhookId, repositoryID, instanceURL, err)
+ return fmt.Errorf("failed to delete webhook ID %s for repository %s from GitLab instance %s: %w", webhookID, repositoryID, instanceURL, err)
}
if code >= 300 {
- return fmt.Errorf("failed to delete webhook ID %s for repository %s from GitLab instance %s, status code: %d", webhookId, repositoryID, instanceURL, code)
+ return fmt.Errorf("failed to delete webhook ID %s for repository %s from GitLab instance %s, status code: %d", webhookID, repositoryID, instanceURL, code)
}
return nil
}
diff --git a/plugin/vcs/vcs.go b/plugin/vcs/vcs.go
index da8f425d00..b701fcf84b 100644
--- a/plugin/vcs/vcs.go
+++ b/plugin/vcs/vcs.go
@@ -28,8 +28,8 @@ func (e Type) String() string {
// So we annotate with json tag using camelCase naming which is consistent with normal
// json naming convention
-// VCSFileCommit is the API message for a VCS file commit.
-type VCSFileCommit struct {
+// FileCommit is the API message for a VCS file commit.
+type FileCommit struct {
ID string `json:"id"`
Title string `json:"title"`
Message string `json:"message"`
@@ -47,21 +47,21 @@ type FileCommitCreate struct {
LastCommitID string
}
-// FileMata records the file metadata.
+// FileMeta records the file metadata.
type FileMeta struct {
LastCommitID string
}
-// VCSPushEvent is the API message for a VCS push event.
-type VCSPushEvent struct {
- VCSType Type `json:"vcsType"`
- BaseDirectory string `json:"baseDir"`
- Ref string `json:"ref"`
- RepositoryID string `json:"repositoryId"`
- RepositoryURL string `json:"repositoryUrl"`
- RepositoryFullPath string `json:"repositoryFullPath"`
- AuthorName string `json:"authorName"`
- FileCommit VCSFileCommit `json:"fileCommit"`
+// PushEvent is the API message for a VCS push event.
+type PushEvent struct {
+ VCSType Type `json:"vcsType"`
+ BaseDirectory string `json:"baseDir"`
+ Ref string `json:"ref"`
+ RepositoryID string `json:"repositoryId"`
+ RepositoryURL string `json:"repositoryUrl"`
+ RepositoryFullPath string `json:"repositoryFullPath"`
+ AuthorName string `json:"authorName"`
+ FileCommit FileCommit `json:"fileCommit"`
}
type UserState string
@@ -122,9 +122,9 @@ type Provider interface {
// Patches a webhook.
//
// The payload stores the patched field(s).
- PatchWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookId string, payload []byte) error
+ PatchWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string, payload []byte) error
// Deletes a webhook.
- DeleteWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookId string) error
+ DeleteWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string) error
}
var (
diff --git a/server/issue.go b/server/issue.go
index d05d848a11..10eb62b064 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -938,7 +938,7 @@ func (s *Server) createPipelineFromIssue(ctx context.Context, issueCreate *api.I
return createdPipeline, nil
}
-func getUpdateTask(database *api.Database, migrationType db.MigrationType, vcsPushEvent *vcs.VCSPushEvent, d *api.UpdateSchemaDetail, taskStatus api.TaskStatus) (*api.TaskCreate, error) {
+func getUpdateTask(database *api.Database, migrationType db.MigrationType, vcsPushEvent *vcs.PushEvent, d *api.UpdateSchemaDetail, taskStatus api.TaskStatus) (*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/server_embed_dev.go b/server/server_embed_dev.go
index c198a227b9..90d3faae1c 100644
--- a/server/server_embed_dev.go
+++ b/server/server_embed_dev.go
@@ -1,3 +1,4 @@
+//go:build !release
// +build !release
package server
diff --git a/server/sheet.go b/server/sheet.go
index 44b9a5699e..dcf92e9955 100644
--- a/server/sheet.go
+++ b/server/sheet.go
@@ -99,7 +99,7 @@ func (s *Server) registerSheetRoutes(g *echo.Group) {
}
sheetFind := &api.SheetFind{
- ID: &id,
+ ID: &id,
}
sheet, err := s.SheetService.FindSheet(ctx, sheetFind)
diff --git a/server/subscription.go b/server/subscription.go
index 24b7eb339c..8ede27bfb2 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -43,14 +43,14 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
// loadLicense will load current subscription by license.
// Return subscription with free plan if no license found.
-func (server *Server) loadSubscription() *enterpriseAPI.Subscription {
+func (s *Server) loadSubscription() *enterpriseAPI.Subscription {
subscription := &enterpriseAPI.Subscription{
Plan: api.FREE,
// -1 means not expire, just for free plan
ExpiresTs: -1,
InstanceCount: 5,
}
- license, _ := server.loadLicense()
+ license, _ := s.loadLicense()
if license != nil {
subscription = &enterpriseAPI.Subscription{
Plan: license.Plan,
@@ -63,18 +63,18 @@ func (server *Server) loadSubscription() *enterpriseAPI.Subscription {
}
// loadLicense will get and parse valid license from file.
-func (server *Server) loadLicense() (*enterpriseAPI.License, error) {
- license, err := server.LicenseService.LoadLicense()
+func (s *Server) loadLicense() (*enterpriseAPI.License, error) {
+ license, err := s.LicenseService.LoadLicense()
if err != nil {
if common.ErrorCode(err) == common.NotFound {
- server.l.Debug("Failed to find license", zap.String("error", err.Error()))
+ s.l.Debug("Failed to find license", zap.String("error", err.Error()))
} else {
- server.l.Warn("Failed to load valid license", zap.String("error", err.Error()))
+ s.l.Warn("Failed to load valid license", zap.String("error", err.Error()))
}
return nil, err
}
- server.l.Info(
+ s.l.Info(
"Load valid license",
zap.String("plan", license.Plan.String()),
zap.Time("expiresAt", time.Unix(license.ExpiresTs, 0)),
diff --git a/server/task_check_executor_statement_advisor.go b/server/task_check_executor_statement_advisor.go
index c54edfd373..d8bc4335a1 100644
--- a/server/task_check_executor_statement_advisor.go
+++ b/server/task_check_executor_statement_advisor.go
@@ -30,7 +30,7 @@ func (exec *TaskCheckStatementAdvisorExecutor) Run(ctx context.Context, server *
return []api.TaskCheckResult{}, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
}
- var advisorType advisor.AdvisorType
+ var advisorType advisor.Type
switch taskCheckRun.Type {
case api.TaskCheckDatabaseStatementFakeAdvise:
advisorType = advisor.Fake
@@ -46,7 +46,7 @@ func (exec *TaskCheckStatementAdvisorExecutor) Run(ctx context.Context, server *
adviceList, err := advisor.Check(
payload.DbType,
advisorType,
- advisor.AdvisorContext{
+ advisor.Context{
Logger: exec.l,
Charset: payload.Charset,
Collation: payload.Collation,
diff --git a/server/task_executor.go b/server/task_executor.go
index 11681d5370..58ef378e23 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -34,7 +34,7 @@ func defaultMigrationVersionFromTaskID(taskID int) string {
return strings.Join([]string{time.Now().Format("20060102150405"), strconv.Itoa(taskID)}, ".")
}
-func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.Task, migrationType db.MigrationType, statement string, vcsPushEvent *vcs.VCSPushEvent) (terminated bool, result *api.TaskRunResultPayload, err error) {
+func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.Task, migrationType db.MigrationType, statement string, vcsPushEvent *vcs.PushEvent) (terminated bool, result *api.TaskRunResultPayload, err error) {
if task.Database == nil {
msg := "missing database when updating schema"
if migrationType == db.Data {
@@ -275,7 +275,7 @@ func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.
// 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 *vcs.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.PushEvent, mi *db.MigrationInfo, branch string, latestSchemaFile string, schema string, bytebaseURL string) (string, error) {
schemaFileMeta, err := vcs.Get(vcs.GitLabSelfHost, vcs.ProviderConfig{Logger: server.l}).ReadFileMeta(
ctx,
common.OauthContext{
diff --git a/server/task_executor_data_update.go b/server/task_executor_data_update.go
index 6d00a5a712..2df1a89257 100644
--- a/server/task_executor_data_update.go
+++ b/server/task_executor_data_update.go
@@ -17,7 +17,7 @@ func NewDataUpdateTaskExecutor(logger *zap.Logger) TaskExecutor {
}
}
-// NewDataUpdateTaskExecutor is the data update (DML) task executor.
+// DataUpdateTaskExecutor is the data update (DML) task executor.
type DataUpdateTaskExecutor struct {
l *zap.Logger
}
diff --git a/server/webhook.go b/server/webhook.go
index ce811287b4..deedf4b0cd 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -90,7 +90,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
continue
}
- vcsPushEvent := vcs.VCSPushEvent{
+ vcsPushEvent := vcs.PushEvent{
VCSType: repository.VCS.Type,
BaseDirectory: repository.BaseDirectory,
Ref: pushEvent.Ref,
@@ -98,7 +98,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
RepositoryURL: pushEvent.Project.WebURL,
RepositoryFullPath: pushEvent.Project.FullPath,
AuthorName: pushEvent.AuthorName,
- FileCommit: vcs.VCSFileCommit{
+ FileCommit: vcs.FileCommit{
ID: commit.ID,
Title: commit.Title,
Message: commit.Message,
@@ -226,7 +226,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
})
}
-func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.VCSPushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {
+func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {
// Find matching database list
databaseFind := &api.DatabaseFind{
ProjectID: &repository.ProjectID,
@@ -301,7 +301,7 @@ func (s *Server) createSchemaUpdateIssue(ctx context.Context, repository *api.Re
return string(createContext), nil
}
-func (s *Server) createTenantSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.VCSPushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {
+func (s *Server) createTenantSchemaUpdateIssue(ctx context.Context, repository *api.Repository, mi *db.MigrationInfo, vcsPushEvent vcs.PushEvent, commit gitlab.WebhookCommit, added string, statement string) (string, error) {
// We don't take environment for tenant mode project because the databases needing schema update are determined by database name and deployment configuration.
if mi.Environment != "" {
return "", fmt.Errorf("environment isn't accepted in schema update for tenant mode project")
diff --git a/store/instance.go b/store/instance.go
index aacb7636df..9ef33b5745 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -108,6 +108,7 @@ func (s *InstanceService) FindInstanceList(ctx context.Context, find *api.Instan
return list, nil
}
+// CountInstance counts the number of instances.
func (s *InstanceService) CountInstance(ctx context.Context, find *api.InstanceFind) (int, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {