From 7e2e7243897be4a1437dda848b31f6a6611de7db Mon Sep 17 00:00:00 2001 From: Carmen Tawalika Date: Fri, 12 Apr 2024 10:03:37 +0200 Subject: [PATCH] utils: do not make unnecessary request to addons GitHub repository if addon path is None (#3571) --------- Co-authored-by: Tomas Zigo --- utils/mkhtml.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/utils/mkhtml.py b/utils/mkhtml.py index 2957b231f3e..f51a821608c 100644 --- a/utils/mkhtml.py +++ b/utils/mkhtml.py @@ -291,25 +291,26 @@ def get_git_commit_from_rest_api_for_addon_repo( # Accessed date time if getting commit from GitHub REST API wasn't successful if not git_log: git_log = get_default_git_log(src_dir=src_dir) - grass_addons_url = ( - "https://api.github.com/repos/osgeo/grass-addons/commits?" - "path={path}&page=1&per_page=1&sha=grass{major}".format( - path=addon_path, - major=major, - ) - ) # sha=git_branch_name - - response = download_git_commit( - url=grass_addons_url, - response_format="application/json", - ) - if response: - commit = json.loads(response.read()) - if commit: - git_log["commit"] = commit[0]["sha"] - git_log["date"] = format_git_commit_date_from_rest_api( - commit_datetime=commit[0]["commit"]["author"]["date"], + if addon_path is not None: + grass_addons_url = ( + "https://api.github.com/repos/osgeo/grass-addons/commits?" + "path={path}&page=1&per_page=1&sha=grass{major}".format( + path=addon_path, + major=major, ) + ) # sha=git_branch_name + + response = download_git_commit( + url=grass_addons_url, + response_format="application/json", + ) + if response: + commit = json.loads(response.read()) + if commit: + git_log["commit"] = commit[0]["sha"] + git_log["date"] = format_git_commit_date_from_rest_api( + commit_datetime=commit[0]["commit"]["author"]["date"], + ) return git_log