Skip to content

Commit

Permalink
Merge pull request #172 from amplify-education/fix/calc_repo_path_regex
Browse files Browse the repository at this point in the history
utils/path.py - fix `GIT_REPO_REGEX` and `calc_repo_path`
  • Loading branch information
kkozik-amplify authored Oct 23, 2023
2 parents cfe01c6 + 2adb8e2 commit 58da07a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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")

0 comments on commit 58da07a

Please sign in to comment.