Skip to content

Commit b2f748b

Browse files
committed
feat: add on automated demo PR creation from feature branches into develop
1 parent 0e8f4e7 commit b2f748b

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.github/workflows/sync-demos.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,3 @@ jobs:
4444

4545
- name: Update Demo
4646
run: "uvx nox -s 'update-demo(${{ matrix.demo.session_modifier }})' -- --branch-override ${{ github.head_ref }}"
47-
48-

scripts/update-demo.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@
77
# "typer",
88
# ]
99
# ///
10-
10+
import itertools
11+
import subprocess
1112
from pathlib import Path
1213
from subprocess import CompletedProcess
1314
from typing import Annotated
15+
from typing import Any
1416
from typing import Optional
1517

1618
import cruft
1719
import typer
1820
from cookiecutter.utils import work_in
1921

22+
from util import _read_cruft_file
2023
from util import DEMO
2124
from util import is_ancestor
2225
from util import get_current_branch
2326
from util import get_current_commit
2427
from util import get_demo_name
2528
from util import get_last_cruft_update_commit
29+
from util import gh
2630
from util import git
2731
from util import FolderOption
2832
from util import REPO_FOLDER
@@ -82,6 +86,8 @@ def update_demo(
8286
git("add", ".")
8387
git("commit", "-m", f"chore: {last_update_commit} -> {template_commit}", "--no-verify")
8488
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)
8591

8692

8793
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:
127133
raise ValueError(f"Updating demos directly to main is not allowed currently.")
128134

129135

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+
130173
if __name__ == '__main__':
131174
cli()

0 commit comments

Comments
 (0)