You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- added file_name rules to support both matching file content and file names
- code refactoring - implemented ContentRule and FileNameRule. Better code arrangement.
Copy file name to clipboardExpand all lines: README.md
+33-14Lines changed: 33 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,19 +79,31 @@ This class holds all the added rules for fast reuse.
79
79
80
80
81
81
```python
82
-
defadd_rule(
82
+
defadd_content_rule(
83
83
self,
84
84
name: str,
85
-
match_pattern: str,
86
-
match_whitelist_patterns: typing.List[str],
87
-
match_blacklist_patterns: typing.List[str],
85
+
regex_pattern: str,
86
+
whitelist_regex_patterns: typing.List[str],
87
+
blacklist_regex_patterns: typing.List[str],
88
88
) ->None
89
89
```
90
-
The `add_rule` function adds a new rule to an internal list of rules that could be reused multiple times against different repositories. The same name can be used multiple times and would lead to results which can hold the same name.
90
+
The `add_content_rule` function adds a new rule to an internal list of rules that could be reused multiple times against different repositories. The same name can be used multiple times and would lead to results which can hold the same name. Content rule means that the regex pattern would be tested against the content of the files.
91
91
-`name`- The name of the rule so it can be identified.
92
-
-`match_pattern`- The regex pattern (RE2 syntax) to match against the content of the commited files.
93
-
-`match_whitelist_patterns`- A list of regex patterns (RE2 syntax) to match against the content of the committed file to filterin results. Only one of the patterns should be matched to pass through the result. There is an OR relation between the patterns.
94
-
-`match_blacklist_patterns`- A list of regex patterns (RE2 syntax) to match against the content of the committed file to filter out results. Only one of the patterns should be matched to omit the result. There is an OR relation between the patterns.
92
+
-`regex_pattern`- The regex pattern (RE2 syntax) to match against the content of the commited files.
93
+
-`whitelist_regex_patterns`- A list of regex patterns (RE2 syntax) to match against the content of the committed file to filterin results. Only one of the patterns should be matched to pass through the result. There is an OR relation between the patterns.
94
+
-`blacklist_regex_patterns`- A list of regex patterns (RE2 syntax) to match against the content of the committed file to filter out results. Only one of the patterns should be matched to omit the result. There is an OR relation between the patterns.
95
+
96
+
97
+
```python
98
+
def add_file_name_rule(
99
+
self,
100
+
name: str,
101
+
regex_pattern: str,
102
+
) ->None
103
+
```
104
+
The `add_file_name_rule` function adds a new rule to an internal list of rules that could be reused multiple times against different repositories. The same name can be used multiple times and would lead to results which can hold the same name. File name rule means that the regex pattern would be tested against the file names.
105
+
-`name`- The name of the rule so it can be identified.
106
+
-`regex_pattern`- The regex pattern (RE2 syntax) to match against the file names of the commited files.
95
107
96
108
97
109
```python
@@ -119,7 +131,7 @@ def scan(
119
131
self,
120
132
repository_path: str,
121
133
branch_glob_pattern: '*',
122
-
from_timestamp: int,
134
+
from_timestamp: int=0,
123
135
) -> typing.List[typing.Dict[str, str]]
124
136
```
125
137
The `scan` function is the main function in the library. Calling this function would trigger a new scan that would return a list of matches. The scan function is a multithreaded operation, that would utilize all the available core in the system. The results would not include the file content but only the regex matching group. To retrieve the full file content one should take the `results['oid']`and to call `get_file_content` function.
@@ -162,11 +174,19 @@ import pyrepscan
162
174
grs = pyrepscan.GitRepositoryScanner()
163
175
164
176
# Adds a specific rule, can be called multiple times or none
0 commit comments