|
7 | 7 | # "typer", |
8 | 8 | # ] |
9 | 9 | # /// |
10 | | - |
| 10 | +import itertools |
| 11 | +import subprocess |
11 | 12 | from pathlib import Path |
12 | 13 | from subprocess import CompletedProcess |
13 | 14 | from typing import Annotated |
| 15 | +from typing import Any |
14 | 16 | from typing import Optional |
15 | 17 |
|
16 | 18 | import cruft |
17 | 19 | import typer |
18 | 20 | from cookiecutter.utils import work_in |
19 | 21 |
|
| 22 | +from util import _read_cruft_file |
20 | 23 | from util import DEMO |
21 | 24 | from util import is_ancestor |
22 | 25 | from util import get_current_branch |
23 | 26 | from util import get_current_commit |
24 | 27 | from util import get_demo_name |
25 | 28 | from util import get_last_cruft_update_commit |
| 29 | +from util import gh |
26 | 30 | from util import git |
27 | 31 | from util import FolderOption |
28 | 32 | from util import REPO_FOLDER |
@@ -82,6 +86,8 @@ def update_demo( |
82 | 86 | git("add", ".") |
83 | 87 | git("commit", "-m", f"chore: {last_update_commit} -> {template_commit}", "--no-verify") |
84 | 88 | git("push", "-u", "origin", current_branch) |
| 89 | + if current_branch != "develop": |
| 90 | + _create_demo_pr(demo_path=demo_path, branch=current_branch, commit_start=last_update_commit) |
85 | 91 |
|
86 | 92 |
|
87 | 93 | def _checkout_demo_develop_or_existing_branch(demo_path: Path, branch: str) -> None: |
@@ -127,5 +133,42 @@ def _validate_template_main_not_checked_out(branch: str) -> None: |
127 | 133 | raise ValueError(f"Updating demos directly to main is not allowed currently.") |
128 | 134 |
|
129 | 135 |
|
| 136 | +def _create_demo_pr(demo_path: Path, branch: str, commit_start: str) -> None: |
| 137 | + """Creates a PR to merge the given branch into develop.""" |
| 138 | + gh("repo", "set-default", f"{DEMO.app_author}/{DEMO.app_name}") |
| 139 | + |
| 140 | + body: str = _get_demo_feature_pr_body(demo_path=demo_path, commit_start=commit_start) |
| 141 | + |
| 142 | + pr_kwargs: dict[str, Any] = { |
| 143 | + "--title": branch.capitalize(), |
| 144 | + "--body": body, |
| 145 | + "--base": DEMO.develop_branch, |
| 146 | + "--assignee": "@me", |
| 147 | + "--repo": f"{DEMO.app_author}/{DEMO.app_name}", |
| 148 | + } |
| 149 | + gh("pr", "create", *itertools.chain(pr_kwargs.items())) |
| 150 | + |
| 151 | + |
| 152 | +def _get_demo_feature_pr_body(demo_path: Path, commit_start: str) -> str: |
| 153 | + """Creates the body of the demo feature pull request.""" |
| 154 | + cruft_config: dict[str, Any] = _read_cruft_file(demo_path) |
| 155 | + commit_end: Optional[str] = cruft_config.get("commit_end", None) |
| 156 | + if commit_end is None: |
| 157 | + raise ValueError(f"Unable to find latest commit in .cruft.json for demo at {demo_path}.") |
| 158 | + rev_range: str = f"{commit_start}..{commit_end}" |
| 159 | + command: list[str] = [ |
| 160 | + "uvx", |
| 161 | + "--from", |
| 162 | + "commitizen", |
| 163 | + "cz", |
| 164 | + "changelog", |
| 165 | + rev_range, |
| 166 | + "--dry-run", |
| 167 | + "--unreleased-version" |
| 168 | + ] |
| 169 | + section_notes: str = subprocess.check_output(command, text=True) |
| 170 | + return section_notes.strip() |
| 171 | + |
| 172 | + |
130 | 173 | if __name__ == '__main__': |
131 | 174 | cli() |
0 commit comments