From 13e93ac7f1af4c6aed9b37f714dc8b9a765a5001 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 26 Feb 2024 14:26:55 +0100 Subject: [PATCH] Tools: Don't include commits authored by others in weekly report script So far this would include commits committed by the given user, but authored by someone else. Unfotunately we can't use email addresses to filter these out, since we can't get the email addresses associated with an account from gitea, or do a user lookup by email. In my testing the commit author email and the publicly visible account email would mismatch in most cases. --- tools/triage/gitea_utils.py | 9 +++++++++ tools/triage/weekly_report.py | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/triage/gitea_utils.py b/tools/triage/gitea_utils.py index 1572df99198..aafc3886635 100644 --- a/tools/triage/gitea_utils.py +++ b/tools/triage/gitea_utils.py @@ -53,6 +53,15 @@ def url_json_get_all_pages(url, limit=50, verbose=False): return result +def gitea_user_get(username): + """ + Get the user data as JSON from the user name. https://docs.gitea.com/api/next/#tag/user/operation/userGet + """ + + url = f"{BASE_API_URL}/users/{username}" + return url_json_get(url) + + def gitea_json_issue_get(issue_fullname): """ Get issue/pull JSON data. diff --git a/tools/triage/weekly_report.py b/tools/triage/weekly_report.py index fcbc765dbcb..2d4d19a1b27 100644 --- a/tools/triage/weekly_report.py +++ b/tools/triage/weekly_report.py @@ -20,7 +20,7 @@ import argparse import datetime import json import re -from gitea_utils import gitea_json_activities_get, gitea_json_issue_get, gitea_json_issue_events_filter, git_username_detect +from gitea_utils import gitea_json_activities_get, gitea_json_issue_get, gitea_json_issue_events_filter, gitea_user_get, git_username_detect def argparse_create(): @@ -82,6 +82,8 @@ def report_personal_weekly_get(username, start, verbose=True): commits_main = [] + user_data = gitea_user_get(username) + for i in range(7): date_curr = start + datetime.timedelta(days=i) date_curr_str = date_curr.strftime("%Y-%m-%d") @@ -114,6 +116,11 @@ def report_personal_weekly_get(username, start, verbose=True): content_json = json.loads(activity["content"]) repo_fullname = activity["repo"]["full_name"] for commits in content_json["Commits"]: + # Skip commits that were not made by this user. Using email doesn't seem to + # be possible unfortunately. + if commits["AuthorName"] != user_data["full_name"]: + continue + title = commits["Message"].split('\n', 1)[0] if title.startswith("Merge branch "):