-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgh-hook-bugzilla.py
executable file
·109 lines (86 loc) · 2.39 KB
/
gh-hook-bugzilla.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
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
107
108
109
#!/usr/bin/python
# encoding=utf8
# bugzilla github push web hook
#
# Scripts updates bugzilla bug with merged commit message
from __future__ import print_function
import pprint
import bugzilla
import cgi
import pickle
import sys
import time
import json
from StringIO import StringIO
import sys, urllib
from cgi import parse_qs, escape
import re
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
configfile = '~/gscripts_config.py'
sys.path.append(os.path.dirname(os.path.expanduser(configfile)))
import gscripts_config as gcfg
blogin = gcfg.gcfg['bugz']['login']
bpassword = gcfg.gcfg['bugz']['pass']
print ("%s" % blogin)
qin = sys.stdin.read()
#f = open('python_%s.dump' % time.time(), 'w')
#pickle.dump(qin, f)
#f.close()
#fname = "test.dump"
#qin = pickle.load( open(fname, "rb" ) )
use_refs=['refs/heads/master']
def msg_has_bug(msg):
buglist = set()
print("%s\n" % msg)
for m in re.finditer('https://bugs\.linaro\.org/show_bug\.cgi\?id=([0-9]+)', msg):
buglist.add(m.group(1))
for m in re.finditer(r'[bB]ug #([0-9]+)', msg):
buglist.add(m.group(1))
for m in re.finditer(r'[bB]ug ([0-9]+)', msg):
buglist.add(m.group(1))
for m in re.finditer(r'[bB]ug: ([0-9]+)', msg):
buglist.add(m.group(1))
for m in re.finditer(r'[Ff]ixes: ([0-9]+)', msg):
buglist.add(m.group(1))
print("%s\n" % str(buglist))
return buglist
URL = "https://bugs.linaro.org"
bzapi = bugzilla.Bugzilla(URL)
if not bzapi.logged_in:
bzapi.login(blogin, bpassword)
print("Content-type: text/html\n")
print("""<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>some title</title>
</head>
<body>""")
io = StringIO(qin)
js = json.load(io)
found = 0
for ref in use_refs:
if ref == js["ref"]:
found = 1
break;
if not found:
print("<h1>ref %s is not posted to bugs</h1>" % js["ref"])
print("</body></html>")
sys.exit(0)
for c in js["commits"]:
bugset = msg_has_bug(c["message"])
for bugnum in bugset:
bug = bzapi.getbug(bugnum)
bug_msg = "%s\n%s\n%s\n%s %s\n%s\n" % (c["url"],
js["ref"],
c["timestamp"],
c["author"]["name"], c["author"]["email"],
c["message"])
update = bzapi.build_update(comment=bug_msg)
bzapi.update_bugs([bug.id], update)
print("Posted message to bug %s" % bugnum)
print("<h1>all ok!</h1>")
print("</body></html>")