From 2bc73c5967f64a6bb0923b8b3e5a6662a2a85397 Mon Sep 17 00:00:00 2001 From: Timothy Morey Date: Fri, 17 Sep 2021 17:16:50 -0400 Subject: [PATCH 1/3] try to support a single ignore expression --- action.yml | 3 +++ main.py | 9 +++++++++ tests/test_todo_parser.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/action.yml b/action.yml index c2cd07f..5721d4a 100644 --- a/action.yml +++ b/action.yml @@ -51,3 +51,6 @@ inputs: ORG_PROJECTS: description: "Default organisation projects" required: false + IGNORE: + description: "A regular expression that matches files that should be ignored when searching for TODOs" + required: false diff --git a/main.py b/main.py index d99be2b..341e55b 100644 --- a/main.py +++ b/main.py @@ -348,6 +348,8 @@ class TodoParser(object): if not filename_search: continue curr_file = filename_search.group(0) + if self._should_ignore(curr_file): + continue curr_markers, curr_markdown_language = self._get_file_details(curr_file) if not curr_markers or not curr_markdown_language: print(f'Could not check {curr_file} for TODOs as this language is not yet supported by default.') @@ -604,6 +606,13 @@ class TodoParser(object): projects = list(filter(None, projects.split(','))) return projects + def _should_ignore(self, file): + ignore_pattern = os.getenv('INPUT_IGNORE', None) + if ignore_pattern: + if re.match(ignore_pattern, file): + return True + return False + if __name__ == "__main__": # Create a basic client for communicating with GitHub, automatically initialised with environment variables. diff --git a/tests/test_todo_parser.py b/tests/test_todo_parser.py index 63d8d5e..9a023e8 100644 --- a/tests/test_todo_parser.py +++ b/tests/test_todo_parser.py @@ -1,3 +1,4 @@ +import os import unittest from main import TodoParser @@ -52,3 +53,16 @@ class ClosedIssueTests(unittest.TestCase): def test_ruby_issues(self): self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) + +class IgnorePatternTests(unittest.TestCase): + + def test_single_ignore(self): + os.environ['INPUT_IGNORE'] = '.*\.java' + diff_file = open('tests/test_new.diff', 'r') + self.raw_issues = TodoParser().parse(diff_file) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'yaml'), 2) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'php'), 4) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'java'), 0) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) + os.environ['INPUT_IGNORE'] = '' From bec4b579f8d63e990868ce909858d7acb1afb16e Mon Sep 17 00:00:00 2001 From: Timothy Morey Date: Mon, 20 Sep 2021 12:45:07 -0400 Subject: [PATCH 2/3] extend to support a comma-delimited list of patterns --- action.yml | 2 +- main.py | 9 +++++---- tests/test_todo_parser.py | 11 +++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 5721d4a..65cdf02 100644 --- a/action.yml +++ b/action.yml @@ -52,5 +52,5 @@ inputs: description: "Default organisation projects" required: false IGNORE: - description: "A regular expression that matches files that should be ignored when searching for TODOs" + description: "A collection of comma-delimited regular expression that matches files that should be ignored when searching for TODOs" required: false diff --git a/main.py b/main.py index 341e55b..5327578 100644 --- a/main.py +++ b/main.py @@ -607,10 +607,11 @@ class TodoParser(object): return projects def _should_ignore(self, file): - ignore_pattern = os.getenv('INPUT_IGNORE', None) - if ignore_pattern: - if re.match(ignore_pattern, file): - return True + ignore_patterns = os.getenv('INPUT_IGNORE', None) + if ignore_patterns: + for pattern in filter(None, [pattern.strip() for pattern in ignore_patterns.split(',')]): + if re.match(pattern, file): + return True return False diff --git a/tests/test_todo_parser.py b/tests/test_todo_parser.py index 9a023e8..3d44f55 100644 --- a/tests/test_todo_parser.py +++ b/tests/test_todo_parser.py @@ -66,3 +66,14 @@ class IgnorePatternTests(unittest.TestCase): self.assertEqual(count_issues_for_file_type(self.raw_issues, 'java'), 0) self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) os.environ['INPUT_IGNORE'] = '' + + def test_multiple_ignores(self): + os.environ['INPUT_IGNORE'] = '.*\.java, tests/example-file\.php' + diff_file = open('tests/test_new.diff', 'r') + self.raw_issues = TodoParser().parse(diff_file) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'python'), 2) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'yaml'), 2) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'php'), 0) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'java'), 0) + self.assertEqual(count_issues_for_file_type(self.raw_issues, 'ruby'), 3) + os.environ['INPUT_IGNORE'] = '' From 2b8bdd309dbbd6fb5b4211ba4d0c69cef93c7cf8 Mon Sep 17 00:00:00 2001 From: Timothy Morey Date: Wed, 6 Oct 2021 10:49:38 -0400 Subject: [PATCH 3/3] add readme note --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b9aee6c..8ed16c1 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ The workflow file takes the following optional inputs: | `TOKEN` | No | The GitHub access token to allow us to retrieve, create and update issues for your repo. Default: `${{ github.token }}`. | | `CLOSE_ISSUES` | No | Optional boolean input that specifies whether to attempt to close an issue when a TODO is removed. Default: `true`. | | `AUTO_P` | No | Optional boolean input that specifies whether to format each line in multiline TODOs as a new paragraph. Default: `true`. | +| `IGNORE` | No | Optional string input that provides comma-delimited regular expressions that match files in the repo that we should not scan for TODOs. By default, we will scan all files. | These can be specified in `with` in the workflow file.