Skip to content

Commit 2b80f07

Browse files
author
Maximilian Karl
committed
update ER and resolve bug
1 parent 1ee58eb commit 2b80f07

File tree

6 files changed

+45
-70
lines changed

6 files changed

+45
-70
lines changed

docs/ER_diagram/ER_diagram.drawio

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/ER_diagram/ER_diagram.png

68.7 KB
Loading

github2pandas/core.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ class Files():
230230
Methods
231231
-------
232232
to_list()
233-
Returns a list of all filenames.
233+
Returns a list of all pandas filenames.
234234
to_dict()
235-
Returns a dict with the folder as key and the list of all filenames as value.
235+
Returns a dict with the folder as key and the list of all pandas filenames as value.
236236
237237
"""
238238
DATA_DIR = ""
@@ -242,34 +242,40 @@ def to_list(cls) -> list:
242242
"""
243243
to_list(cls)
244244
245-
Returns a list of all filenames.
245+
Returns a list of all pandas filenames.
246246
247247
Returns
248248
-------
249249
list
250-
List of all filenames.
250+
List of all pandas filenames.
251251
252252
"""
253253
filenames = []
254254
for var, value in vars(cls).items():
255-
if isinstance(value,str) and not "DIR" in var and not var.startswith("__"):
256-
filenames.append(value)
255+
if isinstance(value,str):
256+
if value.endswith(".p") and not var.startswith("__"):
257+
filenames.append(value)
258+
else:
259+
if hasattr(value, "to_list"):
260+
for item in value.to_list():
261+
filenames.append(item)
257262
return filenames
258263

259264
@classmethod
260265
def to_dict(cls) -> dict:
261266
"""
262267
to_dict(cls)
263268
264-
Returns a dict with the folder as key and the list of all filenames as value.
269+
Returns a dict with the folder as key and the list of all pandas filenames as value.
265270
266271
Returns
267272
-------
268273
dict
269-
Dictionary with the folder as key and the list of all filenames as value.
274+
Dictionary with the folder as key and the list of all pandas filenames as value.
270275
271276
"""
272277
return {cls.DATA_DIR: cls.to_list()}
278+
273279

274280
class UserFiles(Files):
275281
"""

github2pandas/github2pandas.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,12 @@ def __init__(self, git_releases: bool = True, issues_params: Issues.Params = Iss
113113
self.version = version
114114
self.workflows_params = workflows_params
115115

116-
class Files():
116+
class Files(Core.Files):
117117
"""
118118
A file class that holds all file names and the folder name.
119119
120120
Attributes
121121
----------
122-
DATA_DIR : str
123-
Folder name for this module.
124122
REPOS : str
125123
Filename of the repos json file.
126124
GIT_RELEASES : GitReleases.Files
@@ -135,8 +133,8 @@ class Files():
135133
Folder and files for version.
136134
WORKFLOWS : Workflows.Files
137135
Folder and files for workflows.
138-
CORE : Core.Files
139-
Folder and files for core.
136+
USER : Core.UserFiles
137+
User pandas files.
140138
141139
Methods
142140
-------
@@ -153,48 +151,27 @@ class Files():
153151
REPOSITORY = Repository.Files
154152
VERSION = Version.Files
155153
WORKFLOWS = Workflows.Files
156-
CORE = Core.Files
154+
USER = Core.UserFiles
157155

158-
@staticmethod
159-
def to_list() -> list:
156+
@classmethod
157+
def to_dict(cls) -> dict:
160158
"""
161-
to_list()
162-
163-
Returns a list of all filenames.
159+
to_dict(cls)
164160
165-
Returns
166-
-------
167-
list
168-
List of all filenames.
169-
170-
"""
171-
return [
172-
GitHub2Pandas.Files.GIT_RELEASES,
173-
GitHub2Pandas.Files.ISSUES,
174-
GitHub2Pandas.Files.PULL_REQUESTS,
175-
GitHub2Pandas.Files.REPOSITORY,
176-
GitHub2Pandas.Files.VERSION,
177-
GitHub2Pandas.Files.WORKFLOWS,
178-
GitHub2Pandas.Files.CORE
179-
]
180-
181-
@staticmethod
182-
def to_dict() -> dict:
183-
"""
184-
to_dict()
185-
186-
Returns a dict with the folder as key and the list of all filenames as value.
161+
Returns a dict with the folder as key and the list of all pandas filenames as value.
187162
188163
Returns
189164
-------
190165
dict
191-
Dictionary with the folder as key and the list of all filenames as value.
166+
Dictionary with the folder as key and the list of all pandas filenames as value.
192167
193168
"""
194-
d = {}
195-
for files in GitHub2Pandas.Files.to_list():
196-
d.update(files.to_dict())
197-
return d
169+
files = {}
170+
for var, value in vars(cls).items():
171+
if not isinstance(value,str):
172+
if hasattr(value, "DATA_DIR"):
173+
files[value.DATA_DIR] = value.to_list()
174+
return files
198175

199176
def __init__(self, github_token: str, data_root_dir: Path, request_maximum: int = 40000, log_level: int = logging.INFO) -> None:
200177
"""
@@ -537,7 +514,7 @@ def save_tables_to_excel(repo_data_dir: Path, filename: str = "GitHub2Pandas") -
537514
writer = pd.ExcelWriter(Path(repo_data_dir,f'{filename}.xlsx'), engine='xlsxwriter')
538515
for folder, files in GitHub2Pandas.Files.to_dict().items():
539516
for file in files:
540-
if not isinstance(file,dict):
517+
if file.endswith(".p"):
541518
df = GitHub2Pandas.get_pandas_data_frame(repo_data_dir,folder,file)
542519
df.to_excel(writer, sheet_name=file[:-2])
543520
writer.save()

github2pandas/pull_requests.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,6 @@ class Files(Core.Files):
115115
PULL_REQUESTS_REACTIONS = "PullRequestsReactions.p"
116116
REVIEWS = "Reviews.p"
117117

118-
@staticmethod
119-
def to_list() -> list:
120-
return [
121-
PullRequests.Files.PULL_REQUESTS,
122-
PullRequests.Files.REVIEWS_COMMENTS,
123-
PullRequests.Files.PULL_REQUESTS_REACTIONS,
124-
PullRequests.Files.REVIEWS
125-
]
126-
127-
@staticmethod
128-
def to_dict() -> dict:
129-
return {PullRequests.Files.DATA_DIR: PullRequests.Files.to_list()}
130-
131118
def __init__(self, github_connection: Github, repo: GitHubRepository, data_root_dir: Path, request_maximum: int = 40000, log_level: int = logging.INFO) -> None:
132119
"""
133120
__init__(self, github_connection, repo, data_root_dir, request_maximum, log_level)
@@ -292,7 +279,7 @@ def generate_pandas_tables(self, check_for_updates: bool = False, params: Params
292279
number = int(issues_df.loc[count,"number"])
293280
pull_request = self.save_api_call(self.repo.get_pull, number)
294281
self.extract_pull_request(pull_request, params)
295-
if params.review_comment:
282+
if params.review_comments:
296283
# extract comments
297284
self.extract_with_updated_and_since(
298285
self.repo.get_pulls_comments,
@@ -302,7 +289,7 @@ def generate_pandas_tables(self, check_for_updates: bool = False, params: Params
302289
if extract_pull_requests:
303290
pull_request_df = DataFrame(self.__pull_request_list)
304291
self.save_pandas_data_frame(PullRequests.Files.PULL_REQUESTS, pull_request_df)
305-
if params.review_comment:
292+
if params.review_comments:
306293
review_comment_df = DataFrame(self.__review_comment_list)
307294
self.save_pandas_data_frame(PullRequests.Files.REVIEWS_COMMENTS, review_comment_df)
308295
if params.reviews:
@@ -357,7 +344,7 @@ def extract_pull_request(self, pull_request: GitHubPullRequest, params: Params)
357344
for i in range(self.request_maximum):
358345
try:
359346
commit = self.get_save_api_data(commits, i)
360-
pull_request_data["commits"].append(commit.sha)
347+
pull_request_data["commit_shas"].append(commit.sha)
361348
except IndexError:
362349
break
363350
self.__pull_request_list.append(pull_request_data)

tests/test_github2pandas.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from github2pandas.core import Core
88
from github2pandas.github2pandas import GitHub2Pandas
99

10-
class TestPullRequests(unittest.TestCase):
10+
class TestGitHub2Pandas(unittest.TestCase):
1111
"""
1212
Test case for GitHub2Pandas class.
1313
"""
@@ -21,13 +21,11 @@ class TestPullRequests(unittest.TestCase):
2121
data_root_dir = Path("test_data")
2222
log_level = logging.DEBUG
2323

24-
def __init__(self, methodName: str = ...) -> None:
24+
def __init__(self, methodName: str = "...") -> None:
2525
super().__init__(methodName)
2626
if self.data_root_dir.exists() and self.data_root_dir.is_dir():
2727
shutil.rmtree(self.data_root_dir, onerror=Core.file_error_handling)
2828
self.data_root_dir.mkdir(parents=True, exist_ok=True)
29-
print(Core.UserFiles.to_list())
30-
print(Core.UserFiles.to_dict())
3129
pass
3230

3331
def test_get_repository_information(self):
@@ -55,8 +53,15 @@ def test_get_all_data_frames(self):
5553
repo_data_dir = Path(self.data_root_dir,self.git_repo_owner,self.git_repo_name)
5654
for files in GitHub2Pandas.Files.to_list():
5755
for file in files.to_list():
58-
if isinstance(file, str):
56+
if file.endswith(".p"):
5957
df = GitHub2Pandas.get_pandas_data_frame(repo_data_dir, files.DATA_DIR, file)
6058

6159
if __name__ == "__main__":
62-
unittest.main()
60+
#unittest.main()
61+
files = GitHub2Pandas.Files.to_list()
62+
files = GitHub2Pandas.Files.to_dict()
63+
data_root_dir = Path("test_data")
64+
git_repo_name = "github2pandas"
65+
git_repo_owner = "TUBAF-IFI-DiPiT"
66+
GitHub2Pandas.save_tables_to_excel(Path(data_root_dir,git_repo_owner,git_repo_name))
67+
pass

0 commit comments

Comments
 (0)