Vishnu Sreekumar has uploaded a new change for review. Change subject: Check for patches not updated for last 30 and 60 days alone. Pass more than one project as command line args. Abandon changes inactive for more than 60 days Signed-off-by: Vishnu Sreekumar <[email protected]> Change-Id: Ic911411a61e097c734d0199cc0405 ......................................................................
Check for patches not updated for last 30 and 60 days alone. Pass more than one project as command line args. Abandon changes inactive for more than 60 days Signed-off-by: Vishnu Sreekumar <[email protected]> Change-Id: Ic911411a61e097c734d0199cc04057c393b974f9 --- M scripts/alert_old_patches.py 1 file changed, 53 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/26/37426/1 diff --git a/scripts/alert_old_patches.py b/scripts/alert_old_patches.py index 0b732db..417a705 100755 --- a/scripts/alert_old_patches.py +++ b/scripts/alert_old_patches.py @@ -2,23 +2,32 @@ from __future__ import print_function +from email.mime.text import MIMEText import json import subprocess import sys import logging import traceback import smtplib +#import os +#GLOBAL +SSH_PORT = "29418" +SSH_USERNAME = "" # or os.environ["USER"] +SSH_KEY_FILE = "" +MAIL_SERVER_HOST = "localhost" -def checkForgottenPatches(gerritURL, days, project): +def check_forgotten_patches(gerrit_url, days, project): + " Return list of commits inactive for the given days. " + global SSH_PORT, SSH_USERNAME, SSH_KEY_FILE gerrit_call = ('ssh -o StrictHostKeyChecking=no -o \ - UserKnownHostsFile=/dev/null -p 29418 %s gerrit \ + UserKnownHostsFile=/dev/null -i %s -p %s %s@%s gerrit \ query --format=JSON status:open --dependencies \ - age:%sd project:%s' % (gerritURL, days, project)) + age:%sd project:%s' % (SSH_KEY_FILE, SSH_PORT, SSH_USERNAME, gerrit_url, days, project)) shell_command = ["bash", "-c", gerrit_call] - output, err, rc = _logExec(shell_command) + output, err, rc = log_exec(shell_command) if rc != 0: - print("Something wrong happened!\n" + str(err)) + print("Error executing %s\n" % shell_command + str(err)) sys.exit(2) patches = {} for line in output.split('\n'): @@ -33,10 +42,21 @@ pass return patches +def abandon_patch(gerrit_url, commit): + " Abandon the patch with comment. " + global SSH_PORT, SSH_USERNAME, SSH_KEY_FILE + gerrit_call = ('ssh -o StrictHostKeyChecking=no -o \ + UserKnownHostsFile=/dev/null -i %s -p %s %s@%s gerrit \ + review --format=JSON --abandon %s --message \ + "Abandoned due to no activity - please restore if still relevant"' % (SSH_KEY_FILE, SSH_PORT, SSH_USERNAME, gerrit_url, commit)) + shell_command = ["bash", "-c", gerrit_call] + output, err, rc = log_exec(shell_command) + if rc != 0: + print("Error executing %s\n" % shell_command + str(err)) + sys.exit(2) -def _logExec(argv, input=None): +def log_exec(argv, input=None): " Execute a given shell command while logging it. " - out = None err = None rc = None @@ -46,8 +66,7 @@ if input is not None: logging.debug(input) stdin = subprocess.PIPE - p = subprocess.Popen(argv, stdin=stdin, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen(argv, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate(input) rc = p.returncode logging.debug(out) @@ -56,30 +75,33 @@ logging.error(traceback.format_exc()) return (out, err, rc) - if __name__ == "__main__": + global MAIL_SERVER_HOST subject = "Forgotten Patches" - mailserver = smtplib.SMTP('localhost') - project = sys.argv[1] + mailserver = smtplib.SMTP(MAIL_SERVER_HOST) fromaddr = "[email protected]" patches = [] - mails = [ - (90, 'Your patch did not have any activity for over 90 days, it may be ' - 'abandoned automatically by the system in the near future : http://gerrit.ovirt.org/%s.'), - (60, 'Your patch did not have any activity for over 60 days, please consider ' - 'nudging for more attention, or should it be abandoned. : http://gerrit.ovirt.org/%s.'), - (30, 'Your patch did not have any activity for over 30 days, please consider ' - 'nudging for more attention. : http://gerrit.ovirt.org/%s.'), - ] - for days, template in mails: - output = checkForgottenPatches("gerrit.ovirt.org", days, project) - if not output: - print("Forgotten patches within the last %d days were not found" % - days) - for patch, owner in output.items(): - if patch not in patches: - patches.append(patch) - txt = template % patch - msg = 'Subject: %s\n\n%s' % (subject, txt) - mailserver.sendmail(fromaddr, owner['email'], msg) + days = [60,30] + template = "Your patch did not have any activity for over 30 days, please consider nudging for more attention. : http://gerrit.ovirt.org/%s" + + for project in sys.argv[1:]: + for day in days: + output = check_forgotten_patches("gerrit.ovirt.org", day, project) + if not output: + print("Forgotten patches within the last %d days were not found" % day) + for patch, owner in output.items(): + if patch not in patches: + patches.append(patch) + if day == 60: + try: + abandon_patch(patch) + except: + print("Error abandoning patch %s" % patch) + else: + txt = template % patch + msg = MIMEText('Subject: %s\n\n%s' % (subject, txt)) + msg['To'] = owner['email'] + if not "@redhat.com" in owner['email']: + msg['CC'] = "[email protected],[email protected]" + mailserver.sendmail(fromaddr, owner['email'], msg.as_string()) mailserver.quit() -- To view, visit http://gerrit.ovirt.org/37426 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic911411a61e097c734d0199cc04057c393b974f9 Gerrit-PatchSet: 1 Gerrit-Project: jenkins Gerrit-Branch: master Gerrit-Owner: Vishnu Sreekumar <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
