Skip to content
Draft
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
40 changes: 21 additions & 19 deletions scripts/src/scverse_template_scripts/cruft_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def make_pr(con: GitHubConnection, release: GHRelease, repo_url: str, *, log_dir

forked_repo = get_fork(con, original_repo)

updated = template_update(
template_update(
con,
forked_repo=forked_repo,
original_repo=original_repo,
Expand All @@ -514,24 +514,26 @@ def make_pr(con: GitHubConnection, release: GHRelease, repo_url: str, *, log_dir
if dry_run:
log.info("Skipping PR because in dry-run mode")
return
if updated:
if old_pr := next((p for p in original_repo.get_pulls("open") if pr.matches_current_version(p)), None):
log.info(f"PR already exists: #{old_pr.number} with branch name `{old_pr.head.ref}`. Skipping PR creation.")
return

if old_pr := next((p for p in original_repo.get_pulls("open") if pr.matches_prefix(p)), None):
log.info(f"Closing old PR #{old_pr.number} with branch name `{old_pr.head.ref}`.")
old_pr.edit(state="closed")

log.info(f"Creating PR of {pr.namespaced_head} against {original_repo.default_branch}")
new_pr = original_repo.create_pull(
title=pr.title,
body=pr.body,
base=original_repo.default_branch,
head=pr.namespaced_head,
maintainer_can_modify=True,
)
log.info(f"Created PR #{new_pr.number} with branch name `{new_pr.head.ref}`.")

# check against all PRs, including closed ones -- if one already exists for the current version,
# and the developer closed it, we do not want to reopen it.
if old_pr := next((p for p in original_repo.get_pulls() if pr.matches_current_version(p)), None):
log.info(f"PR already exists: #{old_pr.number} with branch name `{old_pr.head.ref}`. Skipping PR creation.")
return

if old_pr := next((p for p in original_repo.get_pulls("open") if pr.matches_prefix(p)), None):
log.info(f"Closing old PR #{old_pr.number} with branch name `{old_pr.head.ref}`.")
old_pr.edit(state="closed")

log.info(f"Creating PR of {pr.namespaced_head} against {original_repo.default_branch}")
new_pr = original_repo.create_pull(
title=pr.title,
body=pr.body,
base=original_repo.default_branch,
head=pr.namespaced_head,
maintainer_can_modify=True,
)
log.info(f"Created PR #{new_pr.number} with branch name `{new_pr.head.ref}`.")


cli = App()
Expand Down
Loading