aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/code.gitea.io/gitea-vet
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/code.gitea.io/gitea-vet')
-rw-r--r--vendor/code.gitea.io/gitea-vet/.changelog.yml30
-rw-r--r--vendor/code.gitea.io/gitea-vet/.drone.yml45
-rw-r--r--vendor/code.gitea.io/gitea-vet/.gitignore5
-rw-r--r--vendor/code.gitea.io/gitea-vet/.golangci.yml23
-rw-r--r--vendor/code.gitea.io/gitea-vet/CHANGELOG.md11
-rw-r--r--vendor/code.gitea.io/gitea-vet/LICENSE19
-rw-r--r--vendor/code.gitea.io/gitea-vet/Makefile22
-rw-r--r--vendor/code.gitea.io/gitea-vet/README.md11
-rw-r--r--vendor/code.gitea.io/gitea-vet/checks/imports.go46
-rw-r--r--vendor/code.gitea.io/gitea-vet/checks/license.go73
-rw-r--r--vendor/code.gitea.io/gitea-vet/checks/migrations.go77
-rw-r--r--vendor/code.gitea.io/gitea-vet/go.mod5
-rw-r--r--vendor/code.gitea.io/gitea-vet/go.sum20
-rw-r--r--vendor/code.gitea.io/gitea-vet/main.go19
14 files changed, 406 insertions, 0 deletions
diff --git a/vendor/code.gitea.io/gitea-vet/.changelog.yml b/vendor/code.gitea.io/gitea-vet/.changelog.yml
new file mode 100644
index 0000000000..b3e6446b71
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/.changelog.yml
@@ -0,0 +1,30 @@
+# The full repository name
+repo: gitea/gitea-vet
+
+# Service type (gitea or github)
+service: gitea
+
+# Base URL for Gitea instance if using gitea service type (optional)
+base-url: https://gitea.com
+
+# Changelog groups and which labeled PRs to add to each group
+groups:
+ -
+ name: BREAKING
+ labels:
+ - breaking
+ -
+ name: FEATURES
+ labels:
+ - feature
+ -
+ name: BUGFIXES
+ labels:
+ - bug
+ -
+ name: ENHANCEMENTS
+ labels:
+ - enhancement
+
+# regex indicating which labels to skip for the changelog
+skip-labels: skip-changelog|backport\/.+
diff --git a/vendor/code.gitea.io/gitea-vet/.drone.yml b/vendor/code.gitea.io/gitea-vet/.drone.yml
new file mode 100644
index 0000000000..dd0fc13f9d
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/.drone.yml
@@ -0,0 +1,45 @@
+---
+kind: pipeline
+name: compliance
+
+platform:
+ os: linux
+ arch: arm64
+
+trigger:
+ event:
+ - pull_request
+
+steps:
+ - name: check
+ pull: always
+ image: golang:1.14
+ environment:
+ GOPROXY: https://goproxy.cn
+ commands:
+ - make build
+ - make lint
+ - make vet
+
+---
+kind: pipeline
+name: build-master
+
+platform:
+ os: linux
+ arch: amd64
+
+trigger:
+ branch:
+ - master
+ event:
+ - push
+
+steps:
+ - name: build
+ pull: always
+ image: techknowlogick/xgo:latest
+ environment:
+ GOPROXY: https://goproxy.cn
+ commands:
+ - make build \ No newline at end of file
diff --git a/vendor/code.gitea.io/gitea-vet/.gitignore b/vendor/code.gitea.io/gitea-vet/.gitignore
new file mode 100644
index 0000000000..b89cc42a23
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/.gitignore
@@ -0,0 +1,5 @@
+# GoLand
+.idea/
+
+# Binaries
+/gitea-vet* \ No newline at end of file
diff --git a/vendor/code.gitea.io/gitea-vet/.golangci.yml b/vendor/code.gitea.io/gitea-vet/.golangci.yml
new file mode 100644
index 0000000000..704d99a1d3
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/.golangci.yml
@@ -0,0 +1,23 @@
+linters:
+ enable:
+ - deadcode
+ - dogsled
+ - dupl
+ - errcheck
+ - gocognit
+ - goconst
+ - gocritic
+ - gocyclo
+ - gofmt
+ - golint
+ - gosimple
+ - govet
+ - maligned
+ - misspell
+ - prealloc
+ - staticcheck
+ - structcheck
+ - typecheck
+ - unparam
+ - unused
+ - varcheck \ No newline at end of file
diff --git a/vendor/code.gitea.io/gitea-vet/CHANGELOG.md b/vendor/code.gitea.io/gitea-vet/CHANGELOG.md
new file mode 100644
index 0000000000..295456bb6b
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/CHANGELOG.md
@@ -0,0 +1,11 @@
+## [v0.2.1](https://gitea.com/gitea/gitea-vet/releases/tag/v0.2.1) - 2020-08-15
+
+* BUGFIXES
+ * Split migration check to Deps and Imports (#9)
+
+## [0.2.0](https://gitea.com/gitea/gitea-vet/pulls?q=&type=all&state=closed&milestone=1272) - 2020-07-20
+
+* FEATURES
+ * Add migrations check (#5)
+* BUGFIXES
+ * Correct Import Paths (#6)
diff --git a/vendor/code.gitea.io/gitea-vet/LICENSE b/vendor/code.gitea.io/gitea-vet/LICENSE
new file mode 100644
index 0000000000..a39c526bbe
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2020 The Gitea Authors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/vendor/code.gitea.io/gitea-vet/Makefile b/vendor/code.gitea.io/gitea-vet/Makefile
new file mode 100644
index 0000000000..e9c9f4f70c
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/Makefile
@@ -0,0 +1,22 @@
+GO ?= go
+
+.PHONY: build
+build:
+ $(GO) build
+
+.PHONY: fmt
+fmt:
+ $(GO) fmt ./...
+
+.PHONY: vet
+vet: build
+ $(GO) vet ./...
+ $(GO) vet -vettool=gitea-vet ./...
+
+.PHONY: lint
+lint:
+ @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
+ export BINARY="golangci-lint"; \
+ curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin v1.24.0; \
+ fi
+ golangci-lint run --timeout 5m \ No newline at end of file
diff --git a/vendor/code.gitea.io/gitea-vet/README.md b/vendor/code.gitea.io/gitea-vet/README.md
new file mode 100644
index 0000000000..5d3d09742b
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/README.md
@@ -0,0 +1,11 @@
+# gitea-vet
+
+[![Build Status](https://drone.gitea.com/api/badges/gitea/gitea-vet/status.svg)](https://drone.gitea.com/gitea/gitea-vet)
+
+`go vet` tool for Gitea
+
+| Analyzer | Description |
+|------------|-----------------------------------------------------------------------------|
+| Imports | Checks for import sorting. stdlib->code.gitea.io->other |
+| License | Checks file headers for some form of `Copyright...YYYY...Gitea/Gogs` |
+| Migrations | Checks for black-listed packages in `code.gitea.io/gitea/models/migrations` |
diff --git a/vendor/code.gitea.io/gitea-vet/checks/imports.go b/vendor/code.gitea.io/gitea-vet/checks/imports.go
new file mode 100644
index 0000000000..15563c8543
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/checks/imports.go
@@ -0,0 +1,46 @@
+// 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 (
+ "strings"
+
+ "golang.org/x/tools/go/analysis"
+)
+
+var Imports = &analysis.Analyzer{
+ Name: "imports",
+ Doc: "check for import order",
+ Run: runImports,
+}
+
+func runImports(pass *analysis.Pass) (interface{}, error) {
+ for _, file := range pass.Files {
+ level := 0
+ for _, im := range file.Imports {
+ var lvl int
+ val := im.Path.Value
+ switch {
+ case importHasPrefix(val, "code.gitea.io"):
+ lvl = 2
+ case strings.Contains(val, "."):
+ lvl = 3
+ default:
+ lvl = 1
+ }
+
+ if lvl < level {
+ pass.Reportf(file.Pos(), "Imports are sorted wrong")
+ break
+ }
+ level = lvl
+ }
+ }
+ return nil, nil
+}
+
+func importHasPrefix(s, p string) bool {
+ return strings.HasPrefix(s, "\""+p)
+}
diff --git a/vendor/code.gitea.io/gitea-vet/checks/license.go b/vendor/code.gitea.io/gitea-vet/checks/license.go
new file mode 100644
index 0000000000..a3ae04767b
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/checks/license.go
@@ -0,0 +1,73 @@
+// 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 (
+ "regexp"
+ "strings"
+
+ "golang.org/x/tools/go/analysis"
+)
+
+var (
+ header = regexp.MustCompile(`.*Copyright.*\d{4}.*(Gitea|Gogs)`)
+ goGenerate = "//go:generate"
+ buildTag = "// +build"
+)
+
+var License = &analysis.Analyzer{
+ Name: "license",
+ Doc: "check for a copyright header",
+ Run: runLicense,
+}
+
+func runLicense(pass *analysis.Pass) (interface{}, error) {
+ for _, file := range pass.Files {
+ if len(file.Comments) == 0 {
+ pass.Reportf(file.Pos(), "Copyright not found")
+ continue
+ }
+
+ if len(file.Comments[0].List) == 0 {
+ pass.Reportf(file.Pos(), "Copyright not found or wrong")
+ continue
+ }
+
+ commentGroup := 0
+ if strings.HasPrefix(file.Comments[0].List[0].Text, goGenerate) {
+ if len(file.Comments[0].List) > 1 {
+ pass.Reportf(file.Pos(), "Must be an empty line between the go:generate and the Copyright")
+ continue
+ }
+ commentGroup++
+ }
+
+ if strings.HasPrefix(file.Comments[0].List[0].Text, buildTag) {
+ commentGroup++
+ }
+
+ if len(file.Comments) < commentGroup+1 {
+ pass.Reportf(file.Pos(), "Copyright not found")
+ continue
+ }
+
+ if len(file.Comments[commentGroup].List) < 1 {
+ pass.Reportf(file.Pos(), "Copyright not found or wrong")
+ continue
+ }
+
+ var check bool
+ for _, comment := range file.Comments[commentGroup].List {
+ if header.MatchString(comment.Text) {
+ check = true
+ }
+ }
+
+ if !check {
+ pass.Reportf(file.Pos(), "Copyright did not match check")
+ }
+ }
+ return nil, nil
+}
diff --git a/vendor/code.gitea.io/gitea-vet/checks/migrations.go b/vendor/code.gitea.io/gitea-vet/checks/migrations.go
new file mode 100644
index 0000000000..e3fe570f75
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/checks/migrations.go
@@ -0,0 +1,77 @@
+// 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 (
+ migrationDepBlockList = []string{
+ "code.gitea.io/gitea/models",
+ }
+ migrationImpBlockList = []string{
+ "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, migrationDepBlockList) {
+ pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot depend on the following packages: %s", migrationDepBlockList)
+ return nil, nil
+ }
+ }
+
+ impsCmd := exec.Command("go", "list", "-f", `{{join .Imports "\n"}}`, "code.gitea.io/gitea/models/migrations")
+ impsOut, err := impsCmd.Output()
+ if err != nil {
+ return nil, err
+ }
+
+ imps := strings.Split(string(impsOut), "\n")
+ for _, imp := range imps {
+ if stringInSlice(imp, migrationImpBlockList) {
+ pass.Reportf(0, "code.gitea.io/gitea/models/migrations cannot import the following packages: %s", migrationImpBlockList)
+ 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
+}
diff --git a/vendor/code.gitea.io/gitea-vet/go.mod b/vendor/code.gitea.io/gitea-vet/go.mod
new file mode 100644
index 0000000000..ed0987cc61
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/go.mod
@@ -0,0 +1,5 @@
+module code.gitea.io/gitea-vet
+
+go 1.14
+
+require golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224
diff --git a/vendor/code.gitea.io/gitea-vet/go.sum b/vendor/code.gitea.io/gitea-vet/go.sum
new file mode 100644
index 0000000000..5feddd059c
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/go.sum
@@ -0,0 +1,20 @@
+github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
+golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224 h1:azwY/v0y0K4mFHVsg5+UrTgchqALYWpqVo6vL5OmkmI=
+golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/vendor/code.gitea.io/gitea-vet/main.go b/vendor/code.gitea.io/gitea-vet/main.go
new file mode 100644
index 0000000000..4894055086
--- /dev/null
+++ b/vendor/code.gitea.io/gitea-vet/main.go
@@ -0,0 +1,19 @@
+// 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 main
+
+import (
+ "code.gitea.io/gitea-vet/checks"
+
+ "golang.org/x/tools/go/analysis/unitchecker"
+)
+
+func main() {
+ unitchecker.Main(
+ checks.Imports,
+ checks.License,
+ checks.Migrations,
+ )
+}