Skip to content
Merged
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
2 changes: 2 additions & 0 deletions acp.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ def list_branches(show_all: bool = False, verbose: bool = False) -> None:
"gh",
"pr",
"list",
"--author",
"@me",
"--state",
"open",
"--json",
Expand Down
64 changes: 64 additions & 0 deletions test_acp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,70 @@ def test_skips_tracking_refs(self, mock_acp_run, mock_run_check, mock_run, capsy
assert "HEAD" not in output


class TestListBranchesAuthor:
def _git_result(self, stdout):
return subprocess.CompletedProcess(
args=[], returncode=0, stdout=stdout, stderr=""
)

def _gh_pr_result(self, prs=None):
return subprocess.CompletedProcess(
args=[],
returncode=0,
stdout=json.dumps(prs or []),
stderr="",
)

@mock.patch("subprocess.run")
@mock.patch("acp.run", return_value="testuser")
def test_gh_pr_list_uses_author_me(self, mock_acp_run, mock_run, capsys):
mock_run.side_effect = [
self._git_result(""),
self._git_result(""),
self._gh_pr_result(),
]
acp.list_branches()
pr_list_call = mock_run.call_args_list[2]
assert "--author" in pr_list_call[0][0]
assert "@me" in pr_list_call[0][0]

@mock.patch("subprocess.run")
@mock.patch("acp.run", return_value="testuser")
def test_other_users_prs_do_not_match_local_branches(
self, mock_acp_run, mock_run, capsys
):
other_peoples_prs = [
{"headRefName": "fix-something", "title": "fix", "number": 99, "url": "u"},
{"headRefName": "feature-xyz", "title": "feat", "number": 100, "url": "u"},
]
mock_run.side_effect = [
self._git_result(" origin/acp/testuser/1234\n"),
self._git_result(""),
self._gh_pr_result(other_peoples_prs),
]
acp.list_branches()
assert "No ACP branches with linked PRs found." in capsys.readouterr().out

@mock.patch("subprocess.run")
@mock.patch("acp.run", return_value="testuser")
def test_own_pr_matches_local_branch(self, mock_acp_run, mock_run, capsys):
own_prs = [
{
"headRefName": "acp/testuser/1234",
"title": "my fix",
"number": 42,
"url": "u",
},
]
mock_run.side_effect = [
self._git_result(" origin/acp/testuser/1234\n"),
self._git_result(""),
self._gh_pr_result(own_prs),
]
acp.list_branches()
assert "acp/testuser/1234 -> #42 my fix" in capsys.readouterr().out


class TestListBranchesVerbose:
@mock.patch("subprocess.run")
@mock.patch("acp.run", return_value="testuser")
Expand Down
Loading