Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ on:
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11, 3.12, 3.13]

steps:

- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: ${{ matrix.python-version }}

- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv

- name: Update Python version in Pipfile
run: |
sed -i "s/python-version = \".*\"/python-version = \"${{ matrix.python-version }}\"/" Pipfile

- name: Install dependencies using pipenv
run: pipenv install --dev

Expand All @@ -28,22 +37,31 @@ jobs:

pytest:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.11, 3.12, 3.13]

steps:

- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: ${{ matrix.python-version }}

- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv

- name: Update Python version in Pipfile
run: |
sed -i "s/python-version = \".*\"/python-version = \"${{ matrix.python-version }}\"/" Pipfile

- name: Install dependencies using pipenv
run: pipenv install --dev

- name: Run Flake8 using pipenv
- name: Run pytest using pipenv
run: pipenv run pytest
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.13

- name: Install necessary packages for make
run: sudo apt-get update && sudo apt-get install -y build-essential
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13.0
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pytest = "7.4.4"
pytest-mock = "3.11.1"

[requires]
python_version = "3.7"
python_version = "3.13.0"
56 changes: 56 additions & 0 deletions gptpr/test_gh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from types import SimpleNamespace
import gptpr.gh as gh_module


def test_create_pr_success(mocker, capsys):
fake_repo = mocker.Mock()
pr = SimpleNamespace(html_url="http://fake.url")
fake_repo.create_pull.return_value = pr

fake_gh = SimpleNamespace()
fake_gh.get_repo = lambda repo_name: fake_repo
mocker.patch.object(gh_module, 'gh', fake_gh)

branch_info = SimpleNamespace(owner="owner", repo="repo",
branch="feature-branch", base_branch="main")
pr_data = SimpleNamespace(title="Test PR", branch_info=branch_info,
create_body=lambda: "My body")

gh_module.create_pr(pr_data, yield_confirmation=True)

fake_repo.create_pull.assert_called_once_with(
title="Test PR", body="My body",
head="feature-branch", base="main"
)
captured = capsys.readouterr()
assert "Pull request created successfully" in captured.out
assert "http://fake.url" in captured.out


def test_create_pr_cancel(mocker, capsys):
fake_repo = mocker.Mock()
fake_gh = SimpleNamespace()
fake_gh.get_repo = lambda repo_name: fake_repo
mocker.patch.object(gh_module, 'gh', fake_gh)

class FakePrompt:
def __init__(self, *args, **kwargs):
pass

def execute(self):
return False

mocker.patch.object(gh_module.inquirer, 'confirm',
lambda *args, **kwargs: FakePrompt(*args, **kwargs))

branch_info = SimpleNamespace(owner="owner", repo="repo",
branch="branch", base_branch="base")
pr_data = SimpleNamespace(title="Cancel PR", branch_info=branch_info,
create_body=lambda: "Body")

gh_module.create_pr(pr_data, yield_confirmation=False)

fake_repo.create_pull.assert_not_called()
captured = capsys.readouterr()

assert "cancelling..." in captured.out
Loading