Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions clickfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
27 changes: 22 additions & 5 deletions deploy/cli/dapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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")):
Expand All @@ -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

2 changes: 1 addition & 1 deletion deploy/cli/github_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, token):
"Accept": "application/vnd.github+json"}

def add_comment_to_pr(self, url, msg):
data = {"body": f"<details>{DAPPS_REPORT_COMMENT_TITLE}\n```\n{msg}\n```\n</details>"}
data = {"body": f"<details>{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)
Expand Down