From 64072461dfcc74857087b23c9ba7d9812b6afe40 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Tue, 10 Nov 2015 20:18:13 +0100 Subject: Add support for package update notifications Introduce a new notification option to receive notifications when a new commit is pushed to a package repository. Implements FS#30109. Signed-off-by: Lukas Fleischer --- git-interface/git-update.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'git-interface') diff --git a/git-interface/git-update.py b/git-interface/git-update.py index 3b587b3..e54e0e6 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -5,6 +5,7 @@ import mysql.connector import os import pygit2 import re +import subprocess import sys import srcinfo.parse @@ -19,6 +20,8 @@ aur_db_user = config.get('database', 'user') aur_db_pass = config.get('database', 'password') aur_db_socket = config.get('database', 'socket') +notify_cmd = config.get('notifications', 'notify-cmd') + repo_path = config.get('serve', 'repo-path') repo_regex = config.get('serve', 'repo-regex') @@ -169,6 +172,13 @@ def save_metadata(metadata, db, cur, user): db.commit() +def update_notify(db, cur, user, pkgbase_id): + # Obtain the user ID of the new maintainer. + cur.execute("SELECT ID FROM Users WHERE Username = %s", [user]) + user_id = int(cur.fetchone()[0]) + + # Execute the notification script. + subprocess.Popen((notify_cmd, 'update', str(user_id), str(pkgbase_id))) def die(msg): sys.stderr.write("error: {:s}\n".format(msg)) @@ -336,8 +346,6 @@ for pkgname in srcinfo.utils.get_package_names(metadata): # Store package base details in the database. save_metadata(metadata, db, cur, user) -db.close() - # Create (or update) a branch with the name of the package base for better # accessibility. repo.create_reference('refs/heads/' + pkgbase, sha1_new, True) @@ -347,3 +355,9 @@ repo.create_reference('refs/heads/' + pkgbase, sha1_new, True) # http://git.661346.n2.nabble.com/PATCH-receive-pack-Create-a-HEAD-ref-for-ref-namespace-td7632149.html # for details. repo.create_reference('refs/namespaces/' + pkgbase + '/HEAD', sha1_new, True) + +# Send package update notifications. +update_notify(db, cur, user, pkgbase_id) + +# Close the database. +db.close() -- cgit v1.2.3-70-g09d2