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.
@@ -4,39 +4,43 @@ import json
4
4
  from datetime import datetime
5
5
  from unittest.mock import patch, mock_open
6
6
 
7
- from gptpr.version import __version__
8
- from gptpr.checkversion import (get_latest_version, load_cache,
9
- save_cache, check_for_updates,
10
- CACHE_DURATION)
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
+ )
11
15
 
12
16
 
13
17
  @pytest.fixture
14
18
  def mock_requests_get(mocker):
15
- return mocker.patch('requests.get')
19
+ return mocker.patch("requests.get")
16
20
 
17
21
 
18
22
  @pytest.fixture
19
23
  def mock_os_path_exists(mocker):
20
- return mocker.patch('os.path.exists')
24
+ return mocker.patch("os.path.exists")
21
25
 
22
26
 
23
27
  @pytest.fixture
24
28
  def mock_open_file(mocker):
25
- return mocker.patch('builtins.open', mock_open())
29
+ return mocker.patch("builtins.open", mock_open())
26
30
 
27
31
 
28
32
  @pytest.fixture
29
33
  def mock_datetime(mocker):
30
- return mocker.patch('gptpr.checkversion.datetime')
34
+ return mocker.patch("gpt_pr.checkversion.datetime")
31
35
 
32
36
 
33
37
  def test_get_latest_version(mock_requests_get, mock_os_path_exists):
34
38
  mock_os_path_exists.return_value = False
35
39
  mock_response = mock_requests_get.return_value
36
40
  mock_response.raise_for_status.return_value = None
37
- mock_response.json.return_value = {'info': {'version': '2.0.0'}}
41
+ mock_response.json.return_value = {"info": {"version": "2.0.0"}}
38
42
 
39
- assert get_latest_version() == '2.0.0'
43
+ assert get_latest_version() == "2.0.0"
40
44
 
41
45
 
42
46
  def test_get_latest_version_error(mock_requests_get, mock_os_path_exists):
@@ -48,13 +52,12 @@ def test_get_latest_version_error(mock_requests_get, mock_os_path_exists):
48
52
 
49
53
  def test_load_cache(mock_os_path_exists, mock_open_file):
50
54
  mock_os_path_exists.return_value = True
51
- mock_open_file.return_value.read.return_value = json.dumps({
52
- 'last_checked': datetime.now().isoformat(),
53
- 'latest_version': '2.0.0'
54
- })
55
+ mock_open_file.return_value.read.return_value = json.dumps(
56
+ {"last_checked": datetime.now().isoformat(), "latest_version": "2.0.0"}
57
+ )
55
58
 
56
59
  cache = load_cache()
57
- assert cache['latest_version'] == '2.0.0'
60
+ assert cache["latest_version"] == "2.0.0"
58
61
 
59
62
 
60
63
  def test_load_cache_no_file(mock_os_path_exists):
@@ -65,47 +68,51 @@ def test_load_cache_no_file(mock_os_path_exists):
65
68
 
66
69
 
67
70
  def test_save_cache(mock_open_file):
68
- data = {
69
- 'last_checked': datetime.now().isoformat(),
70
- 'latest_version': '2.0.0'
71
- }
71
+ data = {"last_checked": datetime.now().isoformat(), "latest_version": "2.0.0"}
72
72
 
73
73
  save_cache(data)
74
74
  mock_open_file.return_value.write.assert_called_once_with(json.dumps(data))
75
75
 
76
76
 
77
- def test_check_for_updates_new_version(mocker, mock_datetime, mock_requests_get, mock_open_file):
77
+ def test_check_for_updates_new_version(
78
+ mocker, mock_datetime, mock_requests_get, mock_open_file
79
+ ):
78
80
  # Set up mocks
79
81
  last_checked_str = (datetime(2024, 1, 1) - CACHE_DURATION).isoformat()
80
82
  mock_datetime.now.return_value = datetime(2024, 1, 2)
81
83
  mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
82
- mock_open_file.return_value.read.return_value = json.dumps({
83
- 'last_checked': last_checked_str,
84
- 'latest_version': '1.0.0'
85
- })
84
+ mock_open_file.return_value.read.return_value = json.dumps(
85
+ {"last_checked": last_checked_str, "latest_version": "1.0.0"}
86
+ )
86
87
  mock_requests_get.return_value.raise_for_status.return_value = None
87
- mock_requests_get.return_value.json.return_value = {'info': {'version': '2.0.0'}}
88
+ mock_requests_get.return_value.json.return_value = {"info": {"version": "2.0.0"}}
88
89
 
89
90
  # Capture the print statements
90
- with patch('builtins.print') as mocked_print:
91
+ with patch("builtins.print") as mocked_print:
91
92
  check_for_updates()
92
93
  assert mocked_print.call_count == 3
93
94
 
94
95
 
95
- def test_check_for_updates_no_new_version(mocker, mock_datetime, mock_requests_get, mock_open_file):
96
+ def test_check_for_updates_no_new_version(
97
+ mocker, mock_datetime, mock_requests_get, mock_open_file
98
+ ):
96
99
  # Set up mocks
97
100
  last_checked_str = (datetime(2024, 1, 1) - CACHE_DURATION).isoformat()
98
101
  mock_datetime.now.return_value = datetime(2024, 1, 2)
99
102
  mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
100
- mock_open_file.return_value.read.return_value = json.dumps({
101
- 'last_checked': (datetime(2024, 1, 1) - CACHE_DURATION).isoformat(),
102
- 'latest_version': __version__
103
- })
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
+ )
104
109
  mock_requests_get.return_value.raise_for_status.return_value = None
105
- mock_requests_get.return_value.json.return_value = {'info': {'version': __version__}}
110
+ mock_requests_get.return_value.json.return_value = {
111
+ "info": {"version": __version__}
112
+ }
106
113
 
107
114
  # Capture the print statements
108
- with patch('builtins.print') as mocked_print:
115
+ with patch("builtins.print") as mocked_print:
109
116
  check_for_updates()
110
117
  assert mocked_print.call_count == 0
111
118
 
@@ -115,12 +122,11 @@ def test_check_for_updates_cache_valid(mock_datetime, mock_open_file):
115
122
  last_checked_str = datetime(2024, 1, 2).isoformat()
116
123
  mock_datetime.now.return_value = datetime(2024, 1, 2)
117
124
  mock_datetime.fromisoformat.return_value = datetime.fromisoformat(last_checked_str)
118
- mock_open_file.return_value.read.return_value = json.dumps({
119
- 'last_checked': last_checked_str,
120
- 'latest_version': __version__
121
- })
125
+ mock_open_file.return_value.read.return_value = json.dumps(
126
+ {"last_checked": last_checked_str, "latest_version": __version__}
127
+ )
122
128
 
123
129
  # Capture the print statements
124
- with patch('builtins.print') as mocked_print:
130
+ with patch("builtins.print") as mocked_print:
125
131
  check_for_updates()
126
132
  assert mocked_print.call_count == 0
@@ -3,12 +3,12 @@ import configparser
3
3
 
4
4
  from pytest import fixture
5
5
 
6
- from gptpr.config import Config
6
+ from gpt_pr.config import Config
7
7
 
8
8
 
9
9
  @fixture
10
10
  def temp_config(tmpdir):
11
- temp_dir = tmpdir.mkdir('config_dir')
11
+ temp_dir = tmpdir.mkdir("config_dir")
12
12
  config = Config(temp_dir)
13
13
  return config, temp_dir
14
14
 
@@ -29,10 +29,14 @@ def test_init_config_file(temp_config):
29
29
  # Check if the file exists
30
30
  assert os.path.isfile(os.path.join(str(temp_dir), config.config_filename))
31
31
 
32
- _check_config(config, temp_dir, [
33
- ('DEFAULT', 'OPENAI_MODEL', 'gpt-4o-mini'),
34
- ('DEFAULT', 'OPENAI_API_KEY', ''),
35
- ])
32
+ _check_config(
33
+ config,
34
+ temp_dir,
35
+ [
36
+ ("DEFAULT", "OPENAI_MODEL", "gpt-4o-mini"),
37
+ ("DEFAULT", "OPENAI_API_KEY", ""),
38
+ ],
39
+ )
36
40
 
37
41
 
38
42
  def test_new_default_value_should_be_added(temp_config):
@@ -42,43 +46,55 @@ def test_new_default_value_should_be_added(temp_config):
42
46
  new_config = Config(temp_dir)
43
47
 
44
48
  # Add a new default value
45
- new_config.default_config['NEW_DEFAULT'] = 'new_default_value'
49
+ new_config.default_config["NEW_DEFAULT"] = "new_default_value"
46
50
  new_config.load() # Should update config file...
47
51
 
48
- _check_config(new_config, temp_dir, [
49
- ('DEFAULT', 'NEW_DEFAULT', 'new_default_value'),
50
- ])
52
+ _check_config(
53
+ new_config,
54
+ temp_dir,
55
+ [
56
+ ("DEFAULT", "NEW_DEFAULT", "new_default_value"),
57
+ ],
58
+ )
51
59
 
52
60
 
53
61
  def test_set_user_config(temp_config):
54
62
  config, temp_dir = temp_config
55
63
 
56
- config.set_user_config('OPENAI_MODEL', 'gpt-3.5')
64
+ config.set_user_config("OPENAI_MODEL", "gpt-3.5")
57
65
  config.persist()
58
66
 
59
67
  # Read the configuration file and verify its contents
60
68
  config_to_test = configparser.ConfigParser()
61
69
  config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
62
70
 
63
- _check_config(config, temp_dir, [
64
- ('user', 'OPENAI_MODEL', 'gpt-3.5'),
65
- ('user', 'OPENAI_API_KEY', ''),
66
- ])
71
+ _check_config(
72
+ config,
73
+ temp_dir,
74
+ [
75
+ ("user", "OPENAI_MODEL", "gpt-3.5"),
76
+ ("user", "OPENAI_API_KEY", ""),
77
+ ],
78
+ )
67
79
 
68
80
 
69
81
  def test_set_user_config_with_int_value(temp_config):
70
82
  config, temp_dir = temp_config
71
83
 
72
- config.set_user_config('INPUT_MAX_TOKENS', 100)
84
+ config.set_user_config("INPUT_MAX_TOKENS", 100)
73
85
  config.persist()
74
86
 
75
87
  # Read the configuration file and verify its contents
76
88
  config_to_test = configparser.ConfigParser()
77
89
  config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
78
90
 
79
- _check_config(config, temp_dir, [
80
- ('user', 'INPUT_MAX_TOKENS', '100'),
81
- ])
91
+ _check_config(
92
+ config,
93
+ temp_dir,
94
+ [
95
+ ("user", "INPUT_MAX_TOKENS", "100"),
96
+ ],
97
+ )
82
98
 
83
99
 
84
100
  def test_all_values(temp_config):
@@ -87,30 +103,36 @@ def test_all_values(temp_config):
87
103
  all_values = config.all_values()
88
104
 
89
105
  assert all_values == [
90
- ('DEFAULT', 'gh_token', ''),
91
- ('DEFAULT', 'input_max_tokens', '15000'),
92
- ('DEFAULT', 'openai_model', 'gpt-4o-mini'),
93
- ('DEFAULT', 'openai_api_key', ''),
94
- ('user', 'gh_token', ''),
95
- ('user', 'input_max_tokens', '15000'),
96
- ('user', 'openai_model', 'gpt-4o-mini'),
97
- ('user', 'openai_api_key', ''),
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", ""),
98
116
  ]
99
117
 
100
118
 
101
119
  def test_reset_user_config(temp_config):
102
120
  config, temp_dir = temp_config
103
121
 
104
- config.set_user_config('OPENAI_MODEL', 'gpt-3.5')
122
+ config.set_user_config("OPENAI_MODEL", "gpt-3.5")
105
123
  config.persist()
106
124
 
107
- config.reset_user_config('OPENAI_MODEL')
125
+ config.reset_user_config("OPENAI_MODEL")
108
126
 
109
127
  # Read the configuration file and verify its contents
110
128
  config_to_test = configparser.ConfigParser()
111
129
  config_to_test.read(os.path.join(str(temp_dir), config.config_filename))
112
130
 
113
- _check_config(config, temp_dir, [
114
- ('user', 'OPENAI_MODEL', 'gpt-4o-mini'),
115
- ('user', 'OPENAI_API_KEY', ''),
116
- ])
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
+ [![asciicast](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A.svg)](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
+ ![image](https://github.com/alissonperez/gpt-pr/assets/756802/cc6c0ca4-5759-44ce-ad35-e4e7305b3875)
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
+