Skip to content

Commit

Permalink
Change ignore branch behavior to be prefix checks (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
yqiu24 authored Nov 15, 2023
1 parent 75d23de commit 91a7758
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
github_token: ${{ github.token }}
last_commit_age_days: 0
dry_run: yes
ignore_branches: test_prefix/one,test_prefix/two,test_prefix_ignored/one
ignore_branches: test_prefix,test_prefix_ignored
branch_limit: 10
only_closed_prs: yes

Expand Down
25 changes: 17 additions & 8 deletions src/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ def get_deletable_branches(
if branch.get('protected') is True:
print(f'Ignoring `{branch_name}` because it is protected')
continue

if branch_name in ignore_branches:
print(f'Ignoring `{branch_name}` because it is on the list of ignored branches')

found_ignored_prefix = False
for prefix in ignore_branches:
if branch_name.startswith(prefix):
found_ignored_prefix = True
break
if found_ignored_prefix is True:
print(f'Ignoring `{branch_name}` because it is on the list of ignored branch prefixes')
continue

# If allowed_prefixes are provided, only consider branches that match one of the prefixes
Expand Down Expand Up @@ -149,14 +154,19 @@ def get_deletable_branches_from_closed_pull_requests(
print(f'Ignoring {html_url} because head branch is already deleted')
continue

if branch_name in ignore_branches:
print(f'Ignoring `{branch_name}` because it is on the list of ignored branches')
continue

# Immediately discard default branch
if branch_name == default_branch:
print(f'Ignoring `{branch_name}` because it is the default branch')
continue

found_ignored_prefix = False
for prefix in ignore_branches:
if branch_name.startswith(prefix):
found_ignored_prefix = True
break
if found_ignored_prefix is True:
print(f'Ignoring `{branch_name}` because it is on the list of ignored branch prefixes')
continue

# If allowed_prefixes are provided, only consider branches that match one of the prefixes
if len(allowed_prefixes) > 0:
Expand All @@ -173,7 +183,6 @@ def get_deletable_branches_from_closed_pull_requests(
print(f'Ignoring {html_url} because last updated time is newer than {last_commit_age_days} days')
continue


branch = self.get_branch_info(branch=branch_name)

# Don't delete protected branches
Expand Down

0 comments on commit 91a7758

Please sign in to comment.