Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template sync #222

Merged
merged 44 commits into from
Nov 28, 2023
Merged
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2b0dcee
Revert "fix typo (#165)"
grst May 1, 2023
c343b6c
Cruft PR workflow (#168)
flying-sheep Jun 1, 2023
40cb337
Fix `git clone` in cruft PR workflow (#196)
flying-sheep Jun 1, 2023
aee3566
depend on cruft in cruft PRs workflow (#197)
flying-sheep Jun 1, 2023
f2e3dca
Fix cruft invocation typo (#198)
flying-sheep Jun 1, 2023
66efb06
Use namespaced head in cruft PRs (#199)
flying-sheep Jun 1, 2023
f9a029b
Use user.login instead of user.name (#200)
flying-sheep Jun 1, 2023
1929d97
Finish cruft PRs (#201)
flying-sheep Jun 1, 2023
e03a54d
Cruft PRs: wait for fork creation (#202)
flying-sheep Jun 2, 2023
03ef73a
Another backoff for cruft (#207)
grst Jun 6, 2023
a04720c
Merge branch 'main' into v0.2.x
grst Aug 4, 2023
3e8f6e7
Merge branch 'main' into v0.2.x
grst Aug 4, 2023
891571c
Update template sync
grst Aug 4, 2023
9527ee9
fix tests
grst Aug 4, 2023
8875ce7
fix tests
grst Aug 4, 2023
b89738e
Make name of forked repos include the original user
grst Aug 4, 2023
a41458d
debug log
grst Aug 4, 2023
cb46a7c
fix artifact upload
grst Aug 4, 2023
809e9aa
Fetch main branch from upstream
grst Aug 4, 2023
a400e6f
Fix get fork
grst Aug 4, 2023
e55346f
fix clone url
grst Aug 4, 2023
c0c2c27
fmt
flying-sheep Aug 7, 2023
3aeb28d
comment on why pre-commit is a runtime dep
flying-sheep Aug 7, 2023
5f2e04d
less positional
flying-sheep Aug 7, 2023
e742888
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2023
98d2f88
Wrap entire command in try/catch
grst Aug 9, 2023
b663f51
Merge remote-tracking branch 'origin/main' into v0.2.x
grst Aug 9, 2023
ac28931
Merge branch 'v0.2.x' of github.com:scverse/cookiecutter-scverse into…
grst Aug 9, 2023
fccd4c3
Skip PR if already exists for current version.
grst Aug 9, 2023
60b1c0c
Fix log messages
grst Aug 9, 2023
419fb31
Fix tests
grst Aug 9, 2023
cd609e2
Try fix test
grst Aug 9, 2023
121bcbf
Arming bot: Apply to all repos
grst Aug 9, 2023
4fcf466
Fix global exception handler
grst Aug 9, 2023
23a9eaa
Fix global exception handler
grst Aug 9, 2023
8be748d
Simplify code
flying-sheep Aug 10, 2023
e27ca0a
Merge branch 'main' into v0.2.x
grst Aug 16, 2023
ff88292
Allow maintainer to modify the PR
grst Aug 16, 2023
abf05fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 16, 2023
605f957
Fix logging for existing PRs
grst Aug 16, 2023
1c20533
Merge branch 'main' into v0.2.x
grst Aug 23, 2023
582c769
Merge branch 'main' into v0.2.x
grst Nov 27, 2023
9b534ce
Merge branch 'main' into v0.2.x
grst Nov 28, 2023
7539d2a
Set git default branch in tests
grst Nov 28, 2023
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
28 changes: 23 additions & 5 deletions scripts/src/scverse_template_scripts/cruft_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ def body(self) -> str:
template_usage="https://cookiecutter-scverse-instance.readthedocs.io/en/latest/template_usage.html",
)

def matches(self, pr: PullRequest) -> bool:
def matches_prefix(self, pr: PullRequest) -> bool:
"""Check if `pr` is either a current or previous template update PR by matching the branch name"""
# Don’t compare title prefix, people might rename PRs
return pr.head.ref.startswith(self.branch_prefix) and pr.user.id == self.con.user.id

def matches_current_version(self, pr: PullRequest) -> bool:
"""Check if `pr` is a template update PR for the current version"""
return pr.head.ref == self.branch and pr.user.id == self.con.user.id


class RepoInfo(TypedDict):
url: str
Expand Down Expand Up @@ -217,6 +222,11 @@ def make_pr(con: GitHubConnection, release: GHRelease, repo_url: str) -> None:
# create fork, populate branch, do PR from it
origin = con.gh.get_repo(repo_url.removeprefix("https://github.com/"))
repo = get_fork(con, origin)

if old_pr := next((p for p in origin.get_pulls("open") if pr.matches_current_version(p)), None):
flying-sheep marked this conversation as resolved.
Show resolved Hide resolved
log.info(f"PR for current version already exists: #{pr.number} with branch name `{pr.head.ref}`. Skipping.")
return

with TemporaryDirectory() as td:
updated = cruft_update(
con,
Expand All @@ -227,7 +237,8 @@ def make_pr(con: GitHubConnection, release: GHRelease, repo_url: str) -> None:
path=Path(td),
)
if updated:
if old_pr := next((p for p in origin.get_pulls("open") if pr.matches(p)), None):
if old_pr := next((p for p in origin.get_pulls("open") if pr.matches_prefix(p)), None):
log.info(f"Closing old PR #{old_pr.number} with branch name `{pr.head.ref}`.")
old_pr.edit(state="closed")
origin.create_pull(pr.title, pr.body, origin.default_branch, pr.namespaced_head)

Expand All @@ -245,10 +256,17 @@ def main(tag_name: str) -> None:
con = GitHubConnection("scverse-bot", token)
release = get_template_release(con.gh, tag_name)
repo_urls = get_repo_urls(con.gh)
failed = 0
for repo_url in repo_urls:
# TODO just use single-repo we control for testing
if repo_url.endswith("icbi-lab/infercnvpy"):
make_pr(con, release, repo_url)
try:
# TODO just use single-repo we control for testing
if repo_url.endswith("icbi-lab/infercnvpy"):
make_pr(con, release, repo_url)
except Exception as e:
failed += 1
log.error(f"Error updating {repo_url}.", e)

sys.exit(failed > 0)


def cli() -> None:
Expand Down