aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Uvarov <maxim.uvarov@linaro.org>2017-08-11 14:34:49 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-08-11 14:35:19 +0300
commita9c4fdd9b6f5d1fa849103ea0f1d1ea098c78969 (patch)
tree0b4813c419fc56481c644f295a69e7e87a6f6978
parent1951be1b589c75663b5a29897ffab0f99a8a089f (diff)
add gh-checkpatch.py: to validate patches
gh-checkpatch.py works together with gh-hook-mr.py to validate patches with checkpatch and odp agreement checks. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rwxr-xr-xgh-checkpatch.py93
-rwxr-xr-xgh-hook-mr.py14
2 files changed, 106 insertions, 1 deletions
diff --git a/gh-checkpatch.py b/gh-checkpatch.py
new file mode 100755
index 0000000..7b3dc94
--- /dev/null
+++ b/gh-checkpatch.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+#
+# 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 github import Github
+import github
+import os
+import re
+import glob
+import sys
+
+configfile = '/home/muvarov/gscripts_config.py'
+sys.path.append(os.path.dirname(os.path.expanduser(configfile)))
+import gscripts_config as gcfg
+
+gh_login = gcfg.gcfg['gh']['login']
+gh_password = gcfg.gcfg['gh']['pass']
+
+g = Github(gh_login, password=gh_password)
+
+for repo in g.get_user().get_repos():
+ if repo.full_name == "Linaro/odp":
+ break
+if not repo:
+ exit(1)
+
+def my_system(cmd):
+ ret = os.system(cmd)
+ if ret:
+ print "Error: %s" % cmd
+ return ret
+
+def do_checkpatch(sha):
+ patch = "%s.patch" % sha
+ my_system("rm %s 2>/dev/null" % patch)
+
+ ret = my_system("wget https://github.com/Linaro/odp/commit/%s > /dev/null" % patch)
+ if ret:
+ print "Download %s failed, abort!\n" % patch
+ sys.exit(1)
+
+ check_patch_ret = my_system("perl ./scripts/checkpatch.pl %s > /dev/null" % patch)
+ print "CHECKPATCH STATUS: %d" % check_patch_ret
+
+ agreement_cmd = "./odp-agreement/odp_check_contr.sh %s ./odp-agreement/Iagree.hash ./odp-agreement/Corplist.hash > /dev/null" % patch
+ agreement_ret = my_system(agreement_cmd)
+ print "AGREEMENT STATUS: %d" % agreement_ret
+
+ my_system("rm %s" % patch)
+ return [check_patch_ret, agreement_ret]
+
+my_system("git clone https://git.linaro.org/people/maxim.uvarov/odp-agreement.git")
+
+for pull in repo.get_pulls():
+ issue = repo.get_issue(pull.number)
+ skip = 0
+ for l in issue.get_labels():
+ if l.name == "checkpatch":
+ skip = 1
+ break
+ if skip:
+ continue
+
+ for c in pull.get_commits():
+ (check_patch_ret, agreement_ret) = do_checkpatch(c.commit.sha)
+ if check_patch_ret == 0:
+ c.create_status(state="success",
+ target_url="http://none",
+ description="checkpatch.pl", context="checkpatch success")
+ else:
+ c.create_status(state="failure",
+ target_url="http://none",
+ description="checkpatch.pl", context="checkpatch failed")
+
+ if agreement_ret == 0:
+ c.create_status(state="success",
+ target_url="http://none",
+ description="ODP License Agreement", context="ODP License Agreement")
+ else:
+ c.create_status(state="failure",
+ target_url="https://www.opendataplane.org/contributor/individual/",
+ description="ODP License Agreement",
+ context="Individual or Corporate agreement check err")
+
+ label = repo.get_label("checkpatch")
+ if not label:
+ label = repo.create_label("checkpatch", "0000ff")
+
+ issue.add_to_labels(label)
diff --git a/gh-hook-mr.py b/gh-hook-mr.py
index 6392950..c216c7e 100755
--- a/gh-hook-mr.py
+++ b/gh-hook-mr.py
@@ -20,6 +20,13 @@ from github3 import pulls
from github3 import issues
import os
+configfile = '/home/muvarov/gscripts_config.py'
+sys.path.append(os.path.dirname(os.path.expanduser(configfile)))
+import gscripts_config as gcfg
+
+gh_login = gcfg.gcfg['gh']['login']
+gh_password = gcfg.gcfg['gh']['pass']
+
qin = sys.stdin.read()
#f = open('mr_%s.dump' % time.time(), 'w')
@@ -41,7 +48,7 @@ print("""<!DOCTYPE HTML>
io = StringIO(qin)
js = json.load(io)
-gh = login('login-github@domain.com', password='password')
+gh = login(gh_login, password=gh_password)
me = gh.user()
print me
@@ -106,6 +113,11 @@ else:
# removed
issue.remove_label("Email_sent")
+try:
+ issue.remove_label("checkpatch")
+except:
+ pass
+
print "body_text %s\n" % issue.body_text