mirror of
https://github.com/vbatts/git-validation.git
synced 2024-11-22 08:05:39 +00:00
*.go: linting and adding lint to the checks done
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
6f5b21b58e
commit
21d1635d10
5 changed files with 51 additions and 6 deletions
33
.github/workflows/lint.yml
vendored
Normal file
33
.github/workflows/lint.yml
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches_ignore: []
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: ['1.20']
|
||||||
|
|
||||||
|
name: Documentation and Linting
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: go/src/github.com/vbatts/git-validation
|
||||||
|
|
||||||
|
# commit for v1 release
|
||||||
|
- uses: actions/setup-go@0caeaed6fd66a828038c2da3c0f662a42862658f
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
- name: lint
|
||||||
|
env:
|
||||||
|
GOPATH: /home/runner/work/git-validation/git-validation/go
|
||||||
|
run: |
|
||||||
|
set -x
|
||||||
|
export PATH=$GOPATH/bin:$PATH
|
||||||
|
cd go/src/github.com/vbatts/git-validation
|
||||||
|
go run mage.go -v lint
|
|
@ -107,7 +107,7 @@ using the `GIT_CHECK_EXCLUDE` environment variable. Multiple paths should be sep
|
||||||
When making a change, verify it with:
|
When making a change, verify it with:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run mage.go vet build test
|
go run mage.go lint vet build test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Rules
|
## Rules
|
||||||
|
|
4
main.go
4
main.go
|
@ -27,6 +27,10 @@ var (
|
||||||
flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
|
flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
logrus.SetOutput(os.Stderr)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,6 @@ func SanitizeFilters(filtStr string) (filters []string) {
|
||||||
//
|
//
|
||||||
// Some `includes` rules have values assigned to them.
|
// Some `includes` rules have values assigned to them.
|
||||||
// i.e. -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"
|
// i.e. -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"
|
||||||
//
|
|
||||||
func FilterRules(rules []Rule, includes []string) []Rule {
|
func FilterRules(rules []Rule, includes []string) []Rule {
|
||||||
ret := []Rule{}
|
ret := []Rule{}
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ func FilterRules(rules []Rule, includes []string) []Rule {
|
||||||
for i := range includes {
|
for i := range includes {
|
||||||
if strings.Contains(includes[i], "=") {
|
if strings.Contains(includes[i], "=") {
|
||||||
chunks := strings.SplitN(includes[i], "=", 2)
|
chunks := strings.SplitN(includes[i], "=", 2)
|
||||||
if strings.ToLower(r.Name) == strings.ToLower(chunks[0]) {
|
if strings.EqualFold(r.Name, chunks[0]) {
|
||||||
// for these rules, the Name won't be unique per se. There may be
|
// for these rules, the Name won't be unique per se. There may be
|
||||||
// multiple "regexp=" with different values. We'll need to set the
|
// multiple "regexp=" with different values. We'll need to set the
|
||||||
// .Value = chunk[1] and ensure r is dup'ed so they don't clobber
|
// .Value = chunk[1] and ensure r is dup'ed so they don't clobber
|
||||||
|
@ -93,7 +92,7 @@ func FilterRules(rules []Rule, includes []string) []Rule {
|
||||||
ret = append(ret, newR)
|
ret = append(ret, newR)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if strings.ToLower(r.Name) == strings.ToLower(includes[i]) {
|
if strings.EqualFold(r.Name, includes[i]) {
|
||||||
ret = append(ret, r)
|
ret = append(ret, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/vbatts/git-validation/git"
|
"github.com/vbatts/git-validation/git"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +30,11 @@ func NewRunner(root string, rules []Rule, commitrange string, verbose bool) (*Ru
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer os.Chdir(cwd)
|
defer func() {
|
||||||
|
if err := os.Chdir(cwd); err != nil {
|
||||||
|
logrus.Warnf("changing working directory to %q failed: %s", cwd, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := os.Chdir(newroot); err != nil {
|
if err := os.Chdir(newroot); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -56,7 +61,11 @@ func (r *Runner) Run() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Chdir(cwd)
|
defer func() {
|
||||||
|
if err := os.Chdir(cwd); err != nil {
|
||||||
|
logrus.Warnf("changing working directory to %q failed: %s", cwd, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := os.Chdir(r.Root); err != nil {
|
if err := os.Chdir(r.Root); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue