Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git diff logic #1

Merged
merged 9 commits into from
Nov 9, 2023
Merged

Git diff logic #1

merged 9 commits into from
Nov 9, 2023

Conversation

Tedfulk
Copy link
Owner

@Tedfulk Tedfulk commented Nov 9, 2023

No description provided.

Ted Fulk and others added 9 commits November 2, 2023 15:01
…escription, and instructions on how to use the tool.

# Aider chat conversation:

USER: update the README.md to be a comprehensive representation of all the files i have given. I want it to be four sections an Introduction, a more detailed description, and how to use it.

ASSISTANT: Sure, I can help with that. Here's a general structure for the README.md file.

```markdown
README.md
<<<<<<< SEARCH

=======
# Introduction

This project is a command-line tool named BROGRAMMER, an AI Peer Review Bro. It uses the GPT model to review your code and provide feedback. The tool is designed to be flexible, allowing you to specify the level of feedback you want, the files you want to include or exclude, and even the branch to compare the git diff against.

# Detailed Description

The main functionality of the tool is contained within the `main.py` file. This script uses the `typer` library to parse command-line arguments and options. It also uses the `rich` library to display the results in a formatted table in the console.

The `git.py` file contains a function to get the git diff of the current project. It allows you to specify the file extensions to include or exclude, and the branch to compare against.

The `llm.py` file contains functions to interact with the GPT model. It sends a prompt to the model and parses the response.

The `models.py` file defines the `BroMode` enum, which represents the level of feedback you want from the tool.

The `utils.py` file contains utility functions used by the other scripts.

The `constants.py` and `commandments.py` files contain constant values and functions to generate prompts for the GPT model, respectively.

# How to Use

To use the tool, run the `main.py` script with the desired options. For example, to get a chill, jr-level engineer review, use the `--chill` option:

```bash
python main.py --chill
```

To specify the GPT model to use, use the `--model` option:

```bash
python main.py --model gpt-4
```

To only include files with certain extensions, use the `--only` option:

```bash
python main.py --only .py .js
```

To ignore files with certain extensions, use the `--ignore` option:

```bash
python main.py --ignore .txt .md
```

To specify a custom prompt for the GPT model, use the `--prompt` option:

```bash
python main.py --prompt "Review this code"
```

To summarize the git diff, use the `--summarize` option:

```bash
python main.py --summarize
```

To specify the branch to compare the git diff against, use the `--peer-review` option:

```bash
python main.py --peer-review main
```
>>>>>>> REPLACE
```

Please note that this is a general structure and might need to be adjusted based on the specific functionality and usage of your project.
…n, and instructions on how to use the tool.

# Aider chat conversation:

USER: I added these *read-write* files: py_do_you_even_diff_bro/README.md, py_do_you_even_diff_bro/constants.py, py_do_you_even_diff_bro/utils.py, py_do_you_even_diff_bro/models.py, py_do_you_even_diff_bro/llm.py, py_do_you_even_diff_bro/commandments.py

ASSISTANT: Great! Now that we have all the necessary files, let's proceed with the changes.

1. **File to modify:** `py_do_you_even_diff_bro/README.md`

The README file is the first point of contact for anyone who wants to understand your project. It should provide a clear and concise overview of what the project does, how to install and use it, and any other relevant information.

Here's a general structure for the README.md file.

```markdown
README.md
<<<<<<< SEARCH

=======
# Introduction

This project is a command-line tool named BROGRAMMER, an AI Peer Review Bro. It uses the GPT model to review your code and provide feedback. The tool is designed to be flexible, allowing you to specify the level of feedback you want, the files you want to include or exclude, and even the branch to compare the git diff against.

# Detailed Description

The main functionality of the tool is contained within the `main.py` file. This script uses the `typer` library to parse command-line arguments and options. It also uses the `rich` library to display the results in a formatted table in the console.

The `git.py` file contains a function to get the git diff of the current project. It allows you to specify the file extensions to include or exclude, and the branch to compare against.

The `llm.py` file contains functions to interact with the GPT model. It sends a prompt to the model and parses the response.

The `models.py` file defines the `BroMode` enum, which represents the level of feedback you want from the tool.

The `utils.py` file contains utility functions used by the other scripts.

The `constants.py` and `commandments.py` files contain constant values and functions to generate prompts for the GPT model, respectively.

# How to Use

To use the tool, run the `main.py` script with the desired options. For example, to get a chill, jr-level engineer review, use the `--chill` option:

```bash
python main.py --chill
```

To specify the GPT model to use, use the `--model` option:

```bash
python main.py --model gpt-4
```

To only include files with certain extensions, use the `--only` option:

```bash
python main.py --only .py .js
```

To ignore files with certain extensions, use the `--ignore` option:

```bash
python main.py --ignore .txt .md
```

To specify a custom prompt for the GPT model, use the `--prompt` option:

```bash
python main.py --prompt "Review this code"
```

To summarize the git diff, use the `--summarize` option:

```bash
python main.py --summarize
```

To specify the branch to compare the git diff against, use the `--peer-review` option:

```bash
python main.py --peer-review main
```
>>>>>>> REPLACE
```

Please note that this is a general structure and might need to be adjusted based on the specific functionality and usage of your project.
# Aider chat conversation:

USER: update test_main.py to include unit tests using pytest for main.py

ASSISTANT: To add unit tests for `main.py` in `test_main.py`, we need to import the necessary modules and functions, and then write the tests.

Here is an example of how you might structure your tests. Note that the actual tests will depend on the specific functionality of your code, so you may need to adjust these examples to fit your needs.

```python
tests/test_main.py
<<<<<<< SEARCH

=======
import pytest
from py_do_you_even_diff_bro.main import get_bro_mode, display_diff_summary, main
from py_do_you_even_diff_bro.models import BroMode

def test_get_bro_mode():
    assert get_bro_mode(True, False, False) == BroMode.CHILL
    assert get_bro_mode(False, True, False) == BroMode.MID
    assert get_bro_mode(False, False, True) == BroMode.CHAD
    assert get_bro_mode(False, False, False) == BroMode.CHILL

def test_display_diff_summary(mocker):
    mocker.patch('py_do_you_even_diff_bro.main.console')
    display_diff_summary("Test summary")
    py_do_you_even_diff_bro.main.console.print.assert_called_once()

@pytest.mark.parametrize("chill, mid, chad, model, only, ignore, prompt, summarize, peer_review", [
    (True, False, False, 'gpt-4', ['.py'], [], '', False, ''),
    (False, True, False, 'gpt-3.5-turbo', ['.py'], ['.txt'], 'Test prompt', True, 'main')
])
def test_main(chill, mid, chad, model, only, ignore, prompt, summarize, peer_review, mocker):
    mocker.patch('py_do_you_even_diff_bro.main.get_git_diff', return_value="Test diff")
    mocker.patch('py_do_you_even_diff_bro.main.gpt_prompt', return_value="Test response")
    main(chill, mid, chad, model, only, ignore, prompt, summarize, peer_review)
    py_do_you_even_diff_bro.main.get_git_diff.assert_called_once_with(only, ignore, peer_review)
    py_do_you_even_diff_bro.main.gpt_prompt.assert_called()
>>>>>>> REPLACE
```

This code adds three tests:

1. `test_get_bro_mode` tests the `get_bro_mode` function with different combinations of inputs.
2. `test_display_diff_summary` tests the `display_diff_summary` function and checks that it calls the `console.print` method once.
3. `test_main` tests the `main` function with different combinations of inputs and checks that it calls the `get_git_diff` and `gpt_prompt` functions.

Please note that you need to install the `pytest` and `pytest-mock` packages to run these tests. You can install them with pip:

```bash
pip install pytest pytest-mock
```

To run the tests, use the following command:

```bash
pytest tests/test_main.py
```
@Tedfulk Tedfulk merged commit aa6bdb2 into main Nov 9, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant