Skip to content

Commit

Permalink
Add: Add a function to split a repository string into owner name tuple
Browse files Browse the repository at this point in the history
GitHub always uses the owner/name combination for defining the
repository. Therefore add a function that converts this repository into
a owner name (space project) tuple.
  • Loading branch information
bjoernricks committed Feb 5, 2024
1 parent d5befa4 commit f01709f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pontos/release/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ def get_next_release_version(
return calculator.next_release_candidate_version(last_release_version)

raise VersionError(f"Unsupported release type {release_type.value}.")


def repository_split(repository: str) -> tuple[str, str]:
"""
Split a GitHub repository (owner/name) into a space, project tuple
"""
splitted_repo = repository.split("/")
if len(splitted_repo) != 2:
raise ValueError(
f"Invalid repository {repository}. Format must be " "owner/name."
)
return splitted_repo[0], splitted_repo[1]
22 changes: 22 additions & 0 deletions tests/release/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
find_signing_key,
get_git_repository_name,
get_next_release_version,
repository_split,
)
from pontos.testing import temp_git_repository
from pontos.version import VersionError
Expand Down Expand Up @@ -293,3 +294,24 @@ def test_release_version_with_invalid_release_type(self):
release_type=ReleaseType.ALPHA,
release_version=release_version,
)


class RepositorySplitTestCase(unittest.TestCase):
def test_invalid_repository(self):
with self.assertRaisesRegex(
ValueError,
r"Invalid repository foo/bar/baz. Format must be owner/name.",
):
repository_split("foo/bar/baz")

with self.assertRaisesRegex(
ValueError,
r"Invalid repository foo_bar_baz. Format must be owner/name.",
):
repository_split("foo_bar_baz")

def test_repository(self):
space, project = repository_split("foo/bar")

self.assertEqual(space, "foo")
self.assertEqual(project, "bar")

0 comments on commit f01709f

Please sign in to comment.