Skip to content

Commit

Permalink
feat: add composer support
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Feb 2, 2023
1 parent 2511482 commit 9948d63
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Philipp Heuer

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.
41 changes: 41 additions & 0 deletions analyzer/composer/composer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package composer

import (
"path/filepath"

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

type Analyzer struct{}

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

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

for _, file := range ctx.FilesByExtension["json"] {
filename := filepath.Base(file)
if filename == "composer.json" {
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}},
BuildSystem: analyzerapi.BuildSystemComposer,
BuildSystemSyntax: analyzerapi.BuildSystemSyntaxDefault,
Language: nil,
Dependencies: nil,
Submodules: nil,
Files: ctx.Files,
FilesByExtension: ctx.FilesByExtension,
}
analyzerapi.AddModuleToResult(&result, &module)
}
}

return result
}
27 changes: 27 additions & 0 deletions analyzer/composer/composer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package composer

import (
"testing"

"github.com/cidverse/repoanalyzer/util"
"github.com/rs/zerolog/log"

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

func TestAnalyzer_AnalyzeComposer(t *testing.T) {
ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "composer"))

analyzer := Analyzer{}
result := analyzer.Analyze(ctx)

// module
assert.Len(t, result, 1)
assert.Equal(t, "composer", result[0].Name)
assert.Equal(t, "composer", string(result[0].BuildSystem))
assert.Equal(t, "default", string(result[0].BuildSystemSyntax))

// print result
log.Info().Interface("result", result).Msg("output")
}
1 change: 1 addition & 0 deletions analyzerapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const (
BuildSystemSetupPy ProjectBuildSystem = "setup.py"
BuildSystemPoetry ProjectBuildSystem = "poetry"
BuildSystemMkdocs ProjectBuildSystem = "mkdocs"
BuildSystemComposer ProjectBuildSystem = "composer"
)

type ProjectBuildSystemSyntax string
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk=
github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw=
github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
golang.org/x/exp v0.0.0-20220927162542-c76eaa363f9d h1:3wgmvnqHUJ8SxiNWwea5NCzTwAVfhTtuV+0ClVFlClc=
Expand Down
5 changes: 5 additions & 0 deletions testdata/composer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"monolog/monolog": "2.0.0"
}
}

0 comments on commit 9948d63

Please sign in to comment.