mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-24 11:31:36 +01:00
eb37f14923
tagged version v0.2.0 make vendor Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/164 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: techknowlogick <techknowlogick@gitea.io>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package checks
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
)
|
|
|
|
var Migrations = &analysis.Analyzer{
|
|
Name: "migrations",
|
|
Doc: "check migrations for black-listed packages.",
|
|
Run: checkMigrations,
|
|
}
|
|
|
|
var migrationBlacklist = []string{
|
|
"code.gitea.io/gitea/models",
|
|
"code.gitea.io/gitea/modules/structs",
|
|
}
|
|
|
|
func checkMigrations(pass *analysis.Pass) (interface{}, error) {
|
|
if !strings.EqualFold(pass.Pkg.Path(), "code.gitea.io/gitea/models/migrations") {
|
|
return nil, nil
|
|
}
|
|
|
|
if _, err := exec.LookPath("go"); err != nil {
|
|
return nil, errors.New("go was not found in the PATH")
|
|
}
|
|
|
|
depsCmd := exec.Command("go", "list", "-f", `{{join .Deps "\n"}}`, "code.gitea.io/gitea/models/migrations")
|
|
depsOut, err := depsCmd.Output()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
deps := strings.Split(string(depsOut), "\n")
|
|
for _, dep := range deps {
|
|
if stringInSlice(dep, migrationBlacklist) {
|
|
pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot depend on the following packages: %s", migrationBlacklist)
|
|
return nil, nil
|
|
}
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func stringInSlice(needle string, haystack []string) bool {
|
|
for _, h := range haystack {
|
|
if strings.EqualFold(needle, h) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|