summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-09-30 13:24:52 -0400
committerBen Sima <ben@bsima.me>2020-09-30 13:33:35 -0400
commitd58f671d8846bd8f5b6507fb7b614a1150fbfe4a (patch)
tree5e75759f5475cae47ed36be5939a56f5ea323250
parentb040aed9e904d3ec683810422f3b4d9151c7312a (diff)
devalloc: load active users from mailmap
-rwxr-xr-xDevalloc/main.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/Devalloc/main.py b/Devalloc/main.py
index d807aae..280b1b8 100755
--- a/Devalloc/main.py
+++ b/Devalloc/main.py
@@ -12,9 +12,10 @@ import subprocess
import sys
-def extract_email(line):
- """Given 'Ben Sima <ben@bsima.me>', extract `ben@bsima.me'."""
- return re.search(r"<(\S*)>", line).group(1)
+def find_user(line):
+ """Given 'Ben Sima <ben@bsima.me>', finds `Ben Sima'. Returns the first
+ matching string."""
+ return re.findall(r"^[^<]*", line)[0].strip()
def authors_for(path, active_users):
@@ -27,13 +28,23 @@ def authors_for(path, active_users):
data = {}
for line in lines:
parts = line.strip().split("\t")
- author = extract_email(parts[1])
+ author = find_user(parts[1])
commits = parts[0]
if author in active_users:
data[author] = commits
return data
+def mailmap_users():
+ """Returns users from the .mailmap file."""
+ users = []
+ with open(".mailmap") as file:
+ lines = file.readlines()
+ for line in lines:
+ users.append(find_user(line))
+ return users
+
+
MAX_SCORE = 10
@@ -80,7 +91,10 @@ def get_args():
"-i", "--ignored", nargs="+", default=[], help="patterns to ignore in paths",
)
cli.add_argument(
- "--active-users", nargs="+", default=[], help="list of active user emails",
+ "--active-users",
+ nargs="+",
+ default=[],
+ help="list of active user emails. if not provided, this is loaded from .mailmap",
)
cli.add_argument(
"-v",
@@ -135,9 +149,9 @@ class Repo:
self.stats[path] = authors_for(path, active_users)
self.blackholes = [path for path, authors in self.stats.items() if not authors]
self.liabilities = {
- path: list(authors.keys())
+ path: list(authors)
for path, authors in self.stats.items()
- if 1 < len(authors) < 3
+ if 1 <= len(authors) < 3
}
now = datetime.datetime.utcnow().astimezone()
self.stale = {}
@@ -194,6 +208,11 @@ if __name__ == "__main__":
guard_git(ARGS.repo)
+ # if no active users provided, load from .mailmap
+ if ARGS.active_users == []:
+ if os.path.exists(".mailmap"):
+ ARGS.active_users = mailmap_users()
+
# collect data
REPO = Repo(ARGS.ignored, ARGS.active_users)