Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2093 metadata #2207

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/combined_assigned_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,34 @@ def output_html(violations_info_list, path, rules_descriptions):
## Write out file
fileName = path + '/assigned-by-' + id + '-report.html'
ET.ElementTree(htmlObj).write(fileName, encoding='unicode', method='html')

def output_aggregate_md(rules_to_violations, path, rules_descriptions):
s = 'Aggregate GORULE violations'
s += '\n\n## SUMMARY'
s += '\n\nThis report generated on {}'.format(datetime.date.today())
s += '\n\n## Rule Violations'


rules = list(rules_descriptions.keys())
rules.sort()


for rule in rules:
if rule in rules_to_violations:
violations = rules_to_violations[rule]
s += '\n\n## ' + rule + ' - ' + str(len(violations)) + " violations - " + rules_descriptions[rule]["title"]
for violation in violations:
s+= '\n' + violation['message'] + '--`' + violation['line'].strip()
else:
s += '\n\n## ' + rule + ' - no violations - ' + rules_descriptions[rule]["title"]
continue


## Write out file
fileName = path + '/aggregate-rule-violation-report.md'
utils.write_text(fileName, s)


def main():
"""The main runner of our script."""

Expand All @@ -254,6 +280,9 @@ def main():
rules_descriptions[rule_id] = {
"title": rule["title"]
}

#Create a rule to all violations dictionary
rules_to_violations = dict()

## Deal with incoming.
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -405,8 +434,17 @@ def main():
if (len(violations) == 0):
continue

#Add violations to the key_violations Lookup
if key in rules_to_violations:
cur_violations = rules_to_violations[key]
else:
cur_violations = []
rules_to_violations[key] = cur_violations


for violation in violations:
gaf_line = violation['line']
cur_violations.append(violation)
gaf_contents = re.split('\t', gaf_line)

## Get assigned by information from GAF line. If it does not exist, attempt to get from group that created the GAF file
Expand Down Expand Up @@ -472,6 +510,9 @@ def main():

## Output html file for each assigned-by with GORULE violation details
output_html(violator_list, os.path.dirname(args.output), rules_descriptions)

## Output aggregate violations file
output_aggregate_md(rules_to_violations, os.path.dirname(args.output), rules_descriptions)

## Final writeout of combined assigned-by json report
with open(args.output, 'w+') as fhandle:
Expand Down
Loading