-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgh-checkpatch.py
More file actions
executable file
·106 lines (82 loc) · 2.42 KB
/
gh-checkpatch.py
File metadata and controls
executable file
·106 lines (82 loc) · 2.42 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
#
# Cron script to validate patches in open pull requests.
# 1. Validation skipped if "checkpatch" label is set.
# 2. Run both checkpatch.pl and odp agreement checks.
# Result is status on odp pull request github web page and
# label "checkpatch" set.
from dotenv import load_dotenv
from github3 import login
from os import getenv
from pathlib import Path
import re
import subprocess
import glob
import sys
ghpath = Path.home() / '.env'
load_dotenv(dotenv_path=str(ghpath))
gh_login = getenv("GH_LOGIN")
gh_password = getenv("GH_PASS")
if not gh_login or not gh_password:
print("GitHub login missing!")
sys.exit(1)
gh = login(gh_login, gh_password)
def my_system(cmd):
ret = subprocess.call(cmd, shell=False)
if ret:
print("Error: %s" % cmd)
return ret
def do_checkpatch(patch):
f = open("1.patch", "w")
f.write(patch)
f.close()
check_patch_ret = my_system("perl ./scripts/checkpatch.pl 1.patch > /dev/null")
#print "CHECKPATCH STATUS: %d" % check_patch_ret
agreement_cmd = "./odp-agreement/odp_check_contr.sh 1.patch ./odp-agreement/Iagree.hash ./odp-agreement/Corplist.hash > /dev/null"
agreement_ret = my_system(agreement_cmd)
#print "AGREEMENT STATUS: %d" % agreement_ret
my_system("rm 1.patch")
check_patch_ret = 0
agreement_ret = 0
return [check_patch_ret, agreement_ret]
my_system("git clone https://git.linaro.org/people/maxim.uvarov/odp-agreement.git")
my_system("cd odp-agreement && git pull")
repo = gh.repository("OpenDataPlane", "odp")
my_issues = repo.issues(state="open")
for my_issue in my_issues:
skip = 0
for l in my_issue.labels():
if l.name == "checkpatch":
skip = 1
break
if skip:
continue
pr = my_issue.pull_request()
if not pr:
continue
check_patch_ret = 0
agreement_ret = 0
for c in pr.commits():
(cp_ret, a_ret) = do_checkpatch(c.patch())
if cp_ret:
check_patch_ret = 1
if a_ret:
agreement_ret = 1
version = 0
for m in re.finditer(r'\[PATCH.*v([0-9]+)\]', my_issue.title):
version = int(m.group(1))
text = "<pre>v%d checks:\n" % version
if check_patch_ret == 0:
text += "checkpatch.pl - OK\n"
else:
text += "checkpatch.pl - FAIL\n"
if agreement_ret == 0:
text += "ODP License Agreement - PASSED\n"
else:
text += "ODP License Agreement - FAILED\n"
text +="</pre>\n"
my_issue.create_comment(text)
label = repo.label("checkpatch")
if not label:
label = repo.create_label("checkpatch", "0000ff")
my_issue.add_labels("checkpatch")