-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
45 lines (32 loc) · 1.13 KB
/
validate.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
import json
import os
from distutils.util import strtobool
import jq
from utils import (BASE, create_comment, delete_comments, json_from_file,
request, validate_file)
send_comment = strtobool(os.getenv('INPUT_SEND_COMMENT'))
clear_comments = strtobool(os.getenv('INPUT_CLEAR_COMMENTS'))
event_path = os.getenv('GITHUB_EVENT_PATH')
repo = os.getenv('GITHUB_REPOSITORY')
PR_FILES = BASE + '/repos/{repo}/pulls/{pull_number}/files'
event = json_from_file(event_path)
pull_number = jq.compile('.pull_request.number').input(event).first()
errors = []
pr_files_url = PR_FILES.format(repo=repo, pull_number=pull_number)
pr_files = request('get', pr_files_url)
for pr_file in pr_files:
filename = pr_file['filename']
validation_errors = validate_file(filename)
if len(validation_errors):
errors.append({
'path': filename,
'errors': validation_errors
})
if clear_comments:
delete_comments(repo, pull_number)
if len(errors):
if send_comment:
create_comment(repo, pull_number, errors)
for error in errors:
print(error)
raise Exception('Fail validation')