@@ -24,6 +24,10 @@ func qualityCheckBuilderUsesExpect(rules map[string]string, bobfile *Bobfile) er
2424
2525func qualityCheckFiles (rules []FileQualityRule ) error {
2626 for _ , rule := range rules {
27+ if ! conditionsPass (rule .Conditions ) { // rule not in use because didn't pass all conditions
28+ continue
29+ }
30+
2731 if err := qualityCheckFile (rule ); err != nil {
2832 return fmt .Errorf ("quality: file %s: %w" , rule .Path , err )
2933 }
@@ -63,3 +67,48 @@ func qualityCheckFile(rule FileQualityRule) error {
6367
6468 return nil
6569}
70+
71+ func conditionsPass (conditions []QualityRuleCondition ) bool {
72+ for _ , condition := range conditions {
73+ conditionPasses := func (matches bool ) bool {
74+ if condition .Enable && ! matches { // condition disqualifies if NOT match
75+ return false
76+ } else if ! condition .Enable && matches { // condition disqualifies if DOES match
77+ return false
78+ }
79+
80+ return true
81+ }
82+
83+ if origin := condition .RepoOrigin ; origin != "" {
84+ // "*foo*" => "foo"
85+ originWildcard := strings .Trim (origin , "*" )
86+ if len (originWildcard ) != len (origin )- 2 { // stupidest way to check it had * at start AND end
87+ panic ("repo_origin needs to be in form '*foobar*'" )
88+ }
89+
90+ originMatches := strings .Contains (githubURL (getGithubRepoRef ()), originWildcard )
91+
92+ if ! conditionPasses (originMatches ) {
93+ return false
94+ }
95+ }
96+ }
97+
98+ return true
99+ }
100+
101+ // lazily read gitHubRepoRefFromGit() just once
102+ func getGithubRepoRef () githubRepoRef {
103+ if githubRepoRefSingleton == nil {
104+ var err error
105+ githubRepoRefSingleton , err = gitHubRepoRefFromGit ()
106+ if err != nil {
107+ panic (err )
108+ }
109+ }
110+
111+ return * githubRepoRefSingleton
112+ }
113+
114+ var githubRepoRefSingleton * githubRepoRef
0 commit comments