gpt-pr 0.6.1__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gpt-pr might be problematic. Click here for more details.
- gpt_pr/__init__.py +3 -0
- {gptpr → gpt_pr}/checkversion.py +22 -19
- gpt_pr/gh.py +44 -0
- {gptpr → gpt_pr}/gitutil.py +5 -5
- gpt_pr/gpt.py +8 -0
- gpt_pr/main.py +117 -0
- gpt_pr/prdata.py +238 -0
- {gptpr → gpt_pr}/test_checkversion.py +44 -38
- {gptpr → gpt_pr}/test_config.py +55 -35
- gpt_pr/test_gh.py +60 -0
- gpt_pr/test_prdata.py +17 -0
- gpt_pr-0.7.1.dist-info/METADATA +286 -0
- gpt_pr-0.7.1.dist-info/RECORD +17 -0
- {gpt_pr-0.6.1.dist-info → gpt_pr-0.7.1.dist-info}/WHEEL +1 -2
- gpt_pr-0.7.1.dist-info/entry_points.txt +4 -0
- gpt_pr-0.6.1.dist-info/METADATA +0 -49
- gpt_pr-0.6.1.dist-info/RECORD +0 -17
- gpt_pr-0.6.1.dist-info/entry_points.txt +0 -3
- gpt_pr-0.6.1.dist-info/top_level.txt +0 -1
- gptpr/__init__.py +0 -0
- gptpr/gh.py +0 -37
- gptpr/main.py +0 -102
- gptpr/prdata.py +0 -199
- gptpr/test_prdata.py +0 -13
- gptpr/version.py +0 -1
- {gptpr → gpt_pr}/config.py +0 -0
- {gptpr → gpt_pr}/consolecolor.py +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
gpt_pr/__init__.py,sha256=Bs14snCQfkRZPxYfLq-haC5mArtZpKcML3Sa9y9LRYs,72
|
|
2
|
+
gpt_pr/checkversion.py,sha256=fY1lLlFDEKY9EFHgMNkxZjPA0WmY2czydIaaIvgt7uc,2428
|
|
3
|
+
gpt_pr/config.py,sha256=jOr95rErnk-MByWtC92bpgY2dyVc6bbrjaVoP61oO-s,2822
|
|
4
|
+
gpt_pr/consolecolor.py,sha256=_JmBMNjIflWMlgP2VkCWu6uQLR9oHBy52uV3TRJJgF4,800
|
|
5
|
+
gpt_pr/gh.py,sha256=JwFRFjwYqO3O3equVJs1FAFTFpG__qEhSkr_-2C3GrI,1238
|
|
6
|
+
gpt_pr/gitutil.py,sha256=yqvpw_pq7Bw_uOcNa4eaUVIFu6YhrK6cjd-74Obtqfk,5996
|
|
7
|
+
gpt_pr/gpt.py,sha256=CSAX9Z6FQOLXOzbLMe_Opqtc3ruDAKTTk7cPqc6Blh0,263
|
|
8
|
+
gpt_pr/main.py,sha256=zl6qeIoKPX-zT-Mt9sGbCQusz5ejoLAdiKLV4MCFpWA,2850
|
|
9
|
+
gpt_pr/prdata.py,sha256=aWPf0cdsdF2EVSEjFqHqZrq1GzPkEPc6jrySiLt6iuU,7583
|
|
10
|
+
gpt_pr/test_checkversion.py,sha256=slw1Tn4H_2QPrKSQfupi5LMIJsDa1fnSU1v5grGX3Ow,4227
|
|
11
|
+
gpt_pr/test_config.py,sha256=J5CSEj8JbKw_57E0IQit5LgmrsCmboe9li2esT2F5pg,3577
|
|
12
|
+
gpt_pr/test_gh.py,sha256=WfZ0GC4C04hk0g0raIDEPODD74AUJcY4BNT3wAYStcQ,1772
|
|
13
|
+
gpt_pr/test_prdata.py,sha256=TF7FZ_PW-NPj3YvC7ICz5NSVQ98JRVWX1lyHfQv3Eow,499
|
|
14
|
+
gpt_pr-0.7.1.dist-info/METADATA,sha256=k8WML4miusXDgbjhfWuqcwfKo9tY081XGpCWJj3dA2M,9082
|
|
15
|
+
gpt_pr-0.7.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
16
|
+
gpt_pr-0.7.1.dist-info/entry_points.txt,sha256=EJAujhCl6OFb9AmBGWRXd5VamvyCObYVtByaGU-sLs4,80
|
|
17
|
+
gpt_pr-0.7.1.dist-info/RECORD,,
|
gpt_pr-0.6.1.dist-info/METADATA
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: gpt-pr
|
|
3
|
-
Version: 0.6.1
|
|
4
|
-
Summary: Automate your GitHub workflow with GPT-PR: an OpenAI powered library for streamlined PR generation.
|
|
5
|
-
Home-page: http://github.com/alissonperez/gpt-pr
|
|
6
|
-
Author: Alisson R. Perez
|
|
7
|
-
Author-email: alissonperez@outlook.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Requires-Python: >=3.7
|
|
10
|
-
Requires-Dist: cffi ==1.15.1
|
|
11
|
-
Requires-Dist: cryptography ==43.0.1
|
|
12
|
-
Requires-Dist: fire ==0.6.0
|
|
13
|
-
Requires-Dist: pycparser ==2.21
|
|
14
|
-
Requires-Dist: wcwidth ==0.2.13
|
|
15
|
-
Requires-Dist: charset-normalizer ==3.3.2 ; python_full_version >= "3.7.0"
|
|
16
|
-
Requires-Dist: prompt-toolkit ==3.0.43 ; python_full_version >= "3.7.0"
|
|
17
|
-
Requires-Dist: openai ==1.14.0 ; python_full_version >= "3.7.1"
|
|
18
|
-
Requires-Dist: exceptiongroup ==1.2.2 ; python_version < "3.11"
|
|
19
|
-
Requires-Dist: cached-property ==1.5.2 ; python_version < "3.8"
|
|
20
|
-
Requires-Dist: importlib-metadata ==6.7.0 ; python_version == "3.7"
|
|
21
|
-
Requires-Dist: six ==1.16.0 ; python_version >= "2.7" and python_version not in "3.0, 3.1, 3.2"
|
|
22
|
-
Requires-Dist: deprecated ==1.2.14 ; python_version >= "2.7" and python_version not in "3.0, 3.1, 3.2, 3.3"
|
|
23
|
-
Requires-Dist: certifi ==2024.8.30 ; python_version >= "3.6"
|
|
24
|
-
Requires-Dist: distro ==1.9.0 ; python_version >= "3.6"
|
|
25
|
-
Requires-Dist: idna ==3.8 ; python_version >= "3.6"
|
|
26
|
-
Requires-Dist: pynacl ==1.5.0 ; python_version >= "3.6"
|
|
27
|
-
Requires-Dist: wrapt ==1.16.0 ; python_version >= "3.6"
|
|
28
|
-
Requires-Dist: annotated-types ==0.5.0 ; python_version >= "3.7"
|
|
29
|
-
Requires-Dist: anyio ==3.7.1 ; python_version >= "3.7"
|
|
30
|
-
Requires-Dist: gitdb ==4.0.11 ; python_version >= "3.7"
|
|
31
|
-
Requires-Dist: gitpython ==3.1.42 ; python_version >= "3.7"
|
|
32
|
-
Requires-Dist: h11 ==0.14.0 ; python_version >= "3.7"
|
|
33
|
-
Requires-Dist: httpcore ==0.17.3 ; python_version >= "3.7"
|
|
34
|
-
Requires-Dist: httpx ==0.24.1 ; python_version >= "3.7"
|
|
35
|
-
Requires-Dist: pydantic ==2.5.3 ; python_version >= "3.7"
|
|
36
|
-
Requires-Dist: pydantic-core ==2.14.6 ; python_version >= "3.7"
|
|
37
|
-
Requires-Dist: pygithub ==2.2.0 ; python_version >= "3.7"
|
|
38
|
-
Requires-Dist: pyjwt[crypto] ==2.8.0 ; python_version >= "3.7"
|
|
39
|
-
Requires-Dist: requests ==2.31.0 ; python_version >= "3.7"
|
|
40
|
-
Requires-Dist: smmap ==5.0.1 ; python_version >= "3.7"
|
|
41
|
-
Requires-Dist: sniffio ==1.3.1 ; python_version >= "3.7"
|
|
42
|
-
Requires-Dist: termcolor ==2.3.0 ; python_version >= "3.7"
|
|
43
|
-
Requires-Dist: tqdm ==4.66.5 ; python_version >= "3.7"
|
|
44
|
-
Requires-Dist: typing-extensions ==4.7.1 ; python_version >= "3.7"
|
|
45
|
-
Requires-Dist: urllib3 ==2.0.7 ; python_version >= "3.7"
|
|
46
|
-
Requires-Dist: zipp ==3.15.0 ; python_version >= "3.7"
|
|
47
|
-
Requires-Dist: inquirerpy ==0.3.4 ; python_version >= "3.7" and python_version < "4.0"
|
|
48
|
-
Requires-Dist: pfzy ==0.3.4 ; python_version >= "3.7" and python_version < "4.0"
|
|
49
|
-
|
gpt_pr-0.6.1.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
gptpr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
gptpr/checkversion.py,sha256=PmbGiYJelecs1Fv2aAZwdr6wn-qDC826nsYI4A6LLvk,2389
|
|
3
|
-
gptpr/config.py,sha256=jOr95rErnk-MByWtC92bpgY2dyVc6bbrjaVoP61oO-s,2822
|
|
4
|
-
gptpr/consolecolor.py,sha256=_JmBMNjIflWMlgP2VkCWu6uQLR9oHBy52uV3TRJJgF4,800
|
|
5
|
-
gptpr/gh.py,sha256=E03xg8UHfZlHJAY-aAYphpgS3xl-FZ2dmI5oBC2XdoA,1136
|
|
6
|
-
gptpr/gitutil.py,sha256=4if59fnTmP01dinmkrhE6jUnDNoNFUx3_m_J5iLMWsU,5967
|
|
7
|
-
gptpr/main.py,sha256=gen_8YXYAUJU0BpzULZ28j9Br6Y9PTqTr9JEm4nwsJI,2694
|
|
8
|
-
gptpr/prdata.py,sha256=Uls18CtkxWlflfHKrB62hT21MTUVabf8JgJ6CxOOccQ,7053
|
|
9
|
-
gptpr/test_checkversion.py,sha256=WtJ3v4MMkFG0Kob0R1wi_nwVhcQFd4mXtKCKZHajEhM,4266
|
|
10
|
-
gptpr/test_config.py,sha256=iL3b-Ypv1TaMQTFb6mrDKw8fPio3WBpMcaFkWbiLdNQ,3369
|
|
11
|
-
gptpr/test_prdata.py,sha256=rSJ-yqOdw-iYdBWyqnA2SXbdrhT8KgIkRTTf9SY1S1g,474
|
|
12
|
-
gptpr/version.py,sha256=baAcEjLSYFIeNZF51tOMmA_zAMhN8HvKael-UU-Ruec,22
|
|
13
|
-
gpt_pr-0.6.1.dist-info/METADATA,sha256=74diVzLL8Bo-aMbH3brqCX-q1KE1NSwmatmZzl9cp-s,2639
|
|
14
|
-
gpt_pr-0.6.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
-
gpt_pr-0.6.1.dist-info/entry_points.txt,sha256=WhcbcQXqo5-IGliYWiYMhop4-Wm7bcH2ljFKLWrmO7c,81
|
|
16
|
-
gpt_pr-0.6.1.dist-info/top_level.txt,sha256=DZcbzlsjh4BD8njGcvhOeCZ83U_oYWgCn0w8qx5--04,6
|
|
17
|
-
gpt_pr-0.6.1.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
gptpr
|
gptpr/__init__.py
DELETED
|
File without changes
|
gptpr/gh.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from github import Github
|
|
3
|
-
from InquirerPy import inquirer
|
|
4
|
-
from gptpr.config import config, config_command_example, CONFIG_README_SECTION
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def _get_gh_token():
|
|
8
|
-
gh_token = config.get_user_config('GH_TOKEN')
|
|
9
|
-
if not gh_token:
|
|
10
|
-
gh_token = os.environ.get('GH_TOKEN')
|
|
11
|
-
|
|
12
|
-
if not gh_token:
|
|
13
|
-
print('Please set "gh_token" config. Just run:',
|
|
14
|
-
config_command_example('gh_token', '[my gh token]'),
|
|
15
|
-
'more about at', CONFIG_README_SECTION)
|
|
16
|
-
exit(1)
|
|
17
|
-
|
|
18
|
-
return gh_token
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
gh = Github(_get_gh_token())
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def create_pr(pr_data, yield_confirmation):
|
|
25
|
-
repo = gh.get_repo(
|
|
26
|
-
f'{pr_data.branch_info.owner}/{pr_data.branch_info.repo}')
|
|
27
|
-
|
|
28
|
-
pr_confirmation = yield_confirmation or inquirer.confirm(
|
|
29
|
-
message="Create GitHub PR?",
|
|
30
|
-
default=True).execute()
|
|
31
|
-
|
|
32
|
-
if pr_confirmation:
|
|
33
|
-
pr = repo.create_pull(title=pr_data.title, body=pr_data.create_body(),
|
|
34
|
-
head=pr_data.branch_info.branch, base=pr_data.branch_info.base_branch)
|
|
35
|
-
print("Pull request created successfully: ", pr.html_url)
|
|
36
|
-
else:
|
|
37
|
-
print('cancelling...')
|
gptpr/main.py
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import fire
|
|
2
|
-
from InquirerPy import inquirer
|
|
3
|
-
|
|
4
|
-
from gptpr.gitutil import get_branch_info
|
|
5
|
-
from gptpr.gh import create_pr
|
|
6
|
-
from gptpr.prdata import get_pr_data
|
|
7
|
-
from gptpr.version import __version__
|
|
8
|
-
from gptpr.config import config, config_command_example, CONFIG_README_SECTION
|
|
9
|
-
from gptpr import consolecolor as cc
|
|
10
|
-
from gptpr.checkversion import check_for_updates
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def run(base_branch='main', yield_confirmation=False, version=False):
|
|
14
|
-
'''
|
|
15
|
-
Create Pull Requests from current branch with base branch (default 'main' branch)
|
|
16
|
-
'''
|
|
17
|
-
|
|
18
|
-
if version:
|
|
19
|
-
print('Current version:', __version__)
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
branch_info = get_branch_info(base_branch, yield_confirmation)
|
|
23
|
-
|
|
24
|
-
if not branch_info:
|
|
25
|
-
exit(0)
|
|
26
|
-
|
|
27
|
-
pr_data = None
|
|
28
|
-
generate_pr_data = True
|
|
29
|
-
while generate_pr_data:
|
|
30
|
-
pr_data = get_pr_data(branch_info)
|
|
31
|
-
print('')
|
|
32
|
-
print('#########################################')
|
|
33
|
-
print(pr_data.to_display())
|
|
34
|
-
print('#########################################')
|
|
35
|
-
print('')
|
|
36
|
-
|
|
37
|
-
if yield_confirmation:
|
|
38
|
-
break
|
|
39
|
-
|
|
40
|
-
generate_pr_data = not inquirer.confirm(
|
|
41
|
-
message="Create PR with this? If 'no', let's try again...",
|
|
42
|
-
default=True).execute()
|
|
43
|
-
|
|
44
|
-
if generate_pr_data:
|
|
45
|
-
print('Generating another PR data...')
|
|
46
|
-
|
|
47
|
-
create_pr(pr_data, yield_confirmation)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def set_config(name, value):
|
|
51
|
-
name = name.upper()
|
|
52
|
-
config.set_user_config(name, value)
|
|
53
|
-
config.persist()
|
|
54
|
-
|
|
55
|
-
print('Config value', cc.bold(name), 'set to', cc.yellow(value))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def get_config(name):
|
|
59
|
-
upper_name = name.upper()
|
|
60
|
-
print('Config value', cc.bold(name), '=', cc.yellow(config.get_user_config(upper_name)))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def reset_config(name):
|
|
64
|
-
upper_name = name.upper()
|
|
65
|
-
config.reset_user_config(upper_name)
|
|
66
|
-
print('Config value', cc.bold(name), '=', cc.yellow(config.get_user_config(upper_name)))
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def print_config():
|
|
70
|
-
print('Config values at', cc.yellow(config.get_filepath()))
|
|
71
|
-
print('')
|
|
72
|
-
print('To set values, just run:', cc.yellow(config_command_example('[config name]', '[value]')))
|
|
73
|
-
print('More about at', cc.yellow(CONFIG_README_SECTION))
|
|
74
|
-
print('')
|
|
75
|
-
current_section = None
|
|
76
|
-
for section, option, value in config.all_values():
|
|
77
|
-
if current_section != section:
|
|
78
|
-
print('')
|
|
79
|
-
current_section = section
|
|
80
|
-
|
|
81
|
-
print(f'[{cc.bold(section)}]', option, '=', cc.yellow(value))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def main():
|
|
85
|
-
check_for_updates()
|
|
86
|
-
|
|
87
|
-
fire.Fire(run)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def run_config():
|
|
91
|
-
check_for_updates()
|
|
92
|
-
|
|
93
|
-
fire.Fire({
|
|
94
|
-
'set': set_config,
|
|
95
|
-
'get': get_config,
|
|
96
|
-
'print': print_config,
|
|
97
|
-
'reset': reset_config
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if __name__ == '__main__':
|
|
102
|
-
main()
|
gptpr/prdata.py
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
from openai import OpenAI
|
|
5
|
-
|
|
6
|
-
from gptpr.gitutil import BranchInfo
|
|
7
|
-
from gptpr.config import config, CONFIG_PROJECT_REPO_URL
|
|
8
|
-
import gptpr.consolecolor as cc
|
|
9
|
-
|
|
10
|
-
TOKENIZER_RATIO = 4
|
|
11
|
-
|
|
12
|
-
DEFAULT_PR_TEMPLATE = ('### Ref. [Link]\n\n## What was done?\n[Fill here]\n\n'
|
|
13
|
-
'## How was it done?\n[Fill here]\n\n'
|
|
14
|
-
'## How was it tested?\n[Fill here with test information from diff content or commits]')
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def _get_pr_template():
|
|
18
|
-
pr_template = DEFAULT_PR_TEMPLATE
|
|
19
|
-
|
|
20
|
-
try:
|
|
21
|
-
github_dir = os.path.join(os.getcwd(), '.github')
|
|
22
|
-
github_files = os.listdir(github_dir)
|
|
23
|
-
pr_template_file = [f for f in github_files if f.lower().startswith('pull_request_template')][0]
|
|
24
|
-
pr_template_file_path = os.path.join(github_dir, pr_template_file)
|
|
25
|
-
|
|
26
|
-
with open(pr_template_file_path, 'r') as f:
|
|
27
|
-
local_pr_template = f.read()
|
|
28
|
-
|
|
29
|
-
if local_pr_template.strip() != '':
|
|
30
|
-
print('Found PR template at:', pr_template_file_path)
|
|
31
|
-
pr_template = local_pr_template
|
|
32
|
-
else:
|
|
33
|
-
print('Empty PR template at:', pr_template_file_path, 'using default template.')
|
|
34
|
-
except Exception:
|
|
35
|
-
print('PR template not found in .github dir. Using default template.')
|
|
36
|
-
|
|
37
|
-
return pr_template
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _get_open_ai_key():
|
|
41
|
-
api_key = config.get_user_config('OPENAI_API_KEY')
|
|
42
|
-
|
|
43
|
-
if not api_key:
|
|
44
|
-
api_key = os.environ.get('OPENAI_API_KEY')
|
|
45
|
-
|
|
46
|
-
if not api_key:
|
|
47
|
-
print('Please set "openai_api_key" config, just run:',
|
|
48
|
-
cc.yellow('gpt-pr-config set openai_api_key [open ai key]'))
|
|
49
|
-
exit(1)
|
|
50
|
-
|
|
51
|
-
return api_key
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _count_tokens(text):
|
|
55
|
-
return len(text.split(' '))
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@dataclass
|
|
59
|
-
class PrData():
|
|
60
|
-
branch_info: BranchInfo
|
|
61
|
-
title: str
|
|
62
|
-
body: str
|
|
63
|
-
|
|
64
|
-
def to_display(self):
|
|
65
|
-
return '\n'.join([
|
|
66
|
-
f'{cc.bold("Repository")}: {cc.yellow(self.branch_info.owner)}/{cc.yellow(self.branch_info.repo)}',
|
|
67
|
-
f'{cc.bold("Title")}: {cc.yellow(self.title)}',
|
|
68
|
-
f'{cc.bold("Branch name")}: {cc.yellow(self.branch_info.branch)}',
|
|
69
|
-
f'{cc.bold("Base branch")}: {cc.yellow(self.branch_info.base_branch)}',
|
|
70
|
-
f'{cc.bold("PR Description")}:\n{self.create_body()}',
|
|
71
|
-
])
|
|
72
|
-
|
|
73
|
-
def create_body(self):
|
|
74
|
-
body = self.body
|
|
75
|
-
|
|
76
|
-
if config.get_user_config('ADD_TOOL_SIGNATURE') == 'true':
|
|
77
|
-
pr_signature = f'Generated by [GPT-PR]({CONFIG_PROJECT_REPO_URL})'
|
|
78
|
-
body += '\n\n---\n\n' + pr_signature
|
|
79
|
-
|
|
80
|
-
return body
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
functions = [
|
|
84
|
-
{
|
|
85
|
-
"name": "create_pr",
|
|
86
|
-
"description": "Creates a Github Pull Request",
|
|
87
|
-
"parameters": {
|
|
88
|
-
"type": "object",
|
|
89
|
-
"properties": {
|
|
90
|
-
"title": {
|
|
91
|
-
"type": "string",
|
|
92
|
-
"description": "PR title, following angular commit convention"
|
|
93
|
-
},
|
|
94
|
-
"description": {
|
|
95
|
-
"type": "string",
|
|
96
|
-
"description": "PR description"
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
"required": ["title", "description"]
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def get_pr_data(branch_info):
|
|
106
|
-
client = OpenAI(api_key=_get_open_ai_key())
|
|
107
|
-
|
|
108
|
-
messages = _get_messages(branch_info)
|
|
109
|
-
|
|
110
|
-
openai_model = config.get_user_config('OPENAI_MODEL')
|
|
111
|
-
print('Using OpenAI model:', cc.yellow(openai_model))
|
|
112
|
-
|
|
113
|
-
chat_completion = client.chat.completions.create(
|
|
114
|
-
messages=messages,
|
|
115
|
-
model=openai_model,
|
|
116
|
-
functions=functions,
|
|
117
|
-
function_call={'name': 'create_pr'},
|
|
118
|
-
temperature=0,
|
|
119
|
-
max_tokens=1000,
|
|
120
|
-
top_p=1,
|
|
121
|
-
frequency_penalty=0,
|
|
122
|
-
presence_penalty=0
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
arguments = _parse_json(chat_completion.choices[0].message.function_call.arguments)
|
|
126
|
-
|
|
127
|
-
return PrData(
|
|
128
|
-
branch_info=branch_info,
|
|
129
|
-
title=arguments['title'],
|
|
130
|
-
body=arguments['description']
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def _get_messages(branch_info):
|
|
135
|
-
system_content = ('You are a development assistant designed to craft Git pull requests '
|
|
136
|
-
'by incorporating information from main and secondary commits, diff changes, '
|
|
137
|
-
'and adhering to a provided PR template. Your output includes a complete PR '
|
|
138
|
-
'template with all necessary details and a suitable PR title. In the '
|
|
139
|
-
'PR description, detail the work accomplished, the methodology employed, '
|
|
140
|
-
'including testing procedures, and list significant changes in bullet points '
|
|
141
|
-
'if they are extensive. Avoid incorporating diff content directly into '
|
|
142
|
-
'the PR description.')
|
|
143
|
-
|
|
144
|
-
messages = [
|
|
145
|
-
{'role': 'system', 'content': system_content},
|
|
146
|
-
]
|
|
147
|
-
|
|
148
|
-
if len(branch_info.highlight_commits) > 0:
|
|
149
|
-
messages.append({'role': 'user', 'content': 'main commits: ' + '\n'.join(branch_info.highlight_commits)})
|
|
150
|
-
messages.append({'role': 'user', 'content': 'secondary commits: ' + '\n'.join(branch_info.commits)})
|
|
151
|
-
else:
|
|
152
|
-
messages.append({'role': 'user', 'content': 'git commits: \n' + '\n'.join(branch_info.commits)})
|
|
153
|
-
|
|
154
|
-
messages.append({'role': 'user', 'content': 'PR template:\n' + _get_pr_template()})
|
|
155
|
-
|
|
156
|
-
joined_messages = '\n'.join([m['content'] for m in messages])
|
|
157
|
-
current_total_tokens = _count_tokens(joined_messages)
|
|
158
|
-
|
|
159
|
-
input_max_tokens = int(config.get_user_config('INPUT_MAX_TOKENS'))
|
|
160
|
-
|
|
161
|
-
if current_total_tokens > input_max_tokens:
|
|
162
|
-
exp_message = (f'Length of {current_total_tokens} tokens for basic prompt '
|
|
163
|
-
f'(description and commits) is greater than max tokens {input_max_tokens} '
|
|
164
|
-
'(config \'input_max_tokens\')')
|
|
165
|
-
raise Exception(exp_message)
|
|
166
|
-
|
|
167
|
-
total_tokens_with_diff = current_total_tokens + _count_tokens(branch_info.diff)
|
|
168
|
-
if total_tokens_with_diff > input_max_tokens:
|
|
169
|
-
print_msg = (f'Length git changes with diff is too big (total is {total_tokens_with_diff}, '
|
|
170
|
-
f'\'input_max_tokens\' config is {input_max_tokens}).')
|
|
171
|
-
print(print_msg, cc.red('Skipping changes diff content...'))
|
|
172
|
-
else:
|
|
173
|
-
messages.append({'role': 'user', 'content': 'Diff changes:\n' + branch_info.diff})
|
|
174
|
-
|
|
175
|
-
return messages
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def _parse_json(content):
|
|
179
|
-
'''
|
|
180
|
-
A bit of a hack to parse the json content from the chat completion
|
|
181
|
-
Sometimes it returns a string with invalid json content (line breaks) that
|
|
182
|
-
makes it hard to parse.
|
|
183
|
-
example:
|
|
184
|
-
|
|
185
|
-
content = '{\n"title": "feat(dependencies): pin dependencies versions",\n"description":
|
|
186
|
-
"### Ref. [Link]\n\n## What was done? ..."\n}'
|
|
187
|
-
'''
|
|
188
|
-
|
|
189
|
-
try:
|
|
190
|
-
content = content.replace('{\n"title":', '{"title":')
|
|
191
|
-
content = content.replace(',\n"description":', ',"description":')
|
|
192
|
-
content = content.replace('\n}', '}')
|
|
193
|
-
content = content.replace('\n', '\\n')
|
|
194
|
-
|
|
195
|
-
return json.loads(content)
|
|
196
|
-
except Exception as e:
|
|
197
|
-
print('Error to decode message:', e)
|
|
198
|
-
print('Content:', content)
|
|
199
|
-
raise e
|
gptpr/test_prdata.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from gptpr.prdata import _parse_json
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_parse_json():
|
|
5
|
-
content = ('{\n"title": "feat(dependencies): pin dependencies '
|
|
6
|
-
'versions",\n"description": "### Ref. [Link]\n\n## What was done? ..."\n}')
|
|
7
|
-
|
|
8
|
-
expected = {
|
|
9
|
-
'title': 'feat(dependencies): pin dependencies versions',
|
|
10
|
-
'description': '### Ref. [Link]\n\n## What was done? ...'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
assert _parse_json(content) == expected, "The function did not return the expected output."
|
gptpr/version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.6.1"
|
{gptpr → gpt_pr}/config.py
RENAMED
|
File without changes
|
{gptpr → gpt_pr}/consolecolor.py
RENAMED
|
File without changes
|