diff --git a/Android.bp b/Android.bp index 328cf7a985a6f0c615a86d2a8d2c2a2ad9135422..c4f158d3ad8f2505ef88c2bb9e989281d1bcd5c1 100644 --- a/Android.bp +++ b/Android.bp @@ -27,6 +27,7 @@ python_binary_host { name: "external_updater_notifier", main: "notifier.py", srcs: [ + "git_utils.py", "notifier.py", ], } diff --git a/notifier.py b/notifier.py index 982354cf8b896604bd2f81855f7b39a75e006e14..1e2c7cdc37aed3232943cde2feb24f66c06bd629 100644 --- a/notifier.py +++ b/notifier.py @@ -21,6 +21,7 @@ external_updater_notifier \ googletest """ +from datetime import timedelta, datetime import argparse import json import os @@ -28,6 +29,7 @@ import re import subprocess import time +import git_utils def parse_args(): """Parses commandline arguments.""" @@ -73,6 +75,22 @@ def _send_email(proj, latest_ver, recipient, upgrade_log): input=msg, encoding='ascii') +NOTIFIED_TIME_KEY_NAME = 'latest_notified_time' + + +def _should_notify(latest_ver, proj_history): + if latest_ver in proj_history: + # Processed this version before. + return False + + timestamp = proj_history.get(NOTIFIED_TIME_KEY_NAME, 0) + time_diff = datetime.today() - datetime.fromtimestamp(timestamp) + if git_utils.is_commit(latest_ver) and time_diff <= timedelta(days=30): + return False + + return True + + def _process_results(args, history, results): for proj, res in results.items(): if 'latest' not in res: @@ -82,11 +100,12 @@ def _process_results(args, history, results): if latest_ver == current_ver: continue proj_history = history.setdefault(proj, {}) - if latest_ver not in proj_history: + if _should_notify(latest_ver, proj_history): upgrade_log = _upgrade(proj) if args.generate_change else "" try: _send_email(proj, latest_ver, args.recipients, upgrade_log) proj_history[latest_ver] = int(time.time()) + proj_history[NOTIFIED_TIME_KEY_NAME] = int(time.time()) except subprocess.CalledProcessError as err: msg = """Failed to send email for {} ({}). stdout: {}