gpt-pr 0.2.1__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.
- gpt_pr/__init__.py +3 -0
- gpt_pr/checkversion.py +93 -0
- gpt_pr/config.py +104 -0
- gpt_pr/gh.py +44 -0
- {gptpr → gpt_pr}/gitutil.py +26 -12
- gpt_pr/gpt.py +8 -0
- gpt_pr/main.py +117 -0
- gpt_pr/prdata.py +217 -0
- gpt_pr/test_checkversion.py +132 -0
- gpt_pr/test_config.py +138 -0
- gpt_pr/test_gh.py +60 -0
- gpt_pr/test_prdata.py +17 -0
- gpt_pr-0.7.2.dist-info/METADATA +285 -0
- gpt_pr-0.7.2.dist-info/RECORD +17 -0
- {gpt_pr-0.2.1.dist-info → gpt_pr-0.7.2.dist-info}/WHEEL +1 -2
- gpt_pr-0.7.2.dist-info/entry_points.txt +4 -0
- gpt_pr-0.2.1.dist-info/METADATA +0 -49
- gpt_pr-0.2.1.dist-info/RECORD +0 -13
- gpt_pr-0.2.1.dist-info/entry_points.txt +0 -2
- gpt_pr-0.2.1.dist-info/top_level.txt +0 -1
- gptpr/__init__.py +0 -0
- gptpr/gh.py +0 -27
- gptpr/main.py +0 -52
- gptpr/prdata.py +0 -161
- gptpr/test_prdata.py +0 -13
- gptpr/version.py +0 -1
- {gptpr → gpt_pr}/consolecolor.py +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import requests
|
|
3
|
+
import json
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from unittest.mock import patch, mock_open
|
|
6
|
+
|
|
7
|
+
from gpt_pr import __version__
|
|
8
|
+
from gpt_pr.checkversion import (
|
|
9
|
+
get_latest_version,
|
|
10
|
+
load_cache,
|
|
11
|
+
save_cache,
|
|
12
|
+
check_for_updates,
|
|
13
|
+
CACHE_DURATION,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def mock_requests_get(mocker):
|
|
19
|
+
return mocker.patch("requests.get")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def mock_os_path_exists(mocker):
|
|
24
|
+
return mocker.patch("os.path.exists")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.fixture
|
|
28
|
+
def mock_open_file(mocker):
|
|
29
|
+
return mocker.patch("builtins.open", mock_open())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.fixture
|
|
33
|
+
def mock_datetime(mocker):
|
|
34
|
+
return mocker.patch("gpt_pr.checkversion.datetime")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_get_latest_version(mock_requests_get, mock_os_path_exists):
|
|
38
|
+
mock_os_path_exists.return_value = False
|
|
39
|
+
mock_response = mock_requests_get.return_value
|
|
40
|
+
mock_response.raise_for_status.return_value = None
|
|
41
|
+
mock_response.json.return_value = {"info": {"version": "2.0.0"}}
|
|
42
|
+
|
|
43
|
+
assert get_latest_version() == "2.0.0"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_get_latest_version_error(mock_requests_get, mock_os_path_exists):
|
|
47
|
+
mock_os_path_exists.return_value = False
|
|
48
|
+
mock_requests_get.side_effect = requests.exceptions.RequestException
|
|
49
|
+
|
|
50
|
+
assert get_latest_version() is None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_load_cache(mock_os_path_exists, mock_open_file):
|
|
54
|
+
mock_os_path_exists.return_value = True
|
|
55
|
+
mock_open_file.return_value.read.return_value = json.dumps(
|
|
56
|
+
{"last_checked": datetime.now().isoformat(), "latest_version": "2.0.0"}
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
cache = load_cache()
|
|
60
|
+
assert cache["latest_version"] == "2.0.0"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_load_cache_no_file(mock_os_path_exists):
|
|
64
|
+
mock_os_path_exists.return_value = False
|
|
65
|
+
|
|
66
|
+
cache = load_cache()
|
|
67
|
+
assert cache == {}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_save_cache(mock_open_file):
|
|
71
|
+
data = {"last_checked": datetime.now().isoformat(), "latest_version": "2.0.0"}
|
|
72
|
+
|
|
73
|
+
save_cache(data)
|
|
74
|
+
mock_open_file.return_value.write.assert_called_once_with(json.dumps(data))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_check_for_updates_new_version(
|
|
78
|
+
mocker, mock_datetime, mock_requests_get, mock_open_file
|
|
79
|
+
):
|
|
80
|
+
# Set up mocks
|
|
81
|
+
last_checked_str = (datetime(2024, 1, 1) - CACHE_DURATION).isoformat()
|
|
82
|
+
mock_datetime.now.return_value = datetime(2024, 1, 2)
|
|
83
|
+
mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
|
|
84
|
+
mock_open_file.return_value.read.return_value = json.dumps(
|
|
85
|
+
{"last_checked": last_checked_str, "latest_version": "1.0.0"}
|
|
86
|
+
)
|
|
87
|
+
mock_requests_get.return_value.raise_for_status.return_value = None
|
|
88
|
+
mock_requests_get.return_value.json.return_value = {"info": {"version": "2.0.0"}}
|
|
89
|
+
|
|
90
|
+
# Capture the print statements
|
|
91
|
+
with patch("builtins.print") as mocked_print:
|
|
92
|
+
check_for_updates()
|
|
93
|
+
assert mocked_print.call_count == 3
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_check_for_updates_no_new_version(
|
|
97
|
+
mocker, mock_datetime, mock_requests_get, mock_open_file
|
|
98
|
+
):
|
|
99
|
+
# Set up mocks
|
|
100
|
+
last_checked_str = (datetime(2024, 1, 1) - CACHE_DURATION).isoformat()
|
|
101
|
+
mock_datetime.now.return_value = datetime(2024, 1, 2)
|
|
102
|
+
mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
|
|
103
|
+
mock_open_file.return_value.read.return_value = json.dumps(
|
|
104
|
+
{
|
|
105
|
+
"last_checked": (datetime(2024, 1, 1) - CACHE_DURATION).isoformat(),
|
|
106
|
+
"latest_version": __version__,
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
mock_requests_get.return_value.raise_for_status.return_value = None
|
|
110
|
+
mock_requests_get.return_value.json.return_value = {
|
|
111
|
+
"info": {"version": __version__}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# Capture the print statements
|
|
115
|
+
with patch("builtins.print") as mocked_print:
|
|
116
|
+
check_for_updates()
|
|
117
|
+
assert mocked_print.call_count == 0
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_check_for_updates_cache_valid(mock_datetime, mock_open_file):
|
|
121
|
+
# Set up mocks
|
|
122
|
+
last_checked_str = datetime(2024, 1, 2).isoformat()
|
|
123
|
+
mock_datetime.now.return_value = datetime(2024, 1, 2)
|
|
124
|
+
mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
|
|
125
|
+
mock_open_file.return_value.read.return_value = json.dumps(
|
|
126
|
+
{"last_checked": last_checked_str, "latest_version": __version__}
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Capture the print statements
|
|
130
|
+
with patch("builtins.print") as mocked_print:
|
|
131
|
+
check_for_updates()
|
|
132
|
+
assert mocked_print.call_count == 0
|
gpt_pr/test_config.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import configparser
|
|
3
|
+
|
|
4
|
+
from pytest import fixture
|
|
5
|
+
|
|
6
|
+
from gpt_pr.config import Config
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@fixture
|
|
10
|
+
def temp_config(tmpdir):
|
|
11
|
+
temp_dir = tmpdir.mkdir("config_dir")
|
|
12
|
+
config = Config(temp_dir)
|
|
13
|
+
return config, temp_dir
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _check_config(config, temp_dir, config_list):
|
|
17
|
+
# Read the configuration file and verify its contents
|
|
18
|
+
config_to_test = configparser.ConfigParser()
|
|
19
|
+
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
20
|
+
|
|
21
|
+
for section, key, value in config_list:
|
|
22
|
+
assert config_to_test[section][key] == value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_init_config_file(temp_config):
|
|
26
|
+
config, temp_dir = temp_config
|
|
27
|
+
config.load()
|
|
28
|
+
|
|
29
|
+
# Check if the file exists
|
|
30
|
+
assert os.path.isfile(os.path.join(str(temp_dir), config.config_filename))
|
|
31
|
+
|
|
32
|
+
_check_config(
|
|
33
|
+
config,
|
|
34
|
+
temp_dir,
|
|
35
|
+
[
|
|
36
|
+
("DEFAULT", "OPENAI_MODEL", "gpt-4o-mini"),
|
|
37
|
+
("DEFAULT", "OPENAI_API_KEY", ""),
|
|
38
|
+
],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_new_default_value_should_be_added(temp_config):
|
|
43
|
+
config, temp_dir = temp_config
|
|
44
|
+
config.load() # data was written to the file
|
|
45
|
+
|
|
46
|
+
new_config = Config(temp_dir)
|
|
47
|
+
|
|
48
|
+
# Add a new default value
|
|
49
|
+
new_config.default_config["NEW_DEFAULT"] = "new_default_value"
|
|
50
|
+
new_config.load() # Should update config file...
|
|
51
|
+
|
|
52
|
+
_check_config(
|
|
53
|
+
new_config,
|
|
54
|
+
temp_dir,
|
|
55
|
+
[
|
|
56
|
+
("DEFAULT", "NEW_DEFAULT", "new_default_value"),
|
|
57
|
+
],
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_set_user_config(temp_config):
|
|
62
|
+
config, temp_dir = temp_config
|
|
63
|
+
|
|
64
|
+
config.set_user_config("OPENAI_MODEL", "gpt-3.5")
|
|
65
|
+
config.persist()
|
|
66
|
+
|
|
67
|
+
# Read the configuration file and verify its contents
|
|
68
|
+
config_to_test = configparser.ConfigParser()
|
|
69
|
+
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
70
|
+
|
|
71
|
+
_check_config(
|
|
72
|
+
config,
|
|
73
|
+
temp_dir,
|
|
74
|
+
[
|
|
75
|
+
("user", "OPENAI_MODEL", "gpt-3.5"),
|
|
76
|
+
("user", "OPENAI_API_KEY", ""),
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_set_user_config_with_int_value(temp_config):
|
|
82
|
+
config, temp_dir = temp_config
|
|
83
|
+
|
|
84
|
+
config.set_user_config("INPUT_MAX_TOKENS", 100)
|
|
85
|
+
config.persist()
|
|
86
|
+
|
|
87
|
+
# Read the configuration file and verify its contents
|
|
88
|
+
config_to_test = configparser.ConfigParser()
|
|
89
|
+
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
90
|
+
|
|
91
|
+
_check_config(
|
|
92
|
+
config,
|
|
93
|
+
temp_dir,
|
|
94
|
+
[
|
|
95
|
+
("user", "INPUT_MAX_TOKENS", "100"),
|
|
96
|
+
],
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_all_values(temp_config):
|
|
101
|
+
config, temp_dir = temp_config
|
|
102
|
+
|
|
103
|
+
all_values = config.all_values()
|
|
104
|
+
|
|
105
|
+
assert all_values == [
|
|
106
|
+
("DEFAULT", "add_tool_signature", "true"),
|
|
107
|
+
("DEFAULT", "gh_token", ""),
|
|
108
|
+
("DEFAULT", "input_max_tokens", "15000"),
|
|
109
|
+
("DEFAULT", "openai_model", "gpt-4o-mini"),
|
|
110
|
+
("DEFAULT", "openai_api_key", ""),
|
|
111
|
+
("user", "add_tool_signature", "true"),
|
|
112
|
+
("user", "gh_token", ""),
|
|
113
|
+
("user", "input_max_tokens", "15000"),
|
|
114
|
+
("user", "openai_model", "gpt-4o-mini"),
|
|
115
|
+
("user", "openai_api_key", ""),
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_reset_user_config(temp_config):
|
|
120
|
+
config, temp_dir = temp_config
|
|
121
|
+
|
|
122
|
+
config.set_user_config("OPENAI_MODEL", "gpt-3.5")
|
|
123
|
+
config.persist()
|
|
124
|
+
|
|
125
|
+
config.reset_user_config("OPENAI_MODEL")
|
|
126
|
+
|
|
127
|
+
# Read the configuration file and verify its contents
|
|
128
|
+
config_to_test = configparser.ConfigParser()
|
|
129
|
+
config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
|
|
130
|
+
|
|
131
|
+
_check_config(
|
|
132
|
+
config,
|
|
133
|
+
temp_dir,
|
|
134
|
+
[
|
|
135
|
+
("user", "OPENAI_MODEL", "gpt-4o-mini"),
|
|
136
|
+
("user", "OPENAI_API_KEY", ""),
|
|
137
|
+
],
|
|
138
|
+
)
|
gpt_pr/test_gh.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from types import SimpleNamespace
|
|
2
|
+
import gpt_pr.gh as gh_module
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_create_pr_success(mocker, capsys):
|
|
6
|
+
fake_repo = mocker.Mock()
|
|
7
|
+
pr = SimpleNamespace(html_url="http://fake.url")
|
|
8
|
+
fake_repo.create_pull.return_value = pr
|
|
9
|
+
|
|
10
|
+
fake_gh = SimpleNamespace()
|
|
11
|
+
fake_gh.get_repo = lambda repo_name: fake_repo
|
|
12
|
+
|
|
13
|
+
branch_info = SimpleNamespace(
|
|
14
|
+
owner="owner", repo="repo", branch="feature-branch", base_branch="main"
|
|
15
|
+
)
|
|
16
|
+
pr_data = SimpleNamespace(
|
|
17
|
+
title="Test PR", branch_info=branch_info, create_body=lambda: "My body"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
gh_module.create_pr(pr_data, yield_confirmation=True, gh=fake_gh)
|
|
21
|
+
|
|
22
|
+
fake_repo.create_pull.assert_called_once_with(
|
|
23
|
+
title="Test PR", body="My body", head="feature-branch", base="main"
|
|
24
|
+
)
|
|
25
|
+
captured = capsys.readouterr()
|
|
26
|
+
assert "Pull request created successfully" in captured.out
|
|
27
|
+
assert "http://fake.url" in captured.out
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_create_pr_cancel(mocker, capsys):
|
|
31
|
+
fake_repo = mocker.Mock()
|
|
32
|
+
fake_gh = SimpleNamespace()
|
|
33
|
+
fake_gh.get_repo = lambda repo_name: fake_repo
|
|
34
|
+
|
|
35
|
+
class FakePrompt:
|
|
36
|
+
def __init__(self, *args, **kwargs):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
def execute(self):
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
mocker.patch.object(
|
|
43
|
+
gh_module.inquirer,
|
|
44
|
+
"confirm",
|
|
45
|
+
lambda *args, **kwargs: FakePrompt(*args, **kwargs),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
branch_info = SimpleNamespace(
|
|
49
|
+
owner="owner", repo="repo", branch="branch", base_branch="base"
|
|
50
|
+
)
|
|
51
|
+
pr_data = SimpleNamespace(
|
|
52
|
+
title="Cancel PR", branch_info=branch_info, create_body=lambda: "Body"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
gh_module.create_pr(pr_data, yield_confirmation=False, gh=fake_gh)
|
|
56
|
+
|
|
57
|
+
fake_repo.create_pull.assert_not_called()
|
|
58
|
+
captured = capsys.readouterr()
|
|
59
|
+
|
|
60
|
+
assert "cancelling..." in captured.out
|
gpt_pr/test_prdata.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from gpt_pr.prdata import _parse_json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_parse_json():
|
|
5
|
+
content = (
|
|
6
|
+
'{\n"title": "feat(dependencies): pin dependencies '
|
|
7
|
+
'versions",\n"description": "### Ref. [Link]\n\n## What was done? ..."\n}'
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
expected = {
|
|
11
|
+
"title": "feat(dependencies): pin dependencies versions",
|
|
12
|
+
"description": "### Ref. [Link]\n\n## What was done? ...",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
assert _parse_json(content) == expected, (
|
|
16
|
+
"The function did not return the expected output."
|
|
17
|
+
)
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gpt-pr
|
|
3
|
+
Version: 0.7.2
|
|
4
|
+
Summary: Automate your GitHub workflow with GPT-PR: an OpenAI powered library for streamlined PR generation.
|
|
5
|
+
Author: alissonperez
|
|
6
|
+
Author-email: 756802+alissonperez@users.noreply.github.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Dist: fire (>=0.7.1,<0.8.0)
|
|
15
|
+
Requires-Dist: gitpython (>=3.1.45,<4.0.0)
|
|
16
|
+
Requires-Dist: inquirerpy (>=0.3.4,<0.4.0)
|
|
17
|
+
Requires-Dist: prompt-toolkit (>=3.0.52,<4.0.0)
|
|
18
|
+
Requires-Dist: pydantic-ai (>=1.14.0,<2.0.0)
|
|
19
|
+
Requires-Dist: pygithub (>=2.8.1,<3.0.0)
|
|
20
|
+
Requires-Dist: requests (>=2.32.5,<3.0.0)
|
|
21
|
+
Requires-Dist: tiktoken (>=0.12.0,<0.13.0)
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# GPT-PR
|
|
25
|
+
|
|
26
|
+
GPT-PR is an open-source command-line tool designed to streamline your GitHub workflow for opening PRs. Leveraging OpenAI's ChatGPT API, it automatically opens a GitHub Pull Request with a predefined description and title directly from your current project directory.
|
|
27
|
+
|
|
28
|
+
[](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A)
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
For a more detailed explanation, see [Installation](#installation) and [Configuration](#configuration).
|
|
33
|
+
|
|
34
|
+
### 1. Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install -U gpt-pr
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you don't have the `pip` command available, follow [these instructions](https://pip.pypa.io/en/stable/installation/) to install it on different platforms.
|
|
41
|
+
|
|
42
|
+
### 2. Fill OpenAI API Key
|
|
43
|
+
|
|
44
|
+
1. Go to [OpenAI API Keys](https://platform.openai.com/api-keys) and generate a new key.
|
|
45
|
+
2. Run the following command to fill your key in GPT-PR (it will be stored in `~/.gpt-pr.ini`):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
gpt-pr-config set openai_api_key MY-API-KEY-VALUE
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. Generate a GitHub GH Token to Open PRs
|
|
52
|
+
|
|
53
|
+
1. Go to [GitHub Settings](https://github.com/settings/tokens), choose `Generate new token (classic)`, and select all permissions under `repo` (full control of private repositories).
|
|
54
|
+
2. Run the following command to fill your GH token (it will also be stored in `~/.gpt-pr.ini`):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
gpt-pr-config set gh_token MY-GH-TOKEN-VALUE
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 4. Ready to NEVER WRITE A PR AGAIN
|
|
61
|
+
|
|
62
|
+
1. Make your changes, commit them, and push to origin (important!).
|
|
63
|
+
2. Run the following command in your project directory:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
gpt-pr
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
3. Answer the questions. At the end, you'll receive the URL of a freshly opened PR.
|
|
70
|
+
|
|
71
|
+
## Contributing and Feedback
|
|
72
|
+
|
|
73
|
+
We welcome your contributions and feedback to help improve GPT-PR! Here’s how you can get involved:
|
|
74
|
+
|
|
75
|
+
### Open Issues
|
|
76
|
+
|
|
77
|
+
- **Feature Requests**: Have an idea for a new feature? We’d love to hear it! Open an issue to request new features or enhancements.
|
|
78
|
+
- **Bug Reports**: Encountered a bug? Let us know by opening an issue with detailed information so we can fix it.
|
|
79
|
+
- **General Feedback**: Any other suggestions or feedback? Feel free to share your thoughts.
|
|
80
|
+
|
|
81
|
+
To open an issue, go to the [Issues](https://github.com/your-repo/gpt-pr/issues) section of our GitHub repository. Your contributions are very welcome and highly appreciated!
|
|
82
|
+
|
|
83
|
+
More details about it at our [CONTRIBUTING](./CONTRIBUTING.md) guide.
|
|
84
|
+
|
|
85
|
+
## Table of Contents
|
|
86
|
+
|
|
87
|
+
- [Features](#features)
|
|
88
|
+
- [Prerequisites](#prerequisites)
|
|
89
|
+
- [Installation](#installation)
|
|
90
|
+
- [Configuration](#configuration)
|
|
91
|
+
- [Usage](#usage)
|
|
92
|
+
- [How to Contribute](#how-to-contribute)
|
|
93
|
+
- [Roadmap](#roadmap)
|
|
94
|
+
|
|
95
|
+
## Features
|
|
96
|
+
|
|
97
|
+
- Analyzes the diff changes of the current branch against the `main` branch.
|
|
98
|
+
- Provides an option to exclude certain file changes from PR generation (for instance, you can ignore a `package.lock` file with 5k lines changed).
|
|
99
|
+
- Incorporates commit messages into the process.
|
|
100
|
+
|
|
101
|
+
## Prerequisites
|
|
102
|
+
|
|
103
|
+
Before getting started, make sure you have the following installed:
|
|
104
|
+
|
|
105
|
+
- Python 3.9 or higher
|
|
106
|
+
- [Poetry](https://python-poetry.org/)
|
|
107
|
+
|
|
108
|
+
## Installation
|
|
109
|
+
|
|
110
|
+
You can install and use GPT-PR in one of two ways. Choose the option that best suits your needs.
|
|
111
|
+
|
|
112
|
+
### Option 1: Using `pip install` (Recommended)
|
|
113
|
+
|
|
114
|
+
1. Install OR Update the package:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install -U gpt-pr
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
2. Setup API keys for GitHub and OpenAI, take a look at [Configuration](#configuration).
|
|
121
|
+
|
|
122
|
+
3. Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
gpt-pr --help
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Option 2: Cloning the code (NOT recommended)
|
|
129
|
+
|
|
130
|
+
1. Clone the repository:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
git clone https://github.com/alissonperez/gpt-pr.git
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
2. Navigate to the project directory and install dependencies:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
cd gpt-pr
|
|
140
|
+
poetry install
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
After setting up API keys ([Configuration](#configuration)), you can use GPT-PR within any git project directory. Suppose you've cloned **this project** to `~/workplace/gpt-pr`, here's how you can use it:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
poetry run python gpt_pr/main.py --help
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Configuration
|
|
150
|
+
|
|
151
|
+
### See all configs available
|
|
152
|
+
|
|
153
|
+
To print all default configs and what is being used, just run:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
gpt-pr-config print
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Setting up GitHub Token (`GH_TOKEN`)
|
|
160
|
+
|
|
161
|
+
GPT-PR tool will look for a `GH_TOKEN` in current shell env var OR in gpt-pr config file (at `~/.gpt-pr.ini`).
|
|
162
|
+
|
|
163
|
+
To authenticate with GitHub, generate and export a GitHub Personal Access Token:
|
|
164
|
+
|
|
165
|
+
1. Navigate to [GitHub's Personal Access Token page](https://github.com/settings/tokens).
|
|
166
|
+
2. Click "Generate new token."
|
|
167
|
+
3. Provide a description and select the required permissions `repo` for the token.
|
|
168
|
+
4. Click "Generate token" at the bottom of the page.
|
|
169
|
+
5. Copy the generated token.
|
|
170
|
+
6. Set `gh_token` config running (supposing your gh token is `ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b`):
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
gpt-pr-config set gh_token ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Or just export it as an environment variable in your shell initializer:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
export GH_TOKEN=your_generated_token_here
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Setting up OpenAI API Key (`OPENAI_API_KEY`)
|
|
183
|
+
|
|
184
|
+
GPT-PR tool will look for a `OPENAI_API_KEY` env var in current shell OR in gpt-pr config file (at `~/.gpt-pr.ini`).
|
|
185
|
+
|
|
186
|
+
This project needs to interact with the ChatGPT API to generate the pull request description. So, you need to generate and export an OpenAI API Key:
|
|
187
|
+
|
|
188
|
+
1. Navigate to [OpenAI's API Key page](https://platform.openai.com/signup).
|
|
189
|
+
2. If you don't have an account, sign up and log in.
|
|
190
|
+
3. Go to the API Keys section and click "Create new key."
|
|
191
|
+
4. Provide a description and click "Create."
|
|
192
|
+
5. Copy the generated API key.
|
|
193
|
+
6. Set `openai_api_key` config running (supposing your openai_api_key is `QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht`):
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
gpt-pr-config set openai_api_key QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Or just export it as an environment variable in your shell initializer:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
export OPENAI_API_KEY=your_generated_api_key_here
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Setting Max Input LLM Tokens
|
|
206
|
+
|
|
207
|
+
You can adjust the maximum number of input tokens allowed when calling the LLM model by modifying the corresponding setting.
|
|
208
|
+
|
|
209
|
+
For example, to change the maximum to 20,000 tokens, use the following command:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
gpt-pr-config set input_max_tokens 20000
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Change OpenAI model
|
|
216
|
+
|
|
217
|
+
To change OpenAI model, just run:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
gpt-pr-config set openai_model gpt-4o-mini
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
> Obs.: `gpt-4o-mini` already is the default model of the project
|
|
224
|
+
|
|
225
|
+
To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
|
|
226
|
+
|
|
227
|
+
### GPT-PR Library Signature in PRs
|
|
228
|
+
|
|
229
|
+
To help other developers recognize and understand the use of the GPT-PR library in generating pull requests, we have included an optional signature feature. By default, this feature is enabled and appends the text "Generated by GPT-PR" at the end of each pull request. This transparency fosters better collaboration and awareness among team members about the tools being utilized in the development process.
|
|
230
|
+
|
|
231
|
+
If you prefer to disable this feature, simply run the following command:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
gpt-pr-config set add_tool_signature false
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Reset config
|
|
238
|
+
|
|
239
|
+
To reset any config to default value, just run:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
gpt-pr-config reset config_name
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Example:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
gpt-pr-config reset openai_model
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Usage
|
|
252
|
+
|
|
253
|
+
### Generating Github Pull Requests
|
|
254
|
+
|
|
255
|
+
To create a Pull request from your current branch commits to merge with `main` branch, just run:
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
gpt-pr
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
If you would like to compare with other base branch that is not `main`, just use `-b` param:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
gpt-pr -b my-other-branch
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Usage help
|
|
268
|
+
|
|
269
|
+
To show help commands:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
gpt-pr -h
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Output:
|
|
276
|
+

|
|
277
|
+
|
|
278
|
+
## Roadmap
|
|
279
|
+
|
|
280
|
+
- [x] Improve execution method, possibly through a shell script or at least an alias in bash rc files.
|
|
281
|
+
- Change to use with pip installation and console_scripts entry point.
|
|
282
|
+
- [x] Fetch GitHub PR templates from the current project.
|
|
283
|
+
- [ ] Add configuration to set which LLM and model should be used (OpenAI GPT, Mistral, etc...)
|
|
284
|
+
- [ ] Add unit tests.
|
|
285
|
+
|
|
@@ -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,,
|