diff --git a/TodoParser.py b/TodoParser.py index 6101704..af4dc05 100644 --- a/TodoParser.py +++ b/TodoParser.py @@ -24,22 +24,30 @@ class TodoParser(object): ISSUE_URL_PATTERN = re.compile(r'(?<=Issue URL:\s).+', re.IGNORECASE) ISSUE_NUMBER_PATTERN = re.compile(r'/issues/(\d+)', re.IGNORECASE) - def __init__(self): + def __init__(self, options=dict()): # Determine if the issues should be escaped. self.should_escape = os.getenv('INPUT_ESCAPE', 'true') == 'true' - # Load any custom identifiers, otherwise use the default. + # Load any custom identifiers specified by the environment, + # falling back to any specified by the constructor argument, + # otherwise using the default. custom_identifiers = os.getenv('INPUT_IDENTIFIERS') self.identifiers = ['TODO'] self.identifiers_dict = None if custom_identifiers: try: custom_identifiers_dict = json.loads(custom_identifiers) + except json.JSONDecodeError: + print('Invalid identifiers dict, ignoring.') + else: + custom_identifiers_dict = options.get("identifiers", None) + if custom_identifiers_dict: + try: for identifier_dict in custom_identifiers_dict: if type(identifier_dict['name']) is not str or type(identifier_dict['labels']) is not list: raise TypeError self.identifiers = [identifier['name'] for identifier in custom_identifiers_dict] self.identifiers_dict = custom_identifiers_dict - except (json.JSONDecodeError, KeyError, TypeError): + except (KeyError, TypeError): print('Invalid identifiers dict, ignoring.') self.languages_dict = None