Skip to content

Commit

Permalink
Merge pull request #472 from gauge-sh/support-gha-checkout
Browse files Browse the repository at this point in the history
support gha pr commit sha
  • Loading branch information
caelean authored Dec 9, 2024
2 parents e2e7fcc + 3760379 commit 9007238
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tach"
version = "0.16.5"
version = "0.16.6"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ If you use the [pre-commit framework](https://github.com/pre-commit/pre-commit),
```yaml
repos:
- repo: https://github.com/gauge-sh/tach-pre-commit
rev: v0.16.5 # change this to the latest tag!
rev: v0.16.6 # change this to the latest tag!
hooks:
- id: tach
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tach"
version = "0.16.5"
version = "0.16.6"
authors = [
{ name = "Caelean Barnes", email = "[email protected]" },
{ name = "Evan Doyle", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion python/tach/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

__version__: str = "0.16.5"
__version__: str = "0.16.6"

__all__ = ["__version__"]
30 changes: 18 additions & 12 deletions python/tach/filesystem/git_ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import os
from dataclasses import dataclass
from pathlib import Path
Expand All @@ -23,17 +24,22 @@ def is_github_actions():


def _get_branch_name(repo: Repo) -> str:
try:
repo_name = repo.active_branch.name
except TypeError as e:
# GHA uses a detached HEAD / shallow clone in actions/checkout@v4, get the branch name from env
if is_github_actions():
repo_name = os.environ.get("GITHUB_HEAD_REF")
if not repo_name:
raise e
else:
raise e
return repo_name
# GHA uses a detached HEAD / shallow clone in actions/checkout@v4, get the branch name from env
if is_github_actions():
return os.environ["GITHUB_HEAD_REF"]
else:
return repo.active_branch.name


def _get_commit(repo: Repo) -> str:
# GHA uses a detached HEAD in actions/checkout@v4, get the commit from the event file
if is_github_actions():
event_path = os.environ["GITHUB_EVENT_PATH"]
with open(event_path) as f:
event_info = json.load(f)
return event_info["pull_request"]["head"]["sha"]
else:
return repo.head.commit.hexsha


def get_current_branch_info(
Expand All @@ -57,7 +63,7 @@ def get_current_branch_info(
# TODO: support slashes or org names
repo_name = repo.remotes.origin.url.split("/")[-1].replace(".git", "")
branch = _get_branch_name(repo)
commit = repo.head.commit.hexsha
commit = _get_commit(repo)
except Exception as e:
raise TachError(f"Failed to determine current branch information!\nError: {e}")

Expand Down

0 comments on commit 9007238

Please sign in to comment.