forked from litch/ai-school-tech-writer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (34 loc) · 1.31 KB
/
main.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
import os
from github import Github
from utility import *
def main():
# Initialize GitHub API with token
g = Github(os.getenv('GITHUB_TOKEN'))
# Get the repo path and PR number from the environment variables
repo_path = os.getenv('REPO_PATH')
pull_request_number = int(os.getenv('PR_NUMBER'))
# Get the repo object
repo = g.get_repo(repo_path)
# Fetch README content (assuming README.md)
readme_content = repo.get_contents("README.md")
# print(readme_content)
# Fetch pull request by number
pull_request = repo.get_pull(pull_request_number)
# Get the diffs of the pull request
pull_request_diffs = [
{
"filename": file.filename,
"patch": file.patch
}
for file in pull_request.get_files()
]
# Get the commit messages associated with the pull request
commit_messages = [commit.commit.message for commit in pull_request.get_commits()]
# Format data for OpenAI prompt
prompt = format_data_for_openai(pull_request_diffs, readme_content, commit_messages)
# Call OpenAI to generate the updated README content
updated_readme = call_openai(prompt)
# Create PR for Updated PR
update_readme_and_create_pr(repo, updated_readme, readme_content.sha)
if __name__ == '__main__':
main()