blob: c216c7e290ee43723e55b0c3e625bdf920b5fa4d [file] [log] [blame]
Maxim Uvarov1acb99b2017-05-08 23:40:58 +03001#!/usr/bin/python
2
3# github pull request update script
4#
5# Script changes patch version and remove label Email_sent
6# Note: version changed only on pull request update event.
7
8import cgi
9import pickle
10import sys
11import time
12import json
13from StringIO import StringIO
14import sys, urllib
15from cgi import parse_qs, escape
16import re
17
18from github3 import login
19from github3 import pulls
20from github3 import issues
21import os
22
Maxim Uvarova9c4fdd2017-08-11 14:34:49 +030023configfile = '/home/muvarov/gscripts_config.py'
24sys.path.append(os.path.dirname(os.path.expanduser(configfile)))
25import gscripts_config as gcfg
26
27gh_login = gcfg.gcfg['gh']['login']
28gh_password = gcfg.gcfg['gh']['pass']
29
Maxim Uvarov1acb99b2017-05-08 23:40:58 +030030
31qin = sys.stdin.read()
32#f = open('mr_%s.dump' % time.time(), 'w')
33#pickle.dump(qin, f)
34#f.close()
35
36#fname = "mr_1493307805.62.dump"
37#qin = pickle.load( open(fname, "rb" ) )
38
39print("Content-type: text/html\n")
40print("""<!DOCTYPE HTML>
41 <html>
42 <head>
43 <meta charset="utf-8">
44 <title>some title</title>
45 </head>
46 <body>""")
47
48io = StringIO(qin)
49js = json.load(io)
50
Maxim Uvarova9c4fdd2017-08-11 14:34:49 +030051gh = login(gh_login, password=gh_password)
Maxim Uvarov1acb99b2017-05-08 23:40:58 +030052me = gh.user()
53print me
54
55repo = 0
56for r in gh.iter_repos():
57 print r.full_name
58 if r.full_name == "Linaro/odp":
59 #if r.full_name == "muvarov/odp":
60 repo = r
61 break
62
63if not repo:
64 print "Repo not found"
65 sys.exit(1)
66
67#for key, value in js['pull_request'].iteritems() :
68# print "\n\n\n\n----------------"
69# print key
70# print value
71
72action = js['action']
73if action == "synchronize" or action == "opened":
74 print("<h1>action is %s, process</h1>" % action)
75else:
76 print("<h1>action is %s, do nothing</h1>" % action)
77 print("</body></html>")
78 sys.exit(0)
79
80pr_num = js['pull_request']['number']
81pr = repo.pull_request(pr_num)
82issue = repo.issue(pr_num)
83
84
85branch = js['pull_request']['base']['ref']
86print "branch = %s\n" % branch
87
88title = issue.title
89
90version = 0
91for m in re.finditer(r'PATCH.*v([0-9]+)', title):
92 version = int(m.group(1))
93
94version += 1
95
96m = re.search(r"\[PATCH.*\] (.*)", title)
97if m:
98 title = m.group(1)
99
100if branch == "api-next":
101 issue.edit(title="[PATCH API-NEXT v%d] %s" % (version, title))
Yi He36f29342017-05-18 15:19:28 +0800102elif branch == "cloud-dev":
103 issue.edit(title="[PATCH CLOUD-DEV v%d] %s" % (version, title))
Maxim Uvarov1acb99b2017-05-08 23:40:58 +0300104else:
105 issue.edit(title="[PATCH v%d] %s" % (version, title))
106print issue.title
107
108commits = js['pull_request']['commits']
109if commits > 20:
110 issue.add_labels("No_Email_sent")
111else:
112 # return code does not reflect if event was actually
113 # removed
114 issue.remove_label("Email_sent")
115
Maxim Uvarova9c4fdd2017-08-11 14:34:49 +0300116try:
117 issue.remove_label("checkpatch")
118except:
119 pass
120
Maxim Uvarov1acb99b2017-05-08 23:40:58 +0300121print "body_text %s\n" % issue.body_text
122
123
124print("<h1>all ok!</h1>")
125print("</body></html>")