|
18 | 18 |
|
19 | 19 |
|
20 | 20 | class TestGitHubUpdatePRDescriptions(BaseTest): |
| 21 | + def test_github_update_pr_descriptions_related_updates_entire_stack(self, mocker: MockerFixture) -> None: |
| 22 | + """ |
| 23 | + Test that --related flag updates the entire stack (both upstream and downstream PRs), |
| 24 | + even with the default up-only prDescriptionIntroStyle. |
| 25 | +
|
| 26 | + With the OLD logic (before PR #1574), when running `--related` from branch2 with the default |
| 27 | + up-only style, only PR #2 and PR #3 (current and downstream) would be checked/updated. |
| 28 | + PR #1 (upstream) would be skipped entirely. |
| 29 | +
|
| 30 | + With the NEW logic, all PRs in the stack (PR #1, PR #2, PR #3) are checked and updated, |
| 31 | + regardless of the prDescriptionIntroStyle setting. |
| 32 | + Still, the generated intro will follow the prDescriptionIntroStyle setting. |
| 33 | + """ |
| 34 | + self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url) |
| 35 | + self.patch_symbol(mocker, 'git_machete.github.GitHubToken.for_domain', mock_github_token_for_domain_fake) |
| 36 | + |
| 37 | + # Create a simple 3-PR chain: PR1 -> PR2 -> PR3 |
| 38 | + # Give them bodies that will need updating: |
| 39 | + # - PR #1 has an old git-machete generated section with outdated date |
| 40 | + # - PR #2 and #3 have minimal bodies that will be updated with the PR chain info |
| 41 | + prs = [ |
| 42 | + mock_pr_json(head='branch1', base='root', number=1, |
| 43 | + body='<!-- start git-machete generated -->\n\n' |
| 44 | + '**Last updated: 2020-01-01**\n\n' |
| 45 | + '<!-- end git-machete generated -->\n\n' |
| 46 | + '# Summary\n\nOld content'), |
| 47 | + mock_pr_json(head='branch2', base='branch1', number=2, body='# Summary\n'), |
| 48 | + mock_pr_json(head='branch3', base='branch2', number=3, body='# Summary\n') |
| 49 | + ] |
| 50 | + github_api_state = MockGitHubAPIState.with_prs(*prs) |
| 51 | + self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(github_api_state)) |
| 52 | + self.patch_symbol(mocker, 'git_machete.utils.get_current_date', lambda: '2023-12-31') |
| 53 | + |
| 54 | + create_repo_with_remote() |
| 55 | + new_branch("root") |
| 56 | + commit("initial commit") |
| 57 | + push() |
| 58 | + new_branch("branch1") |
| 59 | + commit("branch1 commit") |
| 60 | + push() |
| 61 | + new_branch("branch2") |
| 62 | + commit("branch2 commit") |
| 63 | + push() |
| 64 | + new_branch("branch3") |
| 65 | + commit("branch3 commit") |
| 66 | + push() |
| 67 | + |
| 68 | + body = """ |
| 69 | + root |
| 70 | + branch1 |
| 71 | + branch2 |
| 72 | + branch3 |
| 73 | + """ |
| 74 | + rewrite_branch_layout_file(body) |
| 75 | + |
| 76 | + # Check out the middle branch (branch2) |
| 77 | + check_out('branch2') |
| 78 | + |
| 79 | + # Run with `--related` from the middle branch |
| 80 | + # With the NEW logic, ALL PRs in the stack (PR1, PR2, PR3) are checked and updated |
| 81 | + # With the OLD logic (before PR #1574), only PR2 and PR3 (current and downstream) would be updated, |
| 82 | + # but NOT PR1 (upstream), because the default up-only style would exclude upstream PRs |
| 83 | + assert_success( |
| 84 | + ['github', 'update-pr-descriptions', '--related'], |
| 85 | + """ |
| 86 | + Checking for open GitHub PRs... OK |
| 87 | + Description of PR #1 (branch1 -> root) has been updated |
| 88 | + Description of PR #2 (branch2 -> branch1) has been updated |
| 89 | + Description of PR #3 (branch3 -> branch2) has been updated |
| 90 | + """ |
| 91 | + ) |
| 92 | + |
21 | 93 | @staticmethod |
22 | 94 | def prs_for_test_update_pr_descriptions() -> List[Dict[str, Any]]: |
23 | 95 | return [ |
|
0 commit comments