From 396f77700205ff6ac67599e5c72c2aa5d6c134b9 Mon Sep 17 00:00:00 2001 From: Kowyo <110339237+kowyo@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:38:36 +0800 Subject: [PATCH] fix: skip a not useful commit msg --- scripts/gen_repo_update_time.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/gen_repo_update_time.py b/scripts/gen_repo_update_time.py index 4c726731..07703af2 100644 --- a/scripts/gen_repo_update_time.py +++ b/scripts/gen_repo_update_time.py @@ -13,23 +13,33 @@ def get_http_session(): session.mount('https://', adapter) return session - -# Function to get the latest commit def get_latest_commit(owner, repo): commits_url = f'https://api.github.com/repos/{owner}/{repo}/commits' params = {'since': '2000-01-01T00:00:01Z', - 'per_page': 1} - response = session.get(commits_url, headers=headers, params=params) + 'per_page': 10} # Fetch more than one commit + response = requests.get(commits_url, headers=headers, params=params) commit_info = dict() + if response.status_code == 200: - commit = response.json() - commit_info['author'] = commit[0]['commit']['author']['name'] - commit_info['date'] = datetime.datetime.strptime(commit[0]['commit']['author']['date'], - "%Y-%m-%dT%H:%M:%SZ") + datetime.timedelta(hours=8) # UTC-8 - commit_info['message'] = commit[0]['commit']['message'] + commits = response.json() + + for commit in commits: + message = commit['commit']['message'] + # Skip commits with messages starting with "Replace" + if message.startswith("Replace"): + continue + + # If the commit does not start with "Replace", process it + commit_info['author'] = commit['commit']['author']['name'] + commit_info['date'] = datetime.datetime.strptime(commit['commit']['author']['date'], + "%Y-%m-%dT%H:%M:%SZ") + datetime.timedelta(hours=8) # UTC-8 + commit_info['message'] = message + return commit_info # Return the first valid commit + else: print(f'Failed to fetch commits for {repo}: {response.status_code}') - return commit_info + + return commit_info # Return empty if no valid commit was found def save_latest_update(commit_info):