blob: 3373eef9c4f9e4fb390a8e4cbf20a46906fbbc0c [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
23
24qin = sys.stdin.read()
25#f = open('mr_%s.dump' % time.time(), 'w')
26#pickle.dump(qin, f)
27#f.close()
28
29#fname = "mr_1493307805.62.dump"
30#qin = pickle.load( open(fname, "rb" ) )
31
32print("Content-type: text/html\n")
33print("""<!DOCTYPE HTML>
34 <html>
35 <head>
36 <meta charset="utf-8">
37 <title>some title</title>
38 </head>
39 <body>""")
40
41io = StringIO(qin)
42js = json.load(io)
43
44gh = login('login-github@domain.com', password='password')
45me = gh.user()
46print me
47
48repo = 0
49for r in gh.iter_repos():
50 print r.full_name
51 if r.full_name == "Linaro/odp":
52 #if r.full_name == "muvarov/odp":
53 repo = r
54 break
55
56if not repo:
57 print "Repo not found"
58 sys.exit(1)
59
60#for key, value in js['pull_request'].iteritems() :
61# print "\n\n\n\n----------------"
62# print key
63# print value
64
65action = js['action']
66if action == "synchronize" or action == "opened":
67 print("<h1>action is %s, process</h1>" % action)
68else:
69 print("<h1>action is %s, do nothing</h1>" % action)
70 print("</body></html>")
71 sys.exit(0)
72
73pr_num = js['pull_request']['number']
74pr = repo.pull_request(pr_num)
75issue = repo.issue(pr_num)
76
77
78branch = js['pull_request']['base']['ref']
79print "branch = %s\n" % branch
80
81title = issue.title
82
83version = 0
84for m in re.finditer(r'PATCH.*v([0-9]+)', title):
85 version = int(m.group(1))
86
87version += 1
88
89m = re.search(r"\[PATCH.*\] (.*)", title)
90if m:
91 title = m.group(1)
92
93if branch == "api-next":
94 issue.edit(title="[PATCH API-NEXT v%d] %s" % (version, title))
95else:
96 issue.edit(title="[PATCH v%d] %s" % (version, title))
97print issue.title
98
99commits = js['pull_request']['commits']
100if commits > 20:
101 issue.add_labels("No_Email_sent")
102else:
103 # return code does not reflect if event was actually
104 # removed
105 issue.remove_label("Email_sent")
106
107print "body_text %s\n" % issue.body_text
108
109
110print("<h1>all ok!</h1>")
111print("</body></html>")