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,15 +106,32 @@ 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
try: def _try_cmd(action: Callable[[], Any], reason_for_failure: str) -> bool:
ensure_full_history(repo_path) """
run_git_cmd(["checkout", pr.merge_commit_sha], repo_path) Tries a command, and if it fails, it sets the metadata of the entry.
except subprocess.CalledProcessError as e: """
entry.metadata.last_cmd_error_msg = f"{e.stderr}" try:
entry.metadata.reason_for_failure = f"Couldn't checkout the commit" # return action()
entry.metadata.successful = False action()
except subprocess.CalledProcessError as e:
entry.metadata.last_cmd_error_msg = f"{e.stderr}"
entry.metadata.reason_for_failure = reason_for_failure
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 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
build_handler = get_build_handler(repos_dir, repo.full_name, updates) build_handler = get_build_handler(repos_dir, repo.full_name, updates)
if build_handler is None: if build_handler is None:
entry.metadata.last_cmd_error_msg = updates["error_msg"] entry.metadata.last_cmd_error_msg = updates["error_msg"]