Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Git Clone repos into their own containing folders #1690

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 self.output_dir / folder / folder_name
domwhewell-sage marked this conversation as resolved.
Show resolved Hide resolved
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()
domwhewell-sage marked this conversation as resolved.
Show resolved Hide resolved
]
), "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
Loading