Skip to content

Commit 3158ca2

Browse files
committed
Implement files_editability requests for GitHub
Returns openness and encoding (binary vs text) of CAD files.
1 parent 485a2b7 commit 3158ca2

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

oshminer/GitHub.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,49 @@ async def get_files_editability(project: dict, session) -> dict:
143143
Return a `dict` of files in this repository and an assessment of their
144144
editability based on the `osh-file-types` lists from:
145145
https://gitlab.com/OSEGermany/osh-file-types/
146+
147+
Based on the file list of the repository on its default branch.
146148
"""
147149

148-
filetypes.osh_file_types
150+
# Get complete file list of the repository
151+
file_list: list = await get_file_list(project, session)
152+
153+
# Derive extensions from file list
154+
filenames: list = [{"filename": f, "extension": f.split(".")[-1].lower()} for f in file_list]
155+
# Get a list of files that are not documents (e.g. .md) or data. What's left
156+
# should be mostly CAD files.
157+
cad_filenames: list = [c for c in filenames if c["extension"] not in filetypes.data and c["extension"] not in filetypes.document]
158+
159+
# Get lists of open/closed file extensions
160+
open_file_extensions: list = [o["extension"] for o in filetypes.osh_file_types if o["format"] == "open"]
161+
closed_file_extensions: list = [o["extension"] for o in filetypes.osh_file_types if o["format"] == "proprietary"]
162+
# Get lists of binary and text file extensions
163+
binary_file_extensions: list = [o["extension"] for o in filetypes.osh_file_types if o["encoding"] == "binary"]
164+
text_file_extensions: list = [o["extension"] for o in filetypes.osh_file_types if o["encoding"] == "text"]
165+
166+
# Count number of files in repository that are open, closed, and other
167+
cad_files_openness: dict = {
168+
"open": len([f for f in cad_filenames if f["extension"] in open_file_extensions]),
169+
"closed": len([f for f in cad_filenames if f["extension"] in closed_file_extensions])
170+
}
171+
cad_files_openness["other"]: int = len(cad_filenames) - cad_files_openness["open"] - cad_files_openness["closed"]
172+
173+
# Count number of files in repository that are binary, text, and other
174+
cad_files_encoding: dict = {
175+
"binary": len([f for f in cad_filenames if f["extension"] in binary_file_extensions]),
176+
"text": len([f for f in cad_filenames if f["extension"] in text_file_extensions])
177+
}
178+
cad_files_encoding["other"]: int = len(cad_filenames) - cad_files_encoding["binary"] - cad_files_encoding["text"]
179+
180+
cad_files_count: int = len(cad_filenames)
149181

150182
# Placeholder result
151183
result: dict = {
152-
"files_editability": "Not implemented for GitHub yet."
184+
"files_editability": {
185+
"files_count": cad_files_count,
186+
"files_openness": cad_files_openness,
187+
"files_encoding": cad_files_encoding
188+
}
153189
}
154190

155191
return result

0 commit comments

Comments
 (0)