Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/path.py - fix GIT_REPO_REGEX and calc_repo_path #172

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions terrawrap/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from networkx import DiGraph

GIT_REPO_REGEX = r"URL.*/([\w-]*)(?:\.git)?"
GIT_REPO_REGEX = r"(URL)?.*/([\w-]*)(?:\.git)?"


def get_absolute_path(path: str, root_dir: str = None) -> str:
Expand Down Expand Up @@ -108,7 +108,7 @@ def calc_repo_path(path: str) -> str:
output = byte_output.decode("utf-8", errors="replace")
match = re.search(GIT_REPO_REGEX, output)
if match:
repo_name = match.group(1)
repo_name = match.group(2)
else:
raise RuntimeError("Could not determine git repo name, are we in a git repo?")

Expand Down
2 changes: 1 addition & 1 deletion terrawrap/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Place of record for the package version"""

__version__ = "0.9.30"
__version__ = "0.9.31"
__git_hash__ = "GIT_HASH"
22 changes: 21 additions & 1 deletion test/unit/test_path.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Test path utilities"""
import os
from unittest import TestCase
from unittest.mock import patch, MagicMock

from networkx import DiGraph

from terrawrap.utils.path import get_file_graph
from terrawrap.utils.path import get_file_graph, calc_repo_path


class TestPath(TestCase):
Expand Down Expand Up @@ -64,3 +65,22 @@ def test_get_file_graph(self):
)
self.assertEqual(set(actual.nodes), set(expected.nodes))
self.assertEqual(set(actual.edges), set(expected.edges))

@patch("terrawrap.utils.path.subprocess.check_output")
def test_calc_repo_path(self, check_output_mock: MagicMock):
"""test getting repo path based on repo remote"""
check_output_mock.return_value = b"[email protected]:amplify-education/repo-1.git"
result = calc_repo_path("path/config")
self.assertEqual(result, "repo-1/config")

check_output_mock.return_value = (
b"https://github.com/amplify-education/repo-2.git"
)
result = calc_repo_path("path/config")
self.assertEqual(result, "repo-2/config")

check_output_mock.return_value = (
b"Fetch URL: https://github.com/amplify-education/repo-3.git"
)
result = calc_repo_path("path/config")
self.assertEqual(result, "repo-3/config")
Loading