aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/mgagit
diff options
context:
space:
mode:
authorColin Guthrie <colin@mageia.org>2013-12-14 21:05:06 +0000
committerColin Guthrie <colin@mageia.org>2013-12-14 21:05:06 +0000
commitf767d4cdc2bbadd2bafa6c603db6e2f13e443d11 (patch)
treec83d6154e8aea9344cbc20e55a929a7a058e7d69 /deployment/mgagit
parent0aae0eaa6bf3f22de34437d24dde1b6fba78c92b (diff)
downloadpuppet-f767d4cdc2bbadd2bafa6c603db6e2f13e443d11.tar
puppet-f767d4cdc2bbadd2bafa6c603db6e2f13e443d11.tar.gz
puppet-f767d4cdc2bbadd2bafa6c603db6e2f13e443d11.tar.bz2
puppet-f767d4cdc2bbadd2bafa6c603db6e2f13e443d11.tar.xz
puppet-f767d4cdc2bbadd2bafa6c603db6e2f13e443d11.zip
Attempt to notify bugzilla when bugs are referenced in commits mga#11987
Diffstat (limited to 'deployment/mgagit')
-rwxr-xr-xdeployment/mgagit/templates/git-post-receive-hook63
1 files changed, 63 insertions, 0 deletions
diff --git a/deployment/mgagit/templates/git-post-receive-hook b/deployment/mgagit/templates/git-post-receive-hook
index aff07b17..0ccdb3bf 100755
--- a/deployment/mgagit/templates/git-post-receive-hook
+++ b/deployment/mgagit/templates/git-post-receive-hook
@@ -9,6 +9,10 @@ sys.path.insert(0, LIBDIR)
import git_multimail
+import xmlrpclib
+from cookielib import CookieJar, LWPCookieJar
+from bugz.bugzilla import BugzillaProxy
+
# When editing this list, remember to edit the same list in
# modules/cgit/templates/filter.commit-links.sh
BUG_REFS = {
@@ -23,6 +27,9 @@ BUG_REFS = {
COMMIT_RE = re.compile('^commit ([a-f0-9]{40})')
COMMIT_REPLACE = 'http://gitweb.mageia.org/%s/commit/?id=%s'
+MAGEIA_BUGZILLA_URL = 'https://bugs.mageia.org/xmlrpc.cgi'
+MAGEIA_BUGZILLA_PASSWORD_FILE = '.gitzilla-password'
+MAGEIA_BUGZILLA_COOKIE_FILE = '.gitzilla-cookie'
git_multimail.FOOTER_TEMPLATE = """\
@@ -52,6 +59,42 @@ git_multimail.Environment = LinksEnvironment
# Override the Reviesion class to inject gitweb/cgit links and any referenced
# bug URLs
class LinksRevision(git_multimail.Revision):
+ bz = None
+
+ def bugzilla_init(self):
+ if self.bz is None:
+ cookie_file = os.path.join(os.environ['HOME'], MAGEIA_BUGZILLA_COOKIE_FILE)
+ self.cookiejar = LWPCookieJar(cookie_file)
+ try:
+ self.cookiejar.load()
+ except IOError:
+ pass
+
+ self.bz = BugzillaProxy(MAGEIA_BUGZILLA_URL, cookiejar=self.cookiejar)
+ return self.bz
+
+ def bugzilla_login(self):
+ params = {
+ 'login': 'bot',
+ 'password': open(os.path.join(os.environ['HOME'], MAGEIA_BUGZILLA_PASSWORD_FILE), 'r').readline().rstrip(),
+ 'remember': True
+ }
+ self.bz.User.login(params)
+ self.cookiejar.save()
+ os.chmod(self.cookiejar.filename, 0600)
+
+ def bugzilla_call(self, method, *args):
+ """Attempt to call method with args. Log in if authentication is required.
+ """
+ try:
+ return method(*args)
+ except xmlrpclib.Fault, fault:
+ # Fault code 410 means login required
+ if fault.faultCode == 410:
+ self.bugzilla_login()
+ return method(*args)
+ raise
+
def generate_email_body(self, push):
"""Show this revision."""
@@ -81,6 +124,26 @@ class LinksRevision(git_multimail.Revision):
idx+=1
output.insert(idx, "\n")
idx+=1
+
+ # Attempt to modify bugzilla
+ if "Mageia" in bugs:
+ try:
+ bz = self.bugzilla_init()
+
+ # Mask email address
+ comment = output[0:idx]
+ comment[1] = re.sub(r'^(Author: [^@]*)@.*(>)?', r'\1@...>', comment[1])
+ comment = "".join(comment)
+
+ params = {}
+ params['ids'] = bugs['Mageia']
+ params['comment'] = { 'body': comment }
+ self.bugzilla_call(bz.Bug.update, params)
+ print "Updated bugzilla bugs: %s" % ", ".join(bugs['Mageia'])
+ except:
+ print "Unable to post to bugzilla bugs: %s :(" % ", ".join(bugs['Mageia'])
+ pass
+
break
m = COMMIT_RE.search(line)
if m: