Skip to content
Snippets Groups Projects
Commit d58ac99b authored by Christoph Alt's avatar Christoph Alt
Browse files

fixed the commit info querying

parent abf6dcd7
Branches
Tags
No related merge requests found
Pipeline #56999 passed
...@@ -30,15 +30,20 @@ def get_api_url_commits(base_api_url: str) -> str: ...@@ -30,15 +30,20 @@ def get_api_url_commits(base_api_url: str) -> str:
return f"{base_api_url}/repository/commits" return f"{base_api_url}/repository/commits"
def get_last_commit(instance_url: str, project_id: Project_id, branch: str = ''): def get_last_commit(instance_url: str, project_id: Project_id, branch: str = '', commit=''):
url = get_api_url_commits(get_api_url(instance_url, project_id)) url = get_api_url_commits(get_api_url(instance_url, project_id))
if commit:
url = f"{url}/{commit}"
url = add_pagination(url, page=1, per_page=1) url = add_pagination(url, page=1, per_page=1)
params = {'ref_name': branch if branch else 'master'} params = {'ref_name': branch if branch else 'master'}
commit = requests.get(url, params=params) commit = requests.get(url, params=params)
logger.info(f"requesting {url} with params") logger.info(f"requesting {url} with params")
if commit.status_code != 200: if commit.status_code != 200:
commit.raise_for_status() commit.raise_for_status()
return commit.json()[0] try:
return commit.json()[0]
except KeyError:
return commit.json()
def get_commit_infos_from_api(commit: dict) -> dict: def get_commit_infos_from_api(commit: dict) -> dict:
...@@ -51,12 +56,12 @@ def get_git_infos_from_api(instance_url, project_id: Project_id, ...@@ -51,12 +56,12 @@ def get_git_infos_from_api(instance_url, project_id: Project_id,
commit_key="commit", commit_key="commit",
commit_msg_key="commit_message", commit_msg_key="commit_message",
commit_env_key=None): commit_env_key=None):
last_commit = "" commit = ""
if commit_env_key: if commit_env_key:
last_commit = os.getenv(commit_env_key, None) commit = os.getenv(commit_env_key, None)
last_commit = get_last_commit(instance_url, project_id, branch=branch, commit=commit)
if not last_commit:
last_commit = get_last_commit(instance_url, project_id, branch=branch)
commit, commit_msg = get_commit_infos_from_api(last_commit) commit, commit_msg = get_commit_infos_from_api(last_commit)
commit_msg = remove_newline(commit_msg) commit_msg = remove_newline(commit_msg)
return {commit_key: commit, commit_msg_key: commit_msg} return {commit_key: commit, commit_msg_key: commit_msg}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment