Skip to content

Commit 918e0a5

Browse files
committed
linter
1 parent ba45ced commit 918e0a5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/ghstack/clean.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515

1616
# Regex to match ghstack branch names: gh/{username}/{number}/{kind}
17-
RE_GHSTACK_BRANCH = re.compile(r"^(?:refs/(?:heads|remotes/[^/]+)/)?gh/([^/]+)/([0-9]+)/(.+)$")
17+
RE_GHSTACK_BRANCH = re.compile(
18+
r"^(?:refs/(?:heads|remotes/[^/]+)/)?gh/([^/]+)/([0-9]+)/(.+)$"
19+
)
1820

1921

2022
def parse_ghstack_branch(ref: str) -> Optional[Tuple[str, GhNumber, str]]:
@@ -257,10 +259,14 @@ def main(
257259
pr_number, is_closed = pr_info
258260
pr_closed_cache[pr_number] = is_closed
259261
if is_closed:
260-
logging.info(f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is closed")
262+
logging.info(
263+
f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is closed"
264+
)
261265
orphan_branches.extend(branches)
262266
else:
263-
logging.debug(f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is still open")
267+
logging.debug(
268+
f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is still open"
269+
)
264270
continue
265271

266272
# Check cache first (handles multiple ghnums mapping to same PR)
@@ -275,7 +281,9 @@ def main(
275281
logging.info(f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is closed")
276282
orphan_branches.extend(branches)
277283
else:
278-
logging.debug(f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is still open")
284+
logging.debug(
285+
f"PR #{pr_number} (gh/{branch_username}/{ghnum}) is still open"
286+
)
279287

280288
if not orphan_branches:
281289
logging.info("No orphan branches found.")
@@ -317,7 +325,7 @@ def main(
317325
deleted_branches: List[str] = []
318326

319327
for i in range(0, len(orphan_branches), batch_size):
320-
batch = orphan_branches[i:i + batch_size]
328+
batch = orphan_branches[i : i + batch_size]
321329
try:
322330
sh.git("push", remote_name, "--delete", *batch)
323331
deleted_branches.extend(batch)

test/clean/basic.py.test

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ with captured_output() as (out, err):
2121
deleted_dry = gh_clean(dry_run=True)
2222

2323
# Branches should still exist after dry run
24-
refs_after_dry = upstream_sh.git("for-each-ref", "refs/heads/gh/", "--format=%(refname)")
24+
refs_after_dry = upstream_sh.git(
25+
"for-each-ref", "refs/heads/gh/", "--format=%(refname)"
26+
)
2527
assert "gh/ezyang/1/" in refs_after_dry, "Branches should still exist after dry run"
2628

2729
# Verify dry run found the right branches
@@ -38,10 +40,14 @@ with captured_output() as (out, err):
3840

3941
# Verify the closed PR branches were deleted
4042
refs_after = upstream_sh.git("for-each-ref", "refs/heads/gh/", "--format=%(refname)")
41-
assert "gh/ezyang/1/" not in refs_after, f"Expected branches for PR 1 to be deleted, got: {refs_after}"
43+
assert (
44+
"gh/ezyang/1/" not in refs_after
45+
), f"Expected branches for PR 1 to be deleted, got: {refs_after}"
4246

4347
# Verify the open PR branches still exist
44-
assert "gh/ezyang/2/" in refs_after, f"Expected branches for PR 2 to still exist, got: {refs_after}"
48+
assert (
49+
"gh/ezyang/2/" in refs_after
50+
), f"Expected branches for PR 2 to still exist, got: {refs_after}"
4551

4652
# Clean again - should find nothing to clean
4753
with captured_output() as (out, err):

0 commit comments

Comments
 (0)