-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.py
executable file
·58 lines (47 loc) · 1.89 KB
/
entrypoint.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
import os
import requests
TASKS_API = os.environ.get("PLATFORM_URL", "https://api.devskiller.com") + "/tasks"
input_api_key = os.environ["INPUT_API_KEY"]
input_path = os.environ["INPUT_PATH"]
def validate_input_path():
if not os.path.isfile(input_path) or not (input_path.endswith('.yaml') or input_path.endswith('.yml')):
print("::error::PATH parameter is not a yaml file")
exit(1)
def import_file():
print(f"::info::Importing the YAML file: {input_path}")
with open(input_path, "rb") as f:
response = requests.put(
f"{TASKS_API}/yaml",
data=f.read(),
headers={"Content-Type": "application/yaml", "Devskiller-Api-Key": input_api_key},
)
if response.status_code not in [200, 422]:
print(f"::error::Upload failed with status code: {response.status_code}, response: {response.text}")
exit(1)
return response
def write_summary(import_response):
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as f:
body = import_response.json()
markdown = ""
if import_response.status_code == 422:
markdown = "### Validation errors:\n"
for violation in body.get('violations', []):
markdown += f"- {violation}\n"
f.write(markdown)
exit(1)
elif import_response.status_code == 200:
if body.get('created'):
markdown += "### Created tasks:\n"
for task in body.get('created', []):
markdown += f"- {task}\n"
if body.get('updated'):
markdown += "\n### Updated tasks:\n"
for task in body.get('updated', []):
markdown += f"- {task}\n"
f.write(markdown)
def main():
validate_input_path()
import_response = import_file()
write_summary(import_response)
if __name__ == "__main__":
main()