Skip to content

Commit

Permalink
Reorder summary table in console and PR comment reporters (#10)
Browse files Browse the repository at this point in the history
* Reorder summary table in console and PR comment reporters

* Do not post PR comment if already merged
  • Loading branch information
nvuillam authored Oct 24, 2020
1 parent 8bbc51b commit c1fb5c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 2 additions & 3 deletions megalinter/reporters/ConsoleReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ def __init__(self, params=None):
super().__init__(params)

def produce_report(self):
table_header = ["Descriptor", "Linter",
"Files with error(s)", "Total files"]
table_header = ["Descriptor", "Linter", "Found", "Errors"]
table_data = [table_header]
for linter in self.master.linters:
if linter.is_active is True:
table_data += [
[linter.descriptor_id, linter.linter_name, str(linter.number_errors), str(len(linter.files))]]
[linter.descriptor_id, linter.linter_name, str(len(linter.files)), str(linter.number_errors)]]
table = terminaltables.AsciiTable(table_data)
table.title = "----SUMMARY"
# Output table in console
Expand Down
15 changes: 9 additions & 6 deletions megalinter/reporters/GithubCommentReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def produce_report(self):
run_id = os.environ['GITHUB_RUN_ID']
sha = os.environ.get('GITHUB_SHA')
action_run_url = f"https://github.com/{github_repo}/actions/runs/{run_id}"
table_header = ["Descriptor", "Linter",
"Files with error(s)", "Total files"]
table_header = ["Descriptor", "Linter", "Found", "Errors"]
table_data_raw = [table_header]
for linter in self.master.linters:
if linter.is_active is True:
Expand All @@ -51,7 +50,7 @@ def produce_report(self):
errors_cell = f"[**{linter.number_errors}**]({action_run_url})" if linter.number_errors > 0 \
else linter.number_errors
table_data_raw += [
[first_col, linter_link, errors_cell, len(linter.files)]]
[first_col, linter_link, len(linter.files), errors_cell]]
# Build markdown table
table_data_raw.pop(0)
writer = MarkdownTableWriter(
Expand All @@ -63,10 +62,12 @@ def produce_report(self):
status_with_href = f"[**{self.master.status.upper()}**]({action_run_url}) {emoji}"
p_r_msg = f"## [Mega-Linter]({self.gh_url}) status: {status_with_href}" + os.linesep + os.linesep
p_r_msg += table_content + os.linesep
p_r_msg += f"See artifact Mega-Linter reports on [GitHub Action page]({action_run_url})" + \
p_r_msg += f"See errors details in [**artifact Mega-Linter reports** on " \
f"GitHub Action page]({action_run_url})" + \
os.linesep
p_r_msg += "_Set `VALIDATE_ALL_CODEBASE: true` in mega-linter.yml to validate " + \
"all sources, not only the diff_" + os.linesep
if self.master.validate_all_code_base is False:
p_r_msg += "_Set `VALIDATE_ALL_CODEBASE: true` in mega-linter.yml to validate " + \
"all sources, not only the diff_" + os.linesep
logging.debug("\n" + p_r_msg)
# Post comment on pull request if found
github_auth = os.environ['PAT'] if os.environ.get(
Expand All @@ -76,6 +77,8 @@ def produce_report(self):
commit = repo.get_commit(sha=sha)
pr_list = commit.get_pulls()
for pr in pr_list:
if pr.is_merged():
continue
try:
pr.create_issue_comment(p_r_msg)
logging.debug(f'Posted Github comment: {p_r_msg}')
Expand Down

0 comments on commit c1fb5c7

Please sign in to comment.