generated from actions/hello-world-docker-action
/
report.py
71 lines (50 loc) · 1.59 KB
/
report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import os
import sys
from github import Github
ACCESS_TOKEN = os.getenv('GITHUB_TOKEN')
def get_webhook_event():
filepath = os.getenv('GITHUB_EVENT_PATH')
with open(filepath, 'r') as f:
return json.load(f)
def generate_report(kurobako_report, public_image_url, title):
header_trimmed = kurobako_report[len('# Benchmark Result Report\n\n'):]
metadata, detail = header_trimmed.split('## Table of Contents\n')[:2]
body = f"""
# {title}
![plot curve image]({public_image_url})
{metadata}
<details>
<summary>Please expand here for more details.</summary>
## Table of Contents
{detail}
</details>
"""[1:]
return body
def main():
print(sys.argv)
markdown_report_path = sys.argv[1]
public_image_url = sys.argv[2]
title = sys.argv[3]
event = get_webhook_event()
pull_number = event.get('number')
print("Pull Request:", pull_number)
repository = event.get('repository').get("full_name")
print("Repository:", pull_number)
with open(markdown_report_path, 'r') as f:
kurobako_report = f.read()
client = Github(ACCESS_TOKEN)
issue = client.get_repo(repository).get_issue(pull_number)
body = generate_report(kurobako_report, public_image_url, title)
# Comment to the pull request or edit if previous comment exists.
for c in issue.get_comments():
if not c.user.login.startswith('github-actions'):
continue
if not c.body.startswith(f'# {title}'):
continue
c.edit(body)
break
else:
issue.create_comment(body)
if __name__ == '__main__':
main()