Skip to content

Commit

Permalink
Merge pull request #1690 from domwhewell-sage/small-git-clone-patch
Browse files Browse the repository at this point in the history
Enhancement: Git Clone repos into their own containing folders
  • Loading branch information
TheTechromancer authored Aug 21, 2024
2 parents 1e04373 + ad6de81 commit ab53ff0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions bbot/modules/git_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ 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:
self.debug(f"Error cloning {url}. STDERR: {repr(e.stderr)}")
return

folder_name = output.stderr.split("Cloning into '")[1].split("'")[0]
return self.output_dir / folder_name
return folder / folder_name
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
4 changes: 2 additions & 2 deletions bbot/test/test_step_2/module_tests/test_module_trufflehog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ab53ff0

Please sign in to comment.