fixed the issue (it seems like it at least) of not

being able to checkout the merge commit
This commit is contained in:
Karma Riuk
2025-03-18 11:52:08 +01:00
parent ade00bdf53
commit 7567ce9baa

View File

@ -1,5 +1,5 @@
import argparse, os, subprocess, docker import argparse, os, subprocess, docker
from typing import Optional from typing import Any, Callable, Optional
from github.PullRequest import PullRequest from github.PullRequest import PullRequest
from github.Repository import Repository from github.Repository import Repository
import pandas as pd import pandas as pd
@ -106,13 +106,30 @@ def process_pull(repo: Repository, pr: PullRequest, dataset: Dataset, repos_dir:
entry.metadata.reason_for_failure = "Couldn't clone the repo successfully" entry.metadata.reason_for_failure = "Couldn't clone the repo successfully"
entry.metadata.successful = False entry.metadata.successful = False
def _try_cmd(action: Callable[[], Any], reason_for_failure: str) -> bool:
"""
Tries a command, and if it fails, it sets the metadata of the entry.
"""
try: try:
ensure_full_history(repo_path) # return action()
run_git_cmd(["checkout", pr.merge_commit_sha], repo_path) action()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
entry.metadata.last_cmd_error_msg = f"{e.stderr}" entry.metadata.last_cmd_error_msg = f"{e.stderr}"
entry.metadata.reason_for_failure = f"Couldn't checkout the commit" entry.metadata.reason_for_failure = reason_for_failure
entry.metadata.successful = False entry.metadata.successful = False
# raise e
return entry.metadata.successful
if not _try_cmd(lambda: ensure_full_history(repo_path), "Couldn't ensure the full history of the repo (fetch --unshallow)"):
return
try:
run_git_cmd(["checkout", pr.merge_commit_sha], repo_path)
except subprocess.CalledProcessError:
if not _try_cmd(lambda: run_git_cmd(["fetch", "origin", f"pull/{pr.number}/merge"], repo_path), "Couldn't fetch the PR's merge commit"):
return
if not _try_cmd(lambda: run_git_cmd(["checkout", pr.merge_commit_sha], repo_path), "Coudln't checkout the PR's merge commit (even after fetching the pull/<pr_number>/merge)"):
return return
build_handler = get_build_handler(repos_dir, repo.full_name, updates) build_handler = get_build_handler(repos_dir, repo.full_name, updates)