Skip to content

Commit

Permalink
HelpInputOutputValidator error messages and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gusingh-r7 committed Jan 8, 2020
1 parent 15eb37b commit 40c40cc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ to simulate the `--all` flag.

## Changelog

* 2.6.9 - Update HelpInputOutputValidator to fix error messaging |
Fix issue with HelpInputOutputValidator when help.md has action and trigger with same name
* 2.6.8 - Docker Validator to run with -a command line argument | Helpful message on failure
* 2.6.7 - Fix issue where OutputValidator was throwing error for plugins without any action
* 2.6.6 - Fix issue where HelpInputOutputValidator was not extracting complete output section of an action or trigger
Expand Down
89 changes: 53 additions & 36 deletions icon_validator/rules/help_input_output_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,45 @@ class HelpInputOutputValidator(KomandPluginValidator):
action_missing = 0

@staticmethod
def validate_input(action_title: str, action_input: list):
regex = r"#### " + action_title + "\n.*?#+ Output"
def validate_input(action_title: str, action_input: list, process_type: str):
regex = r"### " + process_type.capitalize() + ".*?#### " + action_title + "\n.*?#+ Output"
if process_type == "actions":
regex = regex + ".*?### Triggers"

action_input_section = re.findall(regex, HelpInputOutputValidator.raw_help, re.DOTALL)

if not action_input_section:
print(f"{YELLOW}Action/Trigger \"{action_title}\" could be missing or title is incorrect in help.md{RESET_ALL}")
print(f"{YELLOW}{process_type[:-1].capitalize()} \"{action_title}\" could be missing or title is incorrect in help.md{RESET_ALL}")
HelpInputOutputValidator.violated = 1
HelpInputOutputValidator.action_missing = 1
return

regex = r"#### " + action_title + "\n.*?#+ Output"
action_input_section = re.findall(regex, action_input_section[0], re.DOTALL)

for input_fields in action_input:
if input_fields not in action_input_section[0]:
HelpInputOutputValidator.violations.append(input_fields)

@staticmethod
def validate_output(action_title: str, action_output: list):
def validate_output(action_title: str, action_output: list, process_type: str):
regex = r"### " + process_type.capitalize() + ".*?#### " + action_title + "\n.*?#+ Output\n\n.*?\n\n"
if process_type == "actions":
regex = regex + ".*?### Trigger"

action_help_section_temp = re.findall(regex, HelpInputOutputValidator.raw_help, re.DOTALL)
regex = r"#### " + action_title + "\n.*?#+ Output\n\n.*?\n\n"
action_help_section = re.findall(regex, HelpInputOutputValidator.raw_help, re.DOTALL)
action_help_section = re.findall(regex, action_help_section_temp[0], re.DOTALL)

if "This " + process_type[:-1] + " does not contain any outputs." not in action_help_section[0]:
regex = r"### " + process_type.capitalize() + ".*?#### " + action_title + "\n.*?#+ Output\n\n.*?" + re.escape("|Name|Type|Required|Description|") + ".*?\n\n"
if process_type == "actions":
regex = regex + ".*?### Triggers"

if "This action does not contain any outputs." not in action_help_section[0]:
action_help_section_temp = re.findall(regex, HelpInputOutputValidator.raw_help, re.DOTALL)
regex = r"#### " + action_title + "\n.*?#+ Output\n\n.*?" + re.escape("|Name|Type|Required|Description|") + ".*?\n\n"
action_help_section = re.findall(regex, HelpInputOutputValidator.raw_help, re.DOTALL)
action_output_section = re.findall(r'#+ Output\n\n.*?' + re.escape("|Name|Type|Required|Description|") + ".*?\n\n", action_help_section[0], re.DOTALL)
action_output_section_temp = re.findall(regex, action_help_section_temp[0], re.DOTALL)
action_output_section = re.findall(r'#+ Output\n\n.*?' + re.escape("|Name|Type|Required|Description|") + ".*?\n\n", action_output_section_temp[0], re.DOTALL)
else:
action_output_section = re.findall(r"#+ Output\n\n.*?\n\n", action_help_section[0], re.DOTALL)

Expand Down Expand Up @@ -68,34 +84,35 @@ def get_spec_output(output_content: dict) -> list:
def validate(self, spec):
HelpInputOutputValidator.raw_help = spec.raw_help()
raw_spec_yaml = spec.spec_dictionary()
actions = raw_spec_yaml.get('actions', {})
actions.update(raw_spec_yaml.get('triggers', {}))

for key, value in actions.items():
action_name = actions[key].get('title')
input_section = actions[key].get('input')
output_section = actions[key].get('output')
HelpInputOutputValidator.action_missing = 0

# Action with no input in spec file will skip input validation
if input_section:
action_input_fields = HelpInputOutputValidator.get_spec_input(input_section)
HelpInputOutputValidator.validate_input(action_name, action_input_fields)

if HelpInputOutputValidator.violations:
print(f'{YELLOW}Input violations: Action/Trigger -> \"{action_name}\": Missing {HelpInputOutputValidator.violations} in help.md{RESET_ALL}')
HelpInputOutputValidator.violations = []
HelpInputOutputValidator.violated = 1

# Actions with no output in spec file will skip output validation. Also, skip output validation for actions not found in help.md
if output_section and not HelpInputOutputValidator.action_missing:
action_output_fields = HelpInputOutputValidator.get_spec_output(output_section)
HelpInputOutputValidator.validate_output(action_name, action_output_fields)

if HelpInputOutputValidator.violations:
print(f'{YELLOW}Output violations: Action/Trigger -> \"{action_name}\": Missing {HelpInputOutputValidator.violations} in help.md{RESET_ALL}')
HelpInputOutputValidator.violations = []
HelpInputOutputValidator.violated = 1
process_type = ["actions", "triggers"]

for p_type in process_type:
actions = raw_spec_yaml.get(p_type, {})
for key, value in actions.items():
action_name = actions[key].get('title')
input_section = actions[key].get('input')
output_section = actions[key].get('output')
HelpInputOutputValidator.action_missing = 0

# Action with no input in spec file will skip input validation
if input_section:
action_input_fields = HelpInputOutputValidator.get_spec_input(input_section)
HelpInputOutputValidator.validate_input(action_name, action_input_fields, p_type)

if HelpInputOutputValidator.violations:
print(f'{YELLOW}Input violations: {p_type[:-1].capitalize()} -> \"{action_name}\": Missing {HelpInputOutputValidator.violations} in help.md{RESET_ALL}')
HelpInputOutputValidator.violations = []
HelpInputOutputValidator.violated = 1

# Actions with no output in spec file will skip output validation. Also, skip output validation for actions not found in help.md
if output_section and not HelpInputOutputValidator.action_missing:
action_output_fields = HelpInputOutputValidator.get_spec_output(output_section)
HelpInputOutputValidator.validate_output(action_name, action_output_fields, p_type)

if HelpInputOutputValidator.violations:
print(f'{YELLOW}Output violations: {p_type[:-1].capitalize()}-> \"{action_name}\": Missing {HelpInputOutputValidator.violations} in help.md{RESET_ALL}')
HelpInputOutputValidator.violations = []
HelpInputOutputValidator.violated = 1

if HelpInputOutputValidator.violated:
raise Exception("Help.md is not in sync with plugin.spec.yaml. Please check and rectify above violations")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description = fh.read()

setup(name='insightconnect_integrations_validators',
version='2.6.8',
version='2.6.9',
description='Validator tooling for InsightConnect integrations',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 40c40cc

Please sign in to comment.