Skip to content

Commit 6e736a8

Browse files
committed
refactor: clone repo with PyDriller
1 parent 354c25f commit 6e736a8

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

code2DFD.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Author: Simon Schneider, 2023
44
# Contact: simon.schneider@tuhh.de
5-
5+
import os
66
from configparser import ConfigParser
77
from datetime import datetime
88
import argparse
@@ -11,7 +11,7 @@
1111
import core.dfd_extraction as dfd_extraction
1212
from output_generators.logger import logger
1313
import tmp.tmp as tmp
14-
from core.file_interaction import get_output_path, get_local_path, clone_repo
14+
from core.file_interaction import get_output_path, clone_repo
1515

1616
CONFIG_SECTIONS = ["Analysis Settings", "Repository", "Technology Profiles", "DFD"]
1717
COMMUNICATIONS_TECH_LIST = '[("RabbitMQ", "rmq"), ("Kafka", "kfk"), ("RestTemplate", "rst"),\
@@ -42,10 +42,10 @@ def api_invocation(path: str) -> dict:
4242
repo_path = str(path)
4343
tmp.tmp_config.set("Repository", "path", repo_path)
4444

45-
local_path = get_local_path(repo_path)
45+
local_path = os.path.join(os.getcwd(), "analysed_repositories", *repo_path.split("/")[1:])
4646
tmp.tmp_config.set("Repository", "local_path", local_path)
4747

48-
clone_repo(repo_path, local_path)
48+
clone_repo(repo_path, local_path) # TODO use Pydriller
4949

5050
# Call extraction
5151
codeable_models, traceability = dfd_extraction.perform_analysis()
@@ -69,6 +69,8 @@ def main():
6969
parser.add_argument("--repo_path", type=str, help="Path to the repository as 'repository/path'")
7070
parser.add_argument("--development_mode", action='store_true', help="Switch on development mode")
7171
parser.add_argument("--commit", type=str, help="Analyze repository at this commit")
72+
# TODO add cli for url
73+
# TODO add cli for local path
7274
now = datetime.now()
7375
start_time = now.strftime("%H:%M:%S")
7476

@@ -98,13 +100,13 @@ def main():
98100
tmp.tmp_config.set("Analysis Settings", "development_mode", "True")
99101

100102
repo_path = tmp.tmp_config.get("Repository", "path")
101-
local_path = get_local_path(repo_path)
102-
clone_repo(repo_path, local_path) # TODO use PyDriller to clone repo
103-
tmp.tmp_config.set("Repository", "local_path", local_path)
104-
tmp.tmp_config.set("Analysis Settings", "output_path", get_output_path(repo_path))
103+
local_path = os.path.join(os.getcwd(), "analysed_repositories")
104+
url_path = tmp.tmp_config.get("Repository", "url")
105105

106-
repository = Repository(path_to_repo=local_path)
107-
with repository._prep_repo(local_path) as git_repo:
106+
os.makedirs(local_path, exist_ok=True)
107+
repository = Repository(path_to_repo=url_path, clone_repo_to=local_path)
108+
with repository._prep_repo(url_path) as git_repo:
109+
tmp.tmp_config.set("Repository", "local_path", str(git_repo.path))
108110
commit = head = git_repo.get_head().hash[:7]
109111
if args.commit is not None:
110112
commit = args.commit[:7]

config/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[Repository]
22
path = apssouza22/java-microservice
3+
url = https://github.com/apssouza22/java-microservice
34
;path = callistaenterprise/blog-microservices
45
;path = fernandoabcampos/spring-netflix-oss-microservices
56
;path = georgwittberger/apache-spring-boot-microservice-example

core/file_interaction.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ def get_output_path(repo_path: str, commit: str = None) -> str:
2828
else:
2929
return os.path.join(os.getcwd(), 'code2DFD_output', repo_path, commit)
3030

31-
32-
def get_local_path(repo_path: str) -> str:
33-
return os.path.join(os.getcwd(), "analysed_repositories", *repo_path.split("/")[1:])
34-
35-
3631
def clone_repo(repo_path, local_path):
3732
# Create analysed_repositories folder in case it doesn't exist yet (issue #2)
3833
os.makedirs(os.path.join(os.getcwd(), "analysed_repositories"), exist_ok=True)

0 commit comments

Comments
 (0)