From 73739ca5ba3cb5afcc41cef40526e889188f4d33 Mon Sep 17 00:00:00 2001 From: Dominic Whewell <122788350+domwhewell-sage@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:47:53 +0100 Subject: [PATCH 1/4] Split out the owner from the repository URL and use that as the containing folder --- bbot/modules/git_clone.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bbot/modules/git_clone.py b/bbot/modules/git_clone.py index dbf24e91e..9f0441304 100644 --- a/bbot/modules/git_clone.py +++ b/bbot/modules/git_clone.py @@ -46,11 +46,14 @@ async def handle_event(self, event): ) async def clone_git_repository(self, repository_url): + owner = repository_url.split("/")[-2] + folder = self.output_dir / owner + self.helpers.mkdir(folder) if self.api_key: url = repository_url.replace("https://github.com", f"https://user:{self.api_key}@github.com") else: url = repository_url - command = ["git", "-C", self.output_dir, "clone", url] + command = ["git", "-C", folder, "clone", url] try: output = await self.run_process(command, env={"GIT_TERMINAL_PROMPT": "0"}, check=True) except CalledProcessError as e: @@ -58,4 +61,4 @@ async def clone_git_repository(self, repository_url): return folder_name = output.stderr.split("Cloning into '")[1].split("'")[0] - return self.output_dir / folder_name + return self.output_dir / folder / folder_name From ff53e242522feaf2c1cb773be20bccc7ae27322f Mon Sep 17 00:00:00 2001 From: Dominic Whewell <122788350+domwhewell-sage@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:34:53 +0100 Subject: [PATCH 2/4] Forgot to update the test --- bbot/test/test_step_2/module_tests/test_module_git_clone.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bbot/test/test_step_2/module_tests/test_module_git_clone.py b/bbot/test/test_step_2/module_tests/test_module_git_clone.py index cd59f5dc2..15bc54fb3 100644 --- a/bbot/test/test_step_2/module_tests/test_module_git_clone.py +++ b/bbot/test/test_step_2/module_tests/test_module_git_clone.py @@ -196,7 +196,7 @@ def check(self, module_test, events): e for e in events if e.type == "FILESYSTEM" - and "git_repos/test_keys" in e.data["path"] + and "git_repos/.bbot_test/test_keys" in e.data["path"] and "git" in e.tags and e.scope_distance == 1 ] From d5a881b917c4b7c3e3c6afcbd6bd8d9172de9482 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Wed, 21 Aug 2024 17:14:54 +0100 Subject: [PATCH 3/4] More test corrections --- bbot/test/test_step_2/module_tests/test_module_trufflehog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bbot/test/test_step_2/module_tests/test_module_trufflehog.py b/bbot/test/test_step_2/module_tests/test_module_trufflehog.py index da72ff354..7dde0d38a 100644 --- a/bbot/test/test_step_2/module_tests/test_module_trufflehog.py +++ b/bbot/test/test_step_2/module_tests/test_module_trufflehog.py @@ -868,7 +868,7 @@ def check(self, module_test, events): [ e for e in filesystem_events - if e.data["path"].endswith("/git_repos/test_keys") and Path(e.data["path"]).is_dir() + if e.data["path"].endswith("/git_repos/.bbot_test/test_keys") and Path(e.data["path"]).is_dir() ] ), "Test keys repo dir does not exist" assert 1 == len( @@ -915,7 +915,7 @@ def check(self, module_test, events): [ e for e in filesystem_events - if e.data["path"].endswith("/git_repos/test_keys") and Path(e.data["path"]).is_dir() + if e.data["path"].endswith("/git_repos/.bbot_test/test_keys") and Path(e.data["path"]).is_dir() ] ), "Test keys repo dir does not exist" assert 1 == len( From ad6de812687f0761144a4ce8391a03072ae0ceb3 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Wed, 21 Aug 2024 18:46:41 +0100 Subject: [PATCH 4/4] removed unnecessary `self.output_dir` --- bbot/modules/git_clone.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bbot/modules/git_clone.py b/bbot/modules/git_clone.py index 9f0441304..4b64ee480 100644 --- a/bbot/modules/git_clone.py +++ b/bbot/modules/git_clone.py @@ -61,4 +61,4 @@ async def clone_git_repository(self, repository_url): return folder_name = output.stderr.split("Cloning into '")[1].split("'")[0] - return self.output_dir / folder / folder_name + return folder / folder_name