gpt-pr 0.3.0__tar.gz → 0.7.2__tar.gz
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-0.7.2/PKG-INFO +285 -0
- {gpt-pr-0.3.0 → gpt_pr-0.7.2}/README.md +88 -19
- gpt_pr-0.7.2/gpt_pr/__init__.py +3 -0
- gpt_pr-0.7.2/gpt_pr/checkversion.py +93 -0
- {gpt-pr-0.3.0/gptpr → gpt_pr-0.7.2/gpt_pr}/config.py +10 -3
- gpt_pr-0.7.2/gpt_pr/gh.py +44 -0
- {gpt-pr-0.3.0/gptpr → gpt_pr-0.7.2/gpt_pr}/gitutil.py +26 -12
- gpt_pr-0.7.2/gpt_pr/gpt.py +8 -0
- gpt_pr-0.7.2/gpt_pr/main.py +117 -0
- gpt_pr-0.7.2/gpt_pr/prdata.py +217 -0
- gpt_pr-0.7.2/gpt_pr/test_checkversion.py +132 -0
- gpt_pr-0.7.2/gpt_pr/test_config.py +138 -0
- gpt_pr-0.7.2/gpt_pr/test_gh.py +60 -0
- gpt_pr-0.7.2/gpt_pr/test_prdata.py +17 -0
- gpt_pr-0.7.2/pyproject.toml +35 -0
- gpt-pr-0.3.0/MANIFEST.in +0 -3
- gpt-pr-0.3.0/PKG-INFO +0 -9
- gpt-pr-0.3.0/gpt_pr.egg-info/PKG-INFO +0 -9
- gpt-pr-0.3.0/gpt_pr.egg-info/SOURCES.txt +0 -22
- gpt-pr-0.3.0/gpt_pr.egg-info/dependency_links.txt +0 -1
- gpt-pr-0.3.0/gpt_pr.egg-info/entry_points.txt +0 -3
- gpt-pr-0.3.0/gpt_pr.egg-info/not-zip-safe +0 -1
- gpt-pr-0.3.0/gpt_pr.egg-info/requires.txt +0 -61
- gpt-pr-0.3.0/gpt_pr.egg-info/top_level.txt +0 -1
- gpt-pr-0.3.0/gptpr/__init__.py +0 -0
- gpt-pr-0.3.0/gptpr/gh.py +0 -37
- gpt-pr-0.3.0/gptpr/main.py +0 -97
- gpt-pr-0.3.0/gptpr/prdata.py +0 -173
- gpt-pr-0.3.0/gptpr/test_config.py +0 -99
- gpt-pr-0.3.0/gptpr/test_prdata.py +0 -13
- gpt-pr-0.3.0/gptpr/version.py +0 -1
- gpt-pr-0.3.0/requirements.txt +0 -40
- gpt-pr-0.3.0/setup.cfg +0 -7
- gpt-pr-0.3.0/setup.py +0 -50
- {gpt-pr-0.3.0/gptpr → gpt_pr-0.7.2/gpt_pr}/consolecolor.py +0 -0
gpt_pr-0.7.2/PKG-INFO
ADDED
|
@@ -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
|
+
|
|
@@ -4,6 +4,61 @@ GPT-PR is an open-source command-line tool designed to streamline your GitHub wo
|
|
|
4
4
|
|
|
5
5
|
[](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A)
|
|
6
6
|
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
For a more detailed explanation, see [Installation](#installation) and [Configuration](#configuration).
|
|
10
|
+
|
|
11
|
+
### 1. Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -U gpt-pr
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
### 2. Fill OpenAI API Key
|
|
20
|
+
|
|
21
|
+
1. Go to [OpenAI API Keys](https://platform.openai.com/api-keys) and generate a new key.
|
|
22
|
+
2. Run the following command to fill your key in GPT-PR (it will be stored in `~/.gpt-pr.ini`):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
gpt-pr-config set openai_api_key MY-API-KEY-VALUE
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 3. Generate a GitHub GH Token to Open PRs
|
|
29
|
+
|
|
30
|
+
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).
|
|
31
|
+
2. Run the following command to fill your GH token (it will also be stored in `~/.gpt-pr.ini`):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
gpt-pr-config set gh_token MY-GH-TOKEN-VALUE
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 4. Ready to NEVER WRITE A PR AGAIN
|
|
38
|
+
|
|
39
|
+
1. Make your changes, commit them, and push to origin (important!).
|
|
40
|
+
2. Run the following command in your project directory:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
gpt-pr
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
3. Answer the questions. At the end, you'll receive the URL of a freshly opened PR.
|
|
47
|
+
|
|
48
|
+
## Contributing and Feedback
|
|
49
|
+
|
|
50
|
+
We welcome your contributions and feedback to help improve GPT-PR! Here’s how you can get involved:
|
|
51
|
+
|
|
52
|
+
### Open Issues
|
|
53
|
+
|
|
54
|
+
- **Feature Requests**: Have an idea for a new feature? We’d love to hear it! Open an issue to request new features or enhancements.
|
|
55
|
+
- **Bug Reports**: Encountered a bug? Let us know by opening an issue with detailed information so we can fix it.
|
|
56
|
+
- **General Feedback**: Any other suggestions or feedback? Feel free to share your thoughts.
|
|
57
|
+
|
|
58
|
+
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!
|
|
59
|
+
|
|
60
|
+
More details about it at our [CONTRIBUTING](./CONTRIBUTING.md) guide.
|
|
61
|
+
|
|
7
62
|
## Table of Contents
|
|
8
63
|
|
|
9
64
|
- [Features](#features)
|
|
@@ -24,8 +79,8 @@ GPT-PR is an open-source command-line tool designed to streamline your GitHub wo
|
|
|
24
79
|
|
|
25
80
|
Before getting started, make sure you have the following installed:
|
|
26
81
|
|
|
27
|
-
- Python 3.
|
|
28
|
-
- [
|
|
82
|
+
- Python 3.9 or higher
|
|
83
|
+
- [Poetry](https://python-poetry.org/)
|
|
29
84
|
|
|
30
85
|
## Installation
|
|
31
86
|
|
|
@@ -33,14 +88,12 @@ You can install and use GPT-PR in one of two ways. Choose the option that best s
|
|
|
33
88
|
|
|
34
89
|
### Option 1: Using `pip install` (Recommended)
|
|
35
90
|
|
|
36
|
-
1. Install the package:
|
|
91
|
+
1. Install OR Update the package:
|
|
37
92
|
|
|
38
93
|
```bash
|
|
39
94
|
pip install -U gpt-pr
|
|
40
95
|
```
|
|
41
96
|
|
|
42
|
-
> Note: Use this command to **update** gpt-pr package to the latest version.
|
|
43
|
-
|
|
44
97
|
2. Setup API keys for GitHub and OpenAI, take a look at [Configuration](#configuration).
|
|
45
98
|
|
|
46
99
|
3. Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
|
|
@@ -49,7 +102,7 @@ pip install -U gpt-pr
|
|
|
49
102
|
gpt-pr --help
|
|
50
103
|
```
|
|
51
104
|
|
|
52
|
-
### Option 2: Cloning the code
|
|
105
|
+
### Option 2: Cloning the code (NOT recommended)
|
|
53
106
|
|
|
54
107
|
1. Clone the repository:
|
|
55
108
|
|
|
@@ -61,19 +114,25 @@ git clone https://github.com/alissonperez/gpt-pr.git
|
|
|
61
114
|
|
|
62
115
|
```bash
|
|
63
116
|
cd gpt-pr
|
|
64
|
-
|
|
117
|
+
poetry install
|
|
65
118
|
```
|
|
66
119
|
|
|
67
120
|
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:
|
|
68
121
|
|
|
69
122
|
```bash
|
|
70
|
-
|
|
71
|
-
PIPENV_PIPFILE=~/workplace/gpt-pr/Pipfile \
|
|
72
|
-
pipenv run python ~/workplace/gpt-pr/gptpr/main.py --help
|
|
123
|
+
poetry run python gpt_pr/main.py --help
|
|
73
124
|
```
|
|
74
125
|
|
|
75
126
|
## Configuration
|
|
76
127
|
|
|
128
|
+
### See all configs available
|
|
129
|
+
|
|
130
|
+
To print all default configs and what is being used, just run:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
gpt-pr-config print
|
|
134
|
+
```
|
|
135
|
+
|
|
77
136
|
### Setting up GitHub Token (`GH_TOKEN`)
|
|
78
137
|
|
|
79
138
|
GPT-PR tool will look for a `GH_TOKEN` in current shell env var OR in gpt-pr config file (at `~/.gpt-pr.ini`).
|
|
@@ -120,22 +179,36 @@ Or just export it as an environment variable in your shell initializer:
|
|
|
120
179
|
export OPENAI_API_KEY=your_generated_api_key_here
|
|
121
180
|
```
|
|
122
181
|
|
|
182
|
+
### Setting Max Input LLM Tokens
|
|
183
|
+
|
|
184
|
+
You can adjust the maximum number of input tokens allowed when calling the LLM model by modifying the corresponding setting.
|
|
185
|
+
|
|
186
|
+
For example, to change the maximum to 20,000 tokens, use the following command:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
gpt-pr-config set input_max_tokens 20000
|
|
190
|
+
```
|
|
191
|
+
|
|
123
192
|
### Change OpenAI model
|
|
124
193
|
|
|
125
194
|
To change OpenAI model, just run:
|
|
126
195
|
|
|
127
196
|
```bash
|
|
128
|
-
gpt-pr-config set openai_model gpt-
|
|
197
|
+
gpt-pr-config set openai_model gpt-4o-mini
|
|
129
198
|
```
|
|
130
199
|
|
|
200
|
+
> Obs.: `gpt-4o-mini` already is the default model of the project
|
|
201
|
+
|
|
131
202
|
To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
|
|
132
203
|
|
|
133
|
-
###
|
|
204
|
+
### GPT-PR Library Signature in PRs
|
|
134
205
|
|
|
135
|
-
To
|
|
206
|
+
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.
|
|
207
|
+
|
|
208
|
+
If you prefer to disable this feature, simply run the following command:
|
|
136
209
|
|
|
137
210
|
```bash
|
|
138
|
-
gpt-pr-config
|
|
211
|
+
gpt-pr-config set add_tool_signature false
|
|
139
212
|
```
|
|
140
213
|
|
|
141
214
|
### Reset config
|
|
@@ -143,7 +216,7 @@ gpt-pr-config print
|
|
|
143
216
|
To reset any config to default value, just run:
|
|
144
217
|
|
|
145
218
|
```bash
|
|
146
|
-
gpt-pr-config reset
|
|
219
|
+
gpt-pr-config reset config_name
|
|
147
220
|
```
|
|
148
221
|
|
|
149
222
|
Example:
|
|
@@ -179,10 +252,6 @@ gpt-pr -h
|
|
|
179
252
|
Output:
|
|
180
253
|

|
|
181
254
|
|
|
182
|
-
## How to contribute?
|
|
183
|
-
|
|
184
|
-
Please follow our [CONTRIBUTING](./CONTRIBUTING.md) guide.
|
|
185
|
-
|
|
186
255
|
## Roadmap
|
|
187
256
|
|
|
188
257
|
- [x] Improve execution method, possibly through a shell script or at least an alias in bash rc files.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
import json
|
|
4
|
+
import tempfile
|
|
5
|
+
from gpt_pr import __version__
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
|
+
|
|
8
|
+
from gpt_pr import consolecolor as cc
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
PACKAGE_NAME = "gpt-pr"
|
|
12
|
+
CACHE_FILE = os.path.join(os.path.expanduser("~"), ".gpt_pr_update_cache.json")
|
|
13
|
+
CACHE_DURATION = timedelta(days=1)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def cache_daily_version(func):
|
|
17
|
+
def wrapper(*args, **kwargs):
|
|
18
|
+
cache = load_cache()
|
|
19
|
+
last_checked = cache.get("last_checked")
|
|
20
|
+
|
|
21
|
+
if last_checked:
|
|
22
|
+
last_checked = datetime.fromisoformat(last_checked)
|
|
23
|
+
|
|
24
|
+
if datetime.now() - last_checked < CACHE_DURATION:
|
|
25
|
+
# Use cached version info
|
|
26
|
+
latest_version = cache.get("latest_version")
|
|
27
|
+
if latest_version:
|
|
28
|
+
return latest_version
|
|
29
|
+
|
|
30
|
+
latest_version = func(*args, **kwargs)
|
|
31
|
+
cache = {
|
|
32
|
+
"last_checked": datetime.now().isoformat(),
|
|
33
|
+
"latest_version": latest_version,
|
|
34
|
+
}
|
|
35
|
+
save_cache(cache)
|
|
36
|
+
|
|
37
|
+
return latest_version
|
|
38
|
+
|
|
39
|
+
return wrapper
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_cache_file_path():
|
|
43
|
+
temp_dir = tempfile.gettempdir()
|
|
44
|
+
return os.path.join(temp_dir, f"{PACKAGE_NAME}_update_cache.json")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@cache_daily_version
|
|
48
|
+
def get_latest_version():
|
|
49
|
+
url = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
response = requests.get(url)
|
|
53
|
+
response.raise_for_status()
|
|
54
|
+
data = response.json()
|
|
55
|
+
return data["info"]["version"]
|
|
56
|
+
except requests.exceptions.RequestException as e:
|
|
57
|
+
print(f"Error fetching latest version info: {e}")
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def load_cache():
|
|
62
|
+
cache_file = get_cache_file_path()
|
|
63
|
+
if os.path.exists(cache_file):
|
|
64
|
+
with open(cache_file, "r") as file:
|
|
65
|
+
return json.load(file)
|
|
66
|
+
|
|
67
|
+
return {}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def save_cache(data):
|
|
71
|
+
cache_file = get_cache_file_path()
|
|
72
|
+
with open(cache_file, "w") as file:
|
|
73
|
+
file.write(json.dumps(data))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def check_for_updates():
|
|
77
|
+
latest_version = get_latest_version()
|
|
78
|
+
|
|
79
|
+
if latest_version and latest_version != __version__:
|
|
80
|
+
print("")
|
|
81
|
+
print(
|
|
82
|
+
cc.yellow(
|
|
83
|
+
f"A new version of {PACKAGE_NAME} is available ({latest_version}). "
|
|
84
|
+
f"You are using version {__version__}. Please update by running"
|
|
85
|
+
),
|
|
86
|
+
cc.green(f"pip install --upgrade {PACKAGE_NAME}."),
|
|
87
|
+
)
|
|
88
|
+
print("")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
check_for_updates()
|
|
93
|
+
# Your CLI code here
|
|
@@ -7,7 +7,8 @@ def config_command_example(name, value_sample):
|
|
|
7
7
|
return f'gpt-pr-config set {name} {value_sample}'
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
CONFIG_PROJECT_REPO_URL = 'https://github.com/alissonperez/gpt-pr'
|
|
11
|
+
CONFIG_README_SECTION = f'{CONFIG_PROJECT_REPO_URL}?tab=readme-ov-file#configuration'
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class Config:
|
|
@@ -15,11 +16,17 @@ class Config:
|
|
|
15
16
|
config_filename = '.gpt-pr.ini'
|
|
16
17
|
|
|
17
18
|
_default_config = {
|
|
19
|
+
# Amenities
|
|
20
|
+
'ADD_TOOL_SIGNATURE': 'true', # Add GPT-PR signature to PRs
|
|
21
|
+
|
|
18
22
|
# Github
|
|
19
23
|
'GH_TOKEN': '',
|
|
20
24
|
|
|
25
|
+
# LLM input MAX Tokens
|
|
26
|
+
'INPUT_MAX_TOKENS': '15000',
|
|
27
|
+
|
|
21
28
|
# Open AI info
|
|
22
|
-
'OPENAI_MODEL': 'gpt-4o',
|
|
29
|
+
'OPENAI_MODEL': 'gpt-4o-mini',
|
|
23
30
|
'OPENAI_API_KEY': '',
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -66,7 +73,7 @@ class Config:
|
|
|
66
73
|
|
|
67
74
|
def set_user_config(self, name, value):
|
|
68
75
|
self.load()
|
|
69
|
-
self._config['user'][name] = value
|
|
76
|
+
self._config['user'][name] = str(value)
|
|
70
77
|
|
|
71
78
|
def reset_user_config(self, name):
|
|
72
79
|
self.load()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from github import Github
|
|
3
|
+
from InquirerPy import inquirer
|
|
4
|
+
from gpt_pr.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(
|
|
14
|
+
'Please set "gh_token" config. Just run:',
|
|
15
|
+
config_command_example("gh_token", "[my gh token]"),
|
|
16
|
+
"more about at",
|
|
17
|
+
CONFIG_README_SECTION,
|
|
18
|
+
)
|
|
19
|
+
raise SystemExit(1)
|
|
20
|
+
|
|
21
|
+
return gh_token
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_pr(pr_data, yield_confirmation, gh=None):
|
|
25
|
+
if not gh:
|
|
26
|
+
gh = Github(_get_gh_token())
|
|
27
|
+
|
|
28
|
+
repo = gh.get_repo(f"{pr_data.branch_info.owner}/{pr_data.branch_info.repo}")
|
|
29
|
+
|
|
30
|
+
pr_confirmation = (
|
|
31
|
+
yield_confirmation
|
|
32
|
+
or inquirer.confirm(message="Create GitHub PR?", default=True).execute()
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
if pr_confirmation:
|
|
36
|
+
pr = repo.create_pull(
|
|
37
|
+
title=pr_data.title,
|
|
38
|
+
body=pr_data.create_body(),
|
|
39
|
+
head=pr_data.branch_info.branch,
|
|
40
|
+
base=pr_data.branch_info.base_branch,
|
|
41
|
+
)
|
|
42
|
+
print("Pull request created successfully: ", pr.html_url)
|
|
43
|
+
else:
|
|
44
|
+
print("cancelling...")
|