Skip to content

Commit

Permalink
feat: add renovate config finder
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Nov 15, 2024
1 parent 17a79b1 commit 804a8bc
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 6 deletions.
2 changes: 2 additions & 0 deletions analyzer/scanners.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cidverse/repoanalyzer/modules/node"
"github.com/cidverse/repoanalyzer/modules/python"
"github.com/cidverse/repoanalyzer/modules/quartz"
"github.com/cidverse/repoanalyzer/modules/renovate"
)

// AllScanners contains all available scanners
Expand All @@ -40,4 +41,5 @@ var AllScanners = []analyzerapi.Scanner{
node.Analyzer{},
python.Analyzer{},
quartz.Analyzer{},
renovate.Analyzer{},
}
1 change: 1 addition & 0 deletions analyzerapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type SpecificationType string
const (
SpecificationTypeOpenAPI SpecificationType = "openapi"
SpecificationTypeAsyncAPI SpecificationType = "asyncapi"
SpecificationTypeRenovate SpecificationType = "renovate"
)

// ProjectDependency contains dependency information
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/mod v0.22.0
)

require (
github.com/charlievieth/fastwalk v1.0.8 // indirect
github.com/charlievieth/fastwalk v1.0.9 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/charlievieth/fastwalk v1.0.8 h1:uaoH6cAKSk73aK7aKXqs0+bL+J3Txzd3NGH8tRXgHko=
github.com/charlievieth/fastwalk v1.0.8/go.mod h1:yGy1zbxog41ZVMcKA/i8ojXLFsuayX5VvwhQVoj9PBI=
github.com/charlievieth/fastwalk v1.0.9 h1:Odb92AfoReO3oFBfDGT5J+nwgzQPF/gWAw6E6/lkor0=
github.com/charlievieth/fastwalk v1.0.9/go.mod h1:yGy1zbxog41ZVMcKA/i8ojXLFsuayX5VvwhQVoj9PBI=
github.com/cidverse/cidverseutils/filesystem v0.1.1 h1:xKGk+QhoywNKUp0artHkRPPOl+C3aa6wujkHhjTB6sI=
github.com/cidverse/cidverseutils/filesystem v0.1.1/go.mod h1:cpAd2RNrNiBRtDJS8S/VRiTD88kU9pxV1i5aA+AqUso=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -19,8 +19,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
54 changes: 54 additions & 0 deletions modules/renovate/renovate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package renovate

import (
"path/filepath"
"strings"

"github.com/cidverse/repoanalyzer/analyzerapi"
"github.com/gosimple/slug"
)

type Analyzer struct{}

func (a Analyzer) GetName() string {
return "renovate"
}

func (a Analyzer) Scan(ctx analyzerapi.AnalyzerContext) []*analyzerapi.ProjectModule {
var result []*analyzerapi.ProjectModule

renovateFiles := []string{
"renovate.json",
"renovate.json5",
".github/renovate.json",
".github/renovate.json5",
".gitlab/renovate.json",
".gitlab/renovate.json5",
".renovaterc",
".renovaterc.json",
".renovaterc.json5",
}
for _, file := range ctx.Files {
for _, renovateFile := range renovateFiles {
if strings.EqualFold(filepath.Base(file), renovateFile) || strings.Contains(file, renovateFile) {
module := analyzerapi.ProjectModule{
RootDirectory: ctx.ProjectDir,
Directory: filepath.Dir(file),
Name: filepath.Base(filepath.Dir(file)),
Slug: slug.Make(filepath.Base(filepath.Dir(file))),
Discovery: []analyzerapi.ProjectModuleDiscovery{{File: file}},
Type: analyzerapi.ModuleTypeSpec,
SpecificationType: analyzerapi.SpecificationTypeRenovate,
Language: nil,
Dependencies: nil,
Submodules: nil,
Files: ctx.Files,
FilesByExtension: ctx.FilesByExtension,
}
analyzerapi.AddModuleToResult(&result, &module)
}
}
}

return result
}
25 changes: 25 additions & 0 deletions modules/renovate/renovate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package renovate

import (
"testing"

"github.com/cidverse/repoanalyzer/analyzerapi"
"github.com/stretchr/testify/assert"
)

func TestAnalyzer_AnalyzeRenovate(t *testing.T) {
ctx := analyzerapi.GetAnalyzerContext(analyzerapi.GetTestDataDir(t, "renovate"))
analyzer := Analyzer{}
result := analyzer.Scan(ctx)

// module
assert.Len(t, result, 1)
assert.Equal(t, "renovate", result[0].Name)
assert.Equal(t, analyzerapi.ModuleTypeSpec, result[0].Type)
assert.Equal(t, analyzerapi.SpecificationTypeRenovate, result[0].SpecificationType)

// print result
for i, item := range result {
t.Logf("result[%d]: %+v", i, *item)
}
}
13 changes: 13 additions & 0 deletions testdata/renovate/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>cidverse/renovate-config:default",
"github>cidverse/renovate-config:assignee"
],
"baseBranches": ["main"],
"ignorePaths": [
".github/workflows/cid**",
"**/testdata/**",
"**/examples/**"
]
}

0 comments on commit 804a8bc

Please sign in to comment.