Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
enciyo committed Jun 9, 2024
1 parent 7f6d92c commit f867ad7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion che.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.0.14
version=1.0.15
python=3.11
21 changes: 8 additions & 13 deletions che/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import stat
import subprocess

from che.intercept.conversation import Conversation
Expand All @@ -9,9 +8,6 @@
__PREF_DIR = "ai/copilot"


def give_permission(file_path):
os.chmod(file_path, 777)


def __author_name():
path = os.path.join(get_config()["project_path"])
Expand All @@ -37,16 +33,15 @@ def create_or_open_file(file_path, mode):
directory, filename = os.path.split(file_path)
if not os.path.exists(directory):
os.makedirs(directory)
give_permission(directory)

if not os.path.exists(file_path):
with open(file_path, "w") as f:
with open(file_path, "w+") as f:
ext = os.path.splitext(filename)[1]
if ext == ".json":
f.write("[]")
else:
f.write("")
give_permission(file_path)

return open(file_path, mode)


Expand All @@ -55,7 +50,7 @@ def get_output_dir():


def create_md_block_from_sample(conversation: Conversation) -> str:
with create_or_open_file(__SAMPLE_MD, "r") as f:
with create_or_open_file(__SAMPLE_MD, "r+") as f:
block = f.readlines()
block = "".join(block)
block = block.replace("{{author_name}}", __author_name())
Expand All @@ -70,20 +65,20 @@ def create_md_file(conversations: dict):
block = "# " + __current_branch() + "\n\n"
for c in conversations:
block += create_md_block_from_sample(Conversation.from_dict(c))
with create_or_open_file(output_file, "w") as f:
with create_or_open_file(output_file, "w+") as f:
f.write(block)


def get_json_files():
output_file = os.path.join(get_output_dir(), __current_branch() + ".json")
with create_or_open_file(output_file, "r") as f:
with create_or_open_file(output_file, "r+") as f:
conversations = json.load(f)
return conversations


def write_to_json_file(conversations: dict):
output_file = os.path.join(get_output_dir(), __current_branch() + ".json")
with create_or_open_file(output_file, "w") as f:
with create_or_open_file(output_file, "w+") as f:
json.dump(conversations, f, indent=2, default=str, ensure_ascii=False)


Expand All @@ -98,13 +93,13 @@ def get_config():
"listen_url": "https://api.githubcopilot.com/chat/completions"
}
)
with open(config_path, "r") as f:
with open(config_path, "r+") as f:
return json.load(f)


def save_config(config):
config_path = os.path.join(os.path.dirname(__file__), "config.json")
with create_or_open_file(config_path, "w") as f:
with create_or_open_file(config_path, "w+") as f:
json.dump(config, f, indent=2, default=str, ensure_ascii=False)


Expand Down

0 comments on commit f867ad7

Please sign in to comment.