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.
This commit is contained in:
Julian Eisel
2024-02-26 14:26:55 +01:00
parent 065ba92c54
commit 13e93ac7f1
2 changed files with 17 additions and 1 deletions

View File

@@ -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.

View File

@@ -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 "):