Skip to content

Commit

Permalink
𝌊 some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexxkara committed Nov 5, 2024
1 parent 15bf42a commit dc56fea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
3 changes: 3 additions & 0 deletions app/service/app_generator_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import time

from openai import OpenAI
from openai.types.chat.parsed_chat_completion import ParsedChatCompletion
Expand Down Expand Up @@ -85,6 +86,8 @@ def create_app(self) -> None:
response_format=responses.StructureResponse, max_tokens=500)

for file in structure.file:
time.sleep(100)

file_path = file.path + file.filename

code: CodeResponse = self.send_request(request=prompts.code_prompt.format(file_path=file_path),
Expand Down
46 changes: 28 additions & 18 deletions app/service/github_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from github import Github
from github import Github, GithubException

from app.models.github_client_model import GitHubClientModel

Expand Down Expand Up @@ -29,21 +29,31 @@ def upload_file(self, local_file_path: str, commit_message: str, remote_dir="")
print(f"Failed to upload {remote_file_path}: {e}")

def delete_all_files(self):
contents = self.repo.get_contents("", ref=self.branch)
commit_message = "Delete file in repository"
files_to_delete = []

while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(self.repo.get_contents(file_content.path, ref=self.branch))
try:
contents = self.repo.get_contents("", ref=self.branch)

if not contents:
print("Repository is empty. Nothing to delete.")
return

files_to_delete = []

while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(self.repo.get_contents(file_content.path, ref=self.branch))
else:
files_to_delete.append(file_content)

for file_content in files_to_delete:
self.repo.delete_file(
path=file_content.path,
message=f"Deleted file {file_content.path}",
sha=file_content.sha,
branch=self.branch
)
except GithubException as e:
if e.status == 404:
print("Repository is empty. Nothing to delete.")
else:
files_to_delete.append(file_content)

for file_content in files_to_delete:
self.repo.delete_file(
path=file_content.path,
message=commit_message,
sha=file_content.sha,
branch=self.branch
)
print(f"An error occurred: {e}")

0 comments on commit dc56fea

Please sign in to comment.