diff --git a/clickfile.py b/clickfile.py index 6e290f81e7..4307dad684 100755 --- a/clickfile.py +++ b/clickfile.py @@ -899,11 +899,13 @@ def dapps(): @click.option("--pr_url_for_report", default="", help="Url to send the report as comment for PR") @click.option("--token", default="", help="github token") def make_dapps_report(directory, pr_url_for_report, token): - report_content = dapps_cli.print_report(directory) + report_data = dapps_cli.prepare_report_data(directory) + dapps_cli.print_report(report_data) if pr_url_for_report: gh_client = GithubClient(token) gh_client.delete_last_comment(pr_url_for_report) - gh_client.add_comment_to_pr(pr_url_for_report, report_content) + format_data = dapps_cli.format_report_for_github.amrom.workers.devment(report_data) + gh_client.add_comment_to_pr(pr_url_for_report, format_data) if __name__ == "__main__": diff --git a/deploy/cli/dapps.py b/deploy/cli/dapps.py index 44d0f4af49..3ce5562296 100644 --- a/deploy/cli/dapps.py +++ b/deploy/cli/dapps.py @@ -41,7 +41,7 @@ ) WEB3_CLIENT = NeonWeb3Client(os.environ.get("PROXY_URL"), os.environ.get("CHAIN_ID", 111)) - +REPORT_HEADERS = ["Action", "Fee", "Cost in $", "Accounts", "TRx", "Estimated Gas", "Used Gas", "Used % of EG"] def set_github_env(envs: tp.Dict, upper=True) -> None: """Set environment for github action""" @@ -194,8 +194,7 @@ def get_solana_accounts_in_tx(eth_transaction): ) -def print_report(directory): - headers = ["Action", "Fee", "Cost in $", "Accounts", "TRx", "Estimated Gas", "Used Gas", "Used % of EG"] +def prepare_report_data(directory): out = {} reports = {} for path in glob.glob(str(pathlib.Path(directory) / "*-report.json")): @@ -222,11 +221,29 @@ def print_report(directory): row.append(used_gas) row.append(used_gas_percentage) out[app].append(row) + return out + + +def print_report(data): report_content = "" - for app in out: + for app in data: report_content += f'Cost report for "{app.title()}" dApp\n' report_content += "----------------------------------------\n" - report_content += tabulate.tabulate(out[app], headers, tablefmt="simple_grid") + "\n" + report_content += tabulate.tabulate(data[app], REPORT_HEADERS, tablefmt="simple_grid") + "\n" print(report_content) return report_content + + +def format_report_for_github.amrom.workers.devment(data): + headers = "| " + " | ".join(REPORT_HEADERS) + " |\n" + headers += "| --- | --- | --- | --- | --- | --- | --- |--- |\n" + report_content = "" + + for app in data: + report_content += f'\nCost report for "{app.title()}" dApp\n\n' + report_content+= headers + for action_data in data[app]: + report_content += "| "+ " | ".join([str(item) for item in action_data]) +" | "+ '\n' + return report_content + diff --git a/deploy/cli/github_api_client.py b/deploy/cli/github_api_client.py index 18850b5d76..3da971ff29 100644 --- a/deploy/cli/github_api_client.py +++ b/deploy/cli/github_api_client.py @@ -13,7 +13,7 @@ def __init__(self, token): "Accept": "application/vnd.github+json"} def add_comment_to_pr(self, url, msg): - data = {"body": f"
{DAPPS_REPORT_COMMENT_TITLE}\n```\n{msg}\n```\n
"} + data = {"body": f"
{DAPPS_REPORT_COMMENT_TITLE}\n\n{msg}\n\n"} click.echo(f"Sent data: {data}") click.echo(f"Headers: {self.headers}") response = requests.post(url, json=data, headers=self.headers)