diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 2cd07c5..72d9dc4 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -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 @@ -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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e307819..8a0e27d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..4eba2a6 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13.0 diff --git a/Pipfile b/Pipfile index 151a4f9..f05af58 100644 --- a/Pipfile +++ b/Pipfile @@ -19,4 +19,4 @@ pytest = "7.4.4" pytest-mock = "3.11.1" [requires] -python_version = "3.7" +python_version = "3.13.0" diff --git a/gptpr/test_gh.py b/gptpr/test_gh.py new file mode 100644 index 0000000..64e386a --- /dev/null +++ b/gptpr/test_gh.py @@ -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