-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit.py
53 lines (45 loc) · 1.89 KB
/
git.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import requests
from utils import Utils
class Git:
def __init__(
self, repo_owner, repo_name, working_dir=f"./.{Utils.generate_random_name(20)}"
):
self.working_dir = working_dir
self.repo_name = repo_name
self.repo_owner = repo_owner
self.branch_name = f"edit-{Utils.generate_random_name()}"
self.working_dir = working_dir
self.github_token = Utils.get_env_variable(
"GITHUB_TOKEN", "Please enter your github token (hit enter): "
)
def clone(self):
os.system(
f"git clone https://github.com/{self.repo_owner}/{self.repo_name}.git {self.working_dir}/{self.repo_name}"
)
def create_pull_request(self):
os.chdir(f"{self.working_dir}/{self.repo_name}")
os.system(f"git checkout -b {self.branch_name}")
os.system("git add .")
os.system('git commit -m "Edit markdown documents"')
os.system(f"git push --set-upstream origin {self.branch_name}")
headers = {
"Authorization": f"token {self.github_token}",
"Accept": "application/vnd.github.v3+json",
}
data = {
"title": "Update markdown documents",
"head": self.branch_name,
"base": "main",
"draft": True,
"body": """**LLM-Assisted Editing Enhancement**
To make the most of your modifications or further developments, it's advisable to use the specific branch from which this Pull Request (PR) originates. This will ensure you have a solid and up-to-date foundation for your tweaks and enhancements.
_Using [Markdown LLM Corrector](https://github.com/vburckhardt/markdown-llm-corrector)._
""",
}
response = requests.post(
f"https://api.github.com/repos/{self.repo_owner}/{self.repo_name}/pulls",
headers=headers,
json=data,
)
return response