-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.py
More file actions
59 lines (51 loc) · 1.73 KB
/
temp.py
File metadata and controls
59 lines (51 loc) · 1.73 KB
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
import sys
import re
import requests
def create_github_comment(repo, token, comment):
url = f"https://api.github.com/repos/{repo}/issues"
# /repos/{owner}/{repo}/issues
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"
}
data = {
"body": comment,
"title": "Homework",
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 201:
print("Comment created successfully!")
else:
print(f"Failed to create comment: {response.status_code}")
print(response.json())
def extract_test_results(line):
# Define a regex pattern to extract the test results
pattern = r"(\d+) tests passed, (\d+) failed, (\d+) skipped \((\d+) total tests\)"
match = re.search(pattern, line)
if match:
passed = match.group(1)
failed = match.group(2)
skipped = match.group(3)
total = match.group(4)
return passed, failed, skipped, total
else:
return None, None, None, None
def main():
if len(sys.argv) < 4:
print("Usage: your_script.py <last_line_of_output>")
sys.exit(1)
last_line = sys.argv[1]
repo = sys.argv[2]
token = sys.argv[3]
passed, failed, skipped, total = extract_test_results(last_line)
comment = f'Tests passed {passed} Total Failed {failed} Score: {10 * int(passed)}'
create_github_comment(repo, token, comment)
if passed is not None:
print(f"Tests passed: {passed}")
print(f"Tests failed: {failed}")
print(f"Tests skipped: {skipped}")
print(f"Total tests: {total}")
else:
print("Failed to parse the test results.")
if __name__ == "__main__":
main()