gpt-pr 0.5.0__py3-none-any.whl → 0.7.2__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.
@@ -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=Ud0TytYnKZ8x6Ycr3rSMrDX1wuRhGTHFI_s_nHlv8Qg,6380
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=dsvPecykJOSjhn6Ki-jliSi0oraVISAaUbcJJIkHxzE,7128
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.2.dist-info/METADATA,sha256=8nTThMTv8uvyrD12WaDdxFVxrMe4arLGpgvHqETilM4,9039
15
+ gpt_pr-0.7.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
16
+ gpt_pr-0.7.2.dist-info/entry_points.txt,sha256=EJAujhCl6OFb9AmBGWRXd5VamvyCObYVtByaGU-sLs4,80
17
+ gpt_pr-0.7.2.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ gpt-pr=gpt_pr.main:main
3
+ gpt-pr-config=gpt_pr.main:run_config
4
+
@@ -1,49 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: gpt-pr
3
- Version: 0.5.0
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.0
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: idna ==3.7 ; python_version >= "3.5"
24
- Requires-Dist: certifi ==2024.7.4 ; python_version >= "3.6"
25
- Requires-Dist: distro ==1.9.0 ; 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.4 ; 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
-
@@ -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=XwHwveyVmeFoHqHpwZXI2BF1Ac3nT1hnEpclmP2TYhQ,2677
4
- gptpr/consolecolor.py,sha256=_JmBMNjIflWMlgP2VkCWu6uQLR9oHBy52uV3TRJJgF4,800
5
- gptpr/gh.py,sha256=uSWY_TzbrAM00neOBkyfV5vxDO4FzMtIrs-Zczp-Tck,1127
6
- gptpr/gitutil.py,sha256=NBD3iRnbFEPRU47w7c5TowwtZieDYkU4zybvv0PoOU0,5783
7
- gptpr/main.py,sha256=gen_8YXYAUJU0BpzULZ28j9Br6Y9PTqTr9JEm4nwsJI,2694
8
- gptpr/prdata.py,sha256=h3RvlfGcAXWUSxy6wfVqem4uxk53gxpvSrmj7xxuYUc,6749
9
- gptpr/test_checkversion.py,sha256=WtJ3v4MMkFG0Kob0R1wi_nwVhcQFd4mXtKCKZHajEhM,4266
10
- gptpr/test_config.py,sha256=ucqbj2mbee4fDK1JwXVY_FfnPXMeRA3VMM6m4-x7OTU,3270
11
- gptpr/test_prdata.py,sha256=rSJ-yqOdw-iYdBWyqnA2SXbdrhT8KgIkRTTf9SY1S1g,474
12
- gptpr/version.py,sha256=LBK46heutvn3KmsCrKIYu8RQikbfnjZaj2xFrXaeCzQ,22
13
- gpt_pr-0.5.0.dist-info/METADATA,sha256=Dt_i-Of-R8hHlBDFWGm2rzWij5diWPVE6cT2FKeXd1k,2638
14
- gpt_pr-0.5.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
15
- gpt_pr-0.5.0.dist-info/entry_points.txt,sha256=WhcbcQXqo5-IGliYWiYMhop4-Wm7bcH2ljFKLWrmO7c,81
16
- gpt_pr-0.5.0.dist-info/top_level.txt,sha256=DZcbzlsjh4BD8njGcvhOeCZ83U_oYWgCn0w8qx5--04,6
17
- gpt_pr-0.5.0.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- gpt-pr = gptpr.main:main
3
- gpt-pr-config = gptpr.main:run_config
@@ -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.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,190 +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
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.body}',
71
- ])
72
-
73
-
74
- functions = [
75
- {
76
- "name": "create_pr",
77
- "description": "Creates a Github Pull Request",
78
- "parameters": {
79
- "type": "object",
80
- "properties": {
81
- "title": {
82
- "type": "string",
83
- "description": "PR title, following angular commit convention"
84
- },
85
- "description": {
86
- "type": "string",
87
- "description": "PR description"
88
- },
89
- },
90
- "required": ["title", "description"]
91
- },
92
- }
93
- ]
94
-
95
-
96
- def get_pr_data(branch_info):
97
- client = OpenAI(api_key=_get_open_ai_key())
98
-
99
- messages = _get_messages(branch_info)
100
-
101
- openai_model = config.get_user_config('OPENAI_MODEL')
102
- print('Using OpenAI model:', cc.yellow(openai_model))
103
-
104
- chat_completion = client.chat.completions.create(
105
- messages=messages,
106
- model=openai_model,
107
- functions=functions,
108
- function_call={'name': 'create_pr'},
109
- temperature=0,
110
- max_tokens=1000,
111
- top_p=1,
112
- frequency_penalty=0,
113
- presence_penalty=0
114
- )
115
-
116
- arguments = _parse_json(chat_completion.choices[0].message.function_call.arguments)
117
-
118
- return PrData(
119
- branch_info=branch_info,
120
- title=arguments['title'],
121
- body=arguments['description']
122
- )
123
-
124
-
125
- def _get_messages(branch_info):
126
- system_content = ('You are a development assistant designed to craft Git pull requests '
127
- 'by incorporating information from main and secondary commits, diff changes, '
128
- 'and adhering to a provided PR template. Your output includes a complete PR '
129
- 'template with all necessary details and a suitable PR title. In the '
130
- 'PR description, detail the work accomplished, the methodology employed, '
131
- 'including testing procedures, and list significant changes in bullet points '
132
- 'if they are extensive. Avoid incorporating diff content directly into '
133
- 'the PR description.')
134
-
135
- messages = [
136
- {'role': 'system', 'content': system_content},
137
- ]
138
-
139
- if len(branch_info.highlight_commits) > 0:
140
- messages.append({'role': 'user', 'content': 'main commits: ' + '\n'.join(branch_info.highlight_commits)})
141
- messages.append({'role': 'user', 'content': 'secondary commits: ' + '\n'.join(branch_info.commits)})
142
- else:
143
- messages.append({'role': 'user', 'content': 'git commits: \n' + '\n'.join(branch_info.commits)})
144
-
145
- messages.append({'role': 'user', 'content': 'PR template:\n' + _get_pr_template()})
146
-
147
- joined_messages = '\n'.join([m['content'] for m in messages])
148
- current_total_tokens = _count_tokens(joined_messages)
149
-
150
- input_max_tokens = int(config.get_user_config('INPUT_MAX_TOKENS'))
151
-
152
- if current_total_tokens > input_max_tokens:
153
- exp_message = (f'Length of {current_total_tokens} tokens for basic prompt '
154
- f'(description and commits) is greater than max tokens {input_max_tokens} '
155
- '(config \'input_max_tokens\')')
156
- raise Exception(exp_message)
157
-
158
- total_tokens_with_diff = current_total_tokens + _count_tokens(branch_info.diff)
159
- if total_tokens_with_diff > input_max_tokens:
160
- print_msg = (f'Length git changes with diff is too big (total is {total_tokens_with_diff}, '
161
- f'\'input_max_tokens\' config is {input_max_tokens}).')
162
- print(print_msg, cc.red('Skipping changes diff content...'))
163
- else:
164
- messages.append({'role': 'user', 'content': 'Diff changes:\n' + branch_info.diff})
165
-
166
- return messages
167
-
168
-
169
- def _parse_json(content):
170
- '''
171
- A bit of a hack to parse the json content from the chat completion
172
- Sometimes it returns a string with invalid json content (line breaks) that
173
- makes it hard to parse.
174
- example:
175
-
176
- content = '{\n"title": "feat(dependencies): pin dependencies versions",\n"description":
177
- "### Ref. [Link]\n\n## What was done? ..."\n}'
178
- '''
179
-
180
- try:
181
- content = content.replace('{\n"title":', '{"title":')
182
- content = content.replace(',\n"description":', ',"description":')
183
- content = content.replace('\n}', '}')
184
- content = content.replace('\n', '\\n')
185
-
186
- return json.loads(content)
187
- except Exception as e:
188
- print('Error to decode message:', e)
189
- print('Content:', content)
190
- 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.5.0"
File without changes