change to using an is_bot() function for detecting bots
Not all bots have the proper marker in their username, so we will need to have a list of known bots.
diff --git a/notifier.py b/notifier.py
index f9aa544..2d4bb1d 100644
--- a/notifier.py
+++ b/notifier.py
@@ -35,6 +35,7 @@
print = asfpy.syslog.Printer(identity="github-event-notifier")
CONFIG_FILE = "github-event-notifier.yaml"
+KNOWN_BOTS_FILE = "known-robots.txt"
SEND_EMAIL = True
RE_PROJECT = re.compile(r"(?:incubator-)?([^-]+)")
RE_JIRA_TICKET = re.compile(r"\b([A-Z0-9]+-\d+)\b")
@@ -56,6 +57,19 @@
"Accept": "*/*",
}
+def is_bot(userid: str):
+ """Figures out if a GitHub user is a known bot or not"""
+ if "[bot]" in userid: # Easiest way to detect is the [bot] marker
+ return True
+ # Try the bot file?
+ known_robots = set()
+ if os.path.isfile(KNOWN_BOTS_FILE): # If we have a list file
+ # Grab all lines that aren't comments
+ bots_from_file = [x.strip() for x in open(KNOWN_BOTS_FILE).readlines() if not x.startswith("#")]
+ #Update bot set with all non-empty lines
+ known_robots.update([bot for bot in bots_from_file if bot])
+ return userid in known_robots
+
class DiffComments:
def __init__(self, uid, original_payload):
@@ -183,7 +197,7 @@
}
# If bot, we remove the [bot] in the user ID and check the bot rules
- if "[bot]" in userid:
+ if is_bot(userid):
for rule in rule_order_bots:
key = rule.format(**rule_dict)
if key in scheme and scheme[key]: # If we have this scheme and it is non-empty, return it