Skip to content

Commit

Permalink
SDK fixes for github actions. (#36)
Browse files Browse the repository at this point in the history
`get_past_n_ancestors` would crash in python if `git merge-base` was
failing. Also made the TS and PY implementations more aligned.
  • Loading branch information
manugoyal authored Nov 9, 2023
1 parent 60e9455 commit 6d9e166
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions js/src/gitutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export async function getPastNAncestors(
`${e}`
);
}
if (!ancestor) {
return [];
}
const commits = await git.log({ from: ancestor, to: "HEAD" });
return commits.all.map((c) => c.hash);
}
Expand Down
7 changes: 5 additions & 2 deletions py/src/braintrust/gitutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_base_branch_ancestor(remote=None):
try:
return subprocess.check_output(["git", "merge-base", head, f"{remote_name}/{base_branch}"]).decode().strip()
except subprocess.CalledProcessError as e:
_logger.warning(f"Could not find a common ancestor with {remote_name}/{base_branch}", e)
# _logger.warning(f"Could not find a common ancestor with {remote_name}/{base_branch}")
return None


Expand All @@ -92,7 +92,10 @@ def get_past_n_ancestors(n=10, remote=None):
if repo is None:
return

ancestor = repo.commit(_get_base_branch_ancestor())
ancestor_output = _get_base_branch_ancestor()
if ancestor_output is None:
return
ancestor = repo.commit(ancestor_output)
for _ in range(n):
yield ancestor.hexsha
if ancestor.parents:
Expand Down

0 comments on commit 6d9e166

Please sign in to comment.