Skip to content

Commit

Permalink
Move known scope definitions to talismanrc
Browse files Browse the repository at this point in the history
  • Loading branch information
svishwanath-tw committed Jun 24, 2021
1 parent 916b293 commit a719399
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
11 changes: 1 addition & 10 deletions cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func NewRunner(additions []gitrepo.Addition) *runner {
//Run will validate the commit range for errors and return either COMPLETED_SUCCESSFULLY or COMPLETED_WITH_ERRORS
func (r *runner) Run(tRC *talismanrc.TalismanRC, promptContext prompt.PromptContext) int {
setCustomSeverities(tRC)
scopeMap := getScopeConfig()
additionsToScan := tRC.IgnoreAdditionsByScope(r.additions, scopeMap)
additionsToScan := tRC.FilterAdditions(r.additions)
detector.DefaultChain(tRC).Test(additionsToScan, tRC, r.results)
r.printReport(promptContext)
exitStatus := r.exitStatus()
Expand All @@ -50,14 +49,6 @@ func setCustomSeverities(tRC *talismanrc.TalismanRC) {
}
}

func getScopeConfig() map[string][]string {
scopeConfig := map[string][]string{
"node": {"yarn.lock", "package-lock.json", "node_modules/"},
"go": {"makefile", "go.mod", "go.sum", "Gopkg.toml", "Gopkg.lock", "glide.yaml", "glide.lock", "vendor/"},
}
return scopeConfig
}

func (r *runner) printReport(promptContext prompt.PromptContext) {
if r.results.HasWarnings() {
fmt.Println(r.results.ReportWarnings())
Expand Down
6 changes: 6 additions & 0 deletions talismanrc/scopes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package talismanrc

var knownScopes = map[string][]string{
"node": {"yarn.lock", "package-lock.json", "node_modules/"},
"go": {"makefile", "go.mod", "go.sum", "Gopkg.toml", "Gopkg.lock", "glide.yaml", "glide.lock", "vendor/"},
}
6 changes: 3 additions & 3 deletions talismanrc/talismanrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (tRC *TalismanRC) Accept(addition gitrepo.Addition, detectorName string) bo
return !tRC.Deny(addition, detectorName)
}

func (tRC *TalismanRC) IgnoreAdditionsByScope(additions []gitrepo.Addition, scopeMap map[string][]string) []gitrepo.Addition {
func (tRC *TalismanRC) FilterAdditions(additions []gitrepo.Addition) []gitrepo.Addition {
var applicableScopeFileNames []string
if tRC.ScopeConfig != nil {
for _, scope := range tRC.ScopeConfig {
if len(scopeMap[scope.ScopeName]) > 0 {
applicableScopeFileNames = append(applicableScopeFileNames, scopeMap[scope.ScopeName]...)
if len(knownScopes[scope.ScopeName]) > 0 {
applicableScopeFileNames = append(applicableScopeFileNames, knownScopes[scope.ScopeName]...)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions talismanrc/talismanrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestIgnoreAdditionsByScope(t *testing.T) {
javaIgnores := []string{"java.lock"}
goIgnores := []string{"go.lock", "Gopkg.lock", "vendors/"}
scopesMap := map[string][]string{"node": nodeIgnores, "java": javaIgnores, "go": goIgnores}

filteredAdditions := talismanRCConfig.IgnoreAdditionsByScope(additions, scopesMap)
knownScopes = scopesMap
filteredAdditions := talismanRCConfig.FilterAdditions(additions)

assert.NotContains(t, filteredAdditions, file1)
assert.NotContains(t, filteredAdditions, file2)
Expand Down

0 comments on commit a719399

Please sign in to comment.