feat(create): scaffold repositories via templates with preview and mirror setup
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled

https://chatgpt.com/share/693f5bdb-1780-800f-a772-0ecf399627fc
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-15 01:52:38 +01:00
parent 9e3ce34626
commit 2c15a4016b
14 changed files with 605 additions and 125 deletions

View File

@@ -0,0 +1,62 @@
from __future__ import annotations
import unittest
from pkgmgr.actions.repository.create import (
RepoParts,
_parse_identifier,
_parse_git_url,
_strip_git_suffix,
_split_host_port,
)
class TestRepositoryCreateParsing(unittest.TestCase):
def test_strip_git_suffix(self) -> None:
self.assertEqual(_strip_git_suffix("repo.git"), "repo")
self.assertEqual(_strip_git_suffix("repo"), "repo")
def test_split_host_port(self) -> None:
self.assertEqual(_split_host_port("example.com"), ("example.com", None))
self.assertEqual(_split_host_port("example.com:2222"), ("example.com", "2222"))
self.assertEqual(_split_host_port("example.com:"), ("example.com", None))
def test_parse_identifier_plain(self) -> None:
parts = _parse_identifier("github.com/owner/repo")
self.assertIsInstance(parts, RepoParts)
self.assertEqual(parts.host, "github.com")
self.assertEqual(parts.port, None)
self.assertEqual(parts.owner, "owner")
self.assertEqual(parts.name, "repo")
def test_parse_identifier_with_port(self) -> None:
parts = _parse_identifier("gitea.example.com:2222/org/repo")
self.assertEqual(parts.host, "gitea.example.com")
self.assertEqual(parts.port, "2222")
self.assertEqual(parts.owner, "org")
self.assertEqual(parts.name, "repo")
def test_parse_git_url_scp_style(self) -> None:
parts = _parse_git_url("git@github.com:owner/repo.git")
self.assertEqual(parts.host, "github.com")
self.assertEqual(parts.port, None)
self.assertEqual(parts.owner, "owner")
self.assertEqual(parts.name, "repo")
def test_parse_git_url_https(self) -> None:
parts = _parse_git_url("https://github.com/owner/repo.git")
self.assertEqual(parts.host, "github.com")
self.assertEqual(parts.port, None)
self.assertEqual(parts.owner, "owner")
self.assertEqual(parts.name, "repo")
def test_parse_git_url_ssh_with_port(self) -> None:
parts = _parse_git_url("ssh://git@gitea.example.com:2222/org/repo.git")
self.assertEqual(parts.host, "gitea.example.com")
self.assertEqual(parts.port, "2222")
self.assertEqual(parts.owner, "org")
self.assertEqual(parts.name, "repo")
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,35 @@
from __future__ import annotations
import unittest
from unittest.mock import patch
from pkgmgr.actions.repository.scaffold import render_default_templates
class TestScaffoldRenderPreview(unittest.TestCase):
def test_render_preview_does_not_write(self) -> None:
with (
patch("pkgmgr.actions.repository.scaffold._templates_dir", return_value="/tpl"),
patch("pkgmgr.actions.repository.scaffold.os.path.isdir", return_value=True),
patch("pkgmgr.actions.repository.scaffold.os.walk", return_value=[("/tpl", [], ["README.md.j2"])]),
patch("pkgmgr.actions.repository.scaffold.os.path.relpath", return_value="README.md.j2"),
patch("pkgmgr.actions.repository.scaffold.os.makedirs") as mk,
patch("pkgmgr.actions.repository.scaffold.open", create=True) as op,
patch("pkgmgr.actions.repository.scaffold.Environment") as env_cls,
):
env = env_cls.return_value
env.get_template.return_value.render.return_value = "X"
render_default_templates(
"/repo",
context={"repository": "x"},
preview=True,
)
mk.assert_not_called()
op.assert_not_called()
env.get_template.assert_not_called()
if __name__ == "__main__":
unittest.main()